@@ -7,6 +7,7 @@ module Imap::Backup
77 class Lockfile
88 # An error that is thrown if a lockfile already exists
99 class LockfileExistsError < StandardError ; end
10+ class ProcessStartTimeUnavailableError < StandardError ; end
1011
1112 attr_reader :path
1213
@@ -53,7 +54,9 @@ def stale?
5354
5455 return true if proc_table_entry . nil?
5556
56- proc_table_entry . starttime != starttime
57+ other_starttime = starttime ( proc_table_entry )
58+
59+ other_starttime != starttime
5760 end
5861
5962 private
@@ -62,9 +65,11 @@ def create
6265 pid = Process . pid
6366 proc_table_entry = Sys ::ProcTable . ps ( pid : pid )
6467
65- raise "Unable to get process info for PID #{ pid } " if proc_table_entry . nil?
68+ if proc_table_entry . nil?
69+ raise ProcessStartTimeUnavailableError , "Unable to get process info for PID #{ pid } "
70+ end
6671
67- starttime = proc_table_entry . starttime
72+ starttime = starttime ( proc_table_entry )
6873
6974 data = {
7075 pid : pid ,
@@ -74,5 +79,16 @@ def create
7479 json_data = JSON . generate ( data )
7580 File . write ( path , json_data )
7681 end
82+
83+ def starttime ( proc_table_entry )
84+ case
85+ when proc_table_entry . respond_to? ( :starttime )
86+ proc_table_entry . starttime
87+ when proc_table_entry . respond_to? ( :start_tvsec )
88+ proc_table_entry . start_tvsec
89+ else
90+ raise ProcessStartTimeUnavailableError , "Proctable entry structure unknown"
91+ end
92+ end
7793 end
7894end
0 commit comments