From ed6a74ff47934bd2694cc34dbfbdde3361c0c88a Mon Sep 17 00:00:00 2001 From: "Glenn Y. Rolland" Date: Fri, 16 Sep 2011 00:40:12 +0200 Subject: [PATCH] qasim-gui: Locker pid testing was buggy. Fixed. --- bin/qasim-gui.rb | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/bin/qasim-gui.rb b/bin/qasim-gui.rb index c201c59..0cf8ac7 100755 --- a/bin/qasim-gui.rb +++ b/bin/qasim-gui.rb @@ -224,14 +224,18 @@ module Qasim 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 + begin + Process.kill(0, masterpid.to_i) + warn "error: Another instance of %s is already running." % APP_NAME + exit 1 + rescue Errno::ESRCH => e + fd = IO::sysopen( lockfname, + Fcntl::O_WRONLY | Fcntl::O_EXCL ) + f = IO.open(fd) + f.syswrite( "#{Process.pid}\n" ) + f.close + @app.exec + end ensure masterpid = File.read(lockfname).strip if masterpid.to_i == Process.pid then