Module: OsCtld::UtmpReader
- Defined in:
- lib/osctld/utmp_reader.rb
Overview
Read utmp files, see man utmp(5)
Defined Under Namespace
Classes: Entry, ExitStatus, TimeValue
Constant Summary collapse
- MAX_ENTRIES =
128
Class Method Summary collapse
- .read(_path, max_entries: MAX_ENTRIES) {|entry| ... } ⇒ Array<Entry>?
-
.read_utmp_fhs(max_entries: MAX_ENTRIES) {|entry| ... } ⇒ Array<Entry>?
Find utmp file in standard locations and read it.
Class Method Details
.read(_path, max_entries: MAX_ENTRIES) {|entry| ... } ⇒ Array<Entry>?
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/osctld/utmp_reader.rb', line 67 def self.read(_path, max_entries: MAX_ENTRIES) ret = [] i = 0 File.open('/run/utmp', 'rb') do |f| until f.eof? e = Entry.read(f) if block_given? yield(e) else ret << e end i += 1 break if i >= max_entries end end block_given? ? nil : ret end |
.read_utmp_fhs(max_entries: MAX_ENTRIES) {|entry| ... } ⇒ Array<Entry>?
Find utmp file in standard locations and read it
94 95 96 97 98 99 100 101 102 |
# File 'lib/osctld/utmp_reader.rb', line 94 def self.read_utmp_fhs(max_entries: MAX_ENTRIES, &block) %w[/run/utmp /var/log/utmp].each do |path| return read(path, max_entries:, &block) rescue Errno::ENOENT next end raise Errno::ENOENT, 'utmp file not found' end |