Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
require 'rubygems'
require 'ffi'
class Info
extend FFI::Library
BOOT_TIME = 2
attach_function :setutxent, [], :void
attach_function :getutxent, [], :pointer
attach_function :endutxent, [], :void
class Timeval < FFI::Struct
layout( :tv_sec, :long,
:tv_usec, :long )
end
class ExitStatus < FFI::Struct
layout( :e_termination, :short,
:e_exit, :short )
end
class Utmpx < FFI::Struct
layout( :ut_type, :short,
:ut_pid, :pid_t,
:ut_line, [:char, 32],
:ut_id, :char,
:ut_user, [:char, 32],
:ut_host, [:char, 256],
:ut_exit, ExitStatus,
:ut_session, :long,
:ut_tv, Timeval )
end
def self.getstuff
begin
setutxent
ent = Utmpx.new(getutxent())
time = Time.at(ent[:ut_tv][:tv_sec], ent[:ut_tv][:tv_usec]) if ent[:ut_type] == BOOT_TIME
ensure
endutxent
end
end
end
puts "Boot time: #{Info.getstuff}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment