qasim-gui: Clean handling of lock file & lock-related exception.

This commit is contained in:
Glenn Y. Rolland 2012-07-28 16:55:42 +02:00
parent 9f7c941709
commit 967eea139a

View file

@ -1,5 +1,6 @@
#!/usr/bin/env ruby #!/usr/bin/env ruby
require 'rubygems'
require 'Qt4' require 'Qt4'
$DEBUG = true $DEBUG = true
@ -33,6 +34,7 @@ module Qasim
class QasimGui < QasimApp class QasimGui < QasimApp
class LockError < RuntimeError ; end
def initialize def initialize
@config = Config.new @config = Config.new
@ -227,7 +229,6 @@ module Qasim
rescue Errno::EEXIST => e rescue Errno::EEXIST => e
# test if the other process still exist # test if the other process still exist
masterpid = File.read(lockfname).strip masterpid = File.read(lockfname).strip
# FIXME: test if the other process exists
other_path = "/proc/#{masterpid.to_i}" other_path = "/proc/#{masterpid.to_i}"
if File.exists? other_path then if File.exists? other_path then
cmdline = File.read( File.join( other_path, 'cmdline' ) ) cmdline = File.read( File.join( other_path, 'cmdline' ) )
@ -244,6 +245,9 @@ module Qasim
end end
def lock_unset def lock_unset
# remove lock if it exists
lockfname = File.join APP_CONFIG_DIR, "lock"
return unless File.exist? lockfname
masterpid = File.read(lockfname).strip masterpid = File.read(lockfname).strip
if masterpid.to_i == Process.pid then if masterpid.to_i == Process.pid then
FileUtils.rm lockfname FileUtils.rm lockfname
@ -256,6 +260,9 @@ module Qasim
def run def run
lock_set lock_set
@app.exec @app.exec
exit 0
rescue LockError
exit 1
ensure ensure
lock_unset lock_unset
end end