lib/perobs/StackFile.rb in perobs-2.4.1 vs lib/perobs/StackFile.rb in perobs-2.4.2
- old
+ new
@@ -52,16 +52,20 @@
@f = File.open(@file_name, 'wb+')
end
rescue => e
PEROBS.log.fatal "Cannot open stack file #{@file_name}: #{e.message}"
end
+ unless @f.flock(File::LOCK_NB | File::LOCK_EX)
+ PEROBS.log.fatal 'Database stack file is locked by another process'
+ end
end
# Close the stack file. This method must be called before the program is
# terminated to avoid data loss.
def close
begin
@f.flush
+ @f.flock(File::LOCK_UN)
@f.close
rescue IOError => e
PEROBS.log.fatal "Cannot close stack file #{@file_name}: #{e.message}"
end
end