lib/perobs/LockFile.rb in perobs-3.0.2 vs lib/perobs/LockFile.rb in perobs-4.0.0
- old
+ new
@@ -68,16 +68,18 @@
def lock
retries = @max_retries
while retries > 0
begin
@file = File.open(@file_name, File::RDWR | File::CREAT, 0644)
+ @file.sync = true
if @file.flock(File::LOCK_EX | File::LOCK_NB)
# We have taken the lock. Write the PID into the file and leave it
# open.
@file.write($$)
@file.flush
+ @file.fsync
@file.truncate(@file.pos)
PEROBS.log.debug "Lock file #{@file_name} has been taken for " +
"process #{$$}"
return true
@@ -127,9 +129,10 @@
return false
end
begin
@file.flock(File::LOCK_UN)
+ @file.fsync
@file.close
forced_unlock
PEROBS.log.debug "Lock file #{@file_name} for PID #{$$} has been " +
"released"
rescue => e