Module: Agent::Lock::ProcessInfo::LegacyStart
- Defined in:
- lib/agent/lock/process_info/legacy_start.rb
Overview
Reads the start time a 4.0.0 gem recorded for a lock's holder.
That gem stored ps -o lstart= as printed, so the text is a wall
clock in a time zone, and in a language, the record does not name:
Sat Nov 28 13:57:53 2026 TZ=America/Los_Angeles
Sa. 28 Nov. 13:57:53 2026 LC_ALL=de_DE.UTF-8
2026년 11월 28일 토요일 13시 57분 53초
It cannot be turned back into an instant, so the question is asked
the other way round: could the process now at that pid, whose start
instant is known, have been printed as this text on some zone's
clock? Only the numbers are compared, because they are the one part
every locale ps knows prints in ASCII digits on a 24-hour clock.
A recycled pid passes only when its process started a whole number of quarter hours from the old one, on a matching date: one start second in 900. Passing keeps a dead holder's lock until somebody breaks it. Failing would reap a live holder's lock, which is the failure this exists to prevent.
Constant Summary collapse
- OFFSETS =
Every UTC offset a zone may have, in seconds: whole quarter hours from UTC-12:00 to UTC+14:00.
(-48..56).map { |quarters| quarters * 900 }.freeze
Class Method Summary collapse
-
.on_clock?(numbers, wall) ⇒ Boolean
Hour, minute and second sit side by side in every locale; the day and the year sit around them in an order that varies, and the year may be printed as two digits.
-
.shows?(text, instant) ⇒ Boolean
Whether some zone's clock showed
textatinstant.
Class Method Details
.on_clock?(numbers, wall) ⇒ Boolean
Hour, minute and second sit side by side in every locale; the day and the year sit around them in an order that varies, and the year may be printed as two digits.
50 51 52 53 54 55 56 |
# File 'lib/agent/lock/process_info/legacy_start.rb', line 50 def on_clock?(numbers, wall) at = numbers.each_cons(3).find_index([wall.hour, wall.min, wall.sec]) return false if at.nil? date = numbers[0...at] + numbers[(at + 3)..] date.include?(wall.day) && date.intersect?([wall.year, wall.year % 100]) end |
.shows?(text, instant) ⇒ Boolean
Returns whether some zone's clock showed text at instant.
36 37 38 39 40 41 |
# File 'lib/agent/lock/process_info/legacy_start.rb', line 36 def shows?(text, instant) # As bytes: a locale that is not UTF-8 leaves text no regexp will # scan as characters, and the digits are ASCII either way. numbers = text.to_s.b.scan(/\d+/).map(&:to_i) OFFSETS.any? { |offset| on_clock?(numbers, instant.getutc + offset) } end |