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:
18 19 20 21 22 23 24 25 26 |
# File 'lib/sys/sv/statusbytes.rb', line 18 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
16 17 18 |
# File 'lib/sys/sv/statusbytes.rb', line 16 def pauseflag @pauseflag end |
#pid ⇒ Object (readonly)
time_t 0 on the TAI scale
16 17 18 |
# File 'lib/sys/sv/statusbytes.rb', line 16 def pid @pid end |
#wantflag ⇒ Object (readonly)
time_t 0 on the TAI scale
16 17 18 |
# File 'lib/sys/sv/statusbytes.rb', line 16 def wantflag @wantflag end |
Instance Method Details
#elapsed ⇒ Object
Number of seconds since service was most recently started or stopped.
30 31 32 |
# File 'lib/sys/sv/statusbytes.rb', line 30 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.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/sys/sv/statusbytes.rb', line 36 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/10e9 end @epoch end |