Class: Sys::Sv::StatusBytes
- Inherits:
-
Object
- Object
- Sys::Sv::StatusBytes
- Defined in:
- lib/sys/sv/statusbytes.rb
Overview
The StatusBytes class interprets state files maintained by a SvDir’s monitor process. It should normally not be instantiated directly.
Constant Summary collapse
- BUFLEN =
:nodoc:
18- TAI_EPOCH =
TODO - grok runit extended info (20 bytes)
4611686018427387914
Instance Attribute Summary collapse
-
#pauseflag ⇒ Object
readonly
time_t 0 on the TAI scale.
-
#pid ⇒ Object
readonly
time_t 0 on the TAI scale.
-
#wantflag ⇒ Object
readonly
time_t 0 on the TAI scale.
Instance Method Summary collapse
-
#elapsed ⇒ Object
Number of seconds since service was most recently started or stopped.
-
#epoch ⇒ Object
Returns the number of seconds since the UNIX epoch since the service was most recently started or stopped.
-
#initialize(bytes) ⇒ StatusBytes
constructor
:nodoc:.
Constructor Details
#initialize(bytes) ⇒ StatusBytes
:nodoc:
19 20 21 22 23 24 25 26 27 |
# File 'lib/sys/sv/statusbytes.rb', line 19 def initialize(bytes) # :nodoc: if bytes.size < BUFLEN raise ::Errno::EPROTO.new("corrupt status buffer") end @bytes = bytes @pid, @pauseflag, @wantflag = @bytes.unpack('x12 V c a') @epoch = nil # computed if needed end |
Instance Attribute Details
#pauseflag ⇒ Object (readonly)
time_t 0 on the TAI scale
17 18 19 |
# File 'lib/sys/sv/statusbytes.rb', line 17 def pauseflag @pauseflag end |
#pid ⇒ Object (readonly)
time_t 0 on the TAI scale
17 18 19 |
# File 'lib/sys/sv/statusbytes.rb', line 17 def pid @pid end |
#wantflag ⇒ Object (readonly)
time_t 0 on the TAI scale
17 18 19 |
# File 'lib/sys/sv/statusbytes.rb', line 17 def wantflag @wantflag end |
Instance Method Details
#elapsed ⇒ Object
Number of seconds since service was most recently started or stopped.
31 32 33 |
# File 'lib/sys/sv/statusbytes.rb', line 31 def elapsed ::Time.now.to_f - epoch() end |
#epoch ⇒ Object
Returns the number of seconds since the UNIX epoch since the service was most recently started or stopped.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/sys/sv/statusbytes.rb', line 37 def epoch return @epoch if @epoch # assemble UNIX-scale seconds from TAI64N label hi32, lo32, nano = @bytes.unpack('N N N') @epoch = (hi32 << 32) + lo32 - TAI_EPOCH if @epoch <= 0 @epoch = 0.0 else @epoch += nano / 1e9 end @epoch end |