Cleanup main app code.
This commit is contained in:
parent
37d4fae023
commit
054f2aa524
1 changed files with 34 additions and 23 deletions
|
@ -26,7 +26,12 @@ end
|
|||
|
||||
|
||||
module Qasim
|
||||
class QasimGui
|
||||
class QasimApp
|
||||
def initialize
|
||||
end
|
||||
end
|
||||
|
||||
class QasimGui < QasimApp
|
||||
|
||||
|
||||
def initialize
|
||||
|
@ -207,10 +212,8 @@ module Qasim
|
|||
end
|
||||
|
||||
|
||||
#
|
||||
#
|
||||
#
|
||||
def run
|
||||
def lock_set
|
||||
begin
|
||||
# create lock
|
||||
have_lock = true
|
||||
|
||||
|
@ -221,18 +224,15 @@ module Qasim
|
|||
f = IO.open(fd)
|
||||
f.syswrite( "#{Process.pid}\n" )
|
||||
f.close
|
||||
@app.exec
|
||||
rescue Errno::EEXIST => e
|
||||
# test if the other process still exist
|
||||
masterpid = File.read(lockfname).strip
|
||||
begin
|
||||
# FIXME: test if the other process exists
|
||||
other_path = "/proc/#{masterpid.to_i}"
|
||||
if File.exists? other_path then
|
||||
cmdline = File.read( File.join( other_path, 'cmdline' ) )
|
||||
if cmdline =~ /qasim/ then
|
||||
warn "error: Another instance of %s is already running." % APP_NAME
|
||||
exit 1
|
||||
raise LockError, "Another instance of %s is already running." % APP_NAME
|
||||
end
|
||||
end
|
||||
fd = IO::sysopen( lockfname,
|
||||
|
@ -240,15 +240,26 @@ module Qasim
|
|||
f = IO.open(fd)
|
||||
f.syswrite( "#{Process.pid}\n" )
|
||||
f.close
|
||||
@app.exec
|
||||
end
|
||||
ensure
|
||||
end
|
||||
|
||||
def lock_unset
|
||||
masterpid = File.read(lockfname).strip
|
||||
if masterpid.to_i == Process.pid then
|
||||
FileUtils.rm lockfname
|
||||
end
|
||||
end
|
||||
|
||||
#
|
||||
#
|
||||
#
|
||||
def run
|
||||
lock_set
|
||||
@app.exec
|
||||
ensure
|
||||
lock_unset
|
||||
end
|
||||
|
||||
|
||||
#
|
||||
#
|
||||
|
|
Loading…
Reference in a new issue