From 29ed8c22801e4b447ae34546d167863154ce64f8 Mon Sep 17 00:00:00 2001 From: "Glenn Y. Rolland" Date: Sat, 10 Sep 2011 13:53:19 +0200 Subject: [PATCH] qasim-gui: test liveness of lock owner. --- bin/qasim-gui.rb | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/bin/qasim-gui.rb b/bin/qasim-gui.rb index 5867c3d..c201c59 100755 --- a/bin/qasim-gui.rb +++ b/bin/qasim-gui.rb @@ -218,15 +218,23 @@ module Qasim fd = IO::sysopen( lockfname, Fcntl::O_WRONLY | Fcntl::O_EXCL | Fcntl::O_CREAT) f = IO.open(fd) - f.syswrite( "Process.pid\n" ) + 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 + Process.kill(0, masterpid.to_i) warn "error: Another instance of %s is already running." % APP_NAME exit 1 + rescue Errno::ESRCH => e + f = IO.open(fd) + f.syswrite( "#{Process.pid}\n" ) + f.close + @app.exec ensure masterpid = File.read(lockfname).strip - if masterpid == Process.pid then + if masterpid.to_i == Process.pid then FileUtils.rm lockfname end end