From c2cc372bbaf2e12f24580eb5d87b61916d33d38a Mon Sep 17 00:00:00 2001 From: "Glenn Y. Rolland" Date: Sun, 4 Sep 2011 04:51:29 +0200 Subject: [PATCH] qasim-gui: prepare for locking. --- bin/qasim-gui.rb | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/bin/qasim-gui.rb b/bin/qasim-gui.rb index 04f2f3e..dd5219b 100755 --- a/bin/qasim-gui.rb +++ b/bin/qasim-gui.rb @@ -7,6 +7,7 @@ $VERBOSE = true require 'pp' require 'set' +require 'fcntl' QASIM_INCLUDE_DIR = "." $:.push QASIM_INCLUDE_DIR @@ -209,7 +210,27 @@ module Qasim # # def run + # create lock + have_lock = true + + lockfname = APP_CONFIG_DIR, "lock" + File.open lockfname, "w" do + unless f.flock File::LOCK_EX | File::LOCK_NB + warn "Another instance of %s is already running." % APP_NAME + exit 1 + end + f.flock File::LOCK_EX + end + + fd = IO::sysopen('/tmp/tempfile', + Fcntl::O_WRONLY | Fcntl::O_EXCL | Fcntl::O_CREAT) + f = IO.open(fd) + f.syswrite("TEMP DATA") + f.close + masterpid = fh.gets @app.exec + ensure + fh.close end