From 054f2aa52410081a6761e071fad48d3e999a8ce1 Mon Sep 17 00:00:00 2001 From: "Glenn Y. Rolland" Date: Fri, 27 Jul 2012 11:35:50 +0200 Subject: [PATCH 1/4] Cleanup main app code. --- bin/qasim-gui.rb | 57 +++++++++++++++++++++++++++++------------------- 1 file changed, 34 insertions(+), 23 deletions(-) diff --git a/bin/qasim-gui.rb b/bin/qasim-gui.rb index ef4bd12..4ae3055 100755 --- a/bin/qasim-gui.rb +++ b/bin/qasim-gui.rb @@ -26,7 +26,12 @@ end module Qasim - class QasimGui + class QasimApp + def initialize + end + end + + class QasimGui < QasimApp def initialize @@ -207,32 +212,27 @@ module Qasim end - # - # - # - def run - # create lock - have_lock = true - - FileUtils.mkdir_p APP_CONFIG_DIR unless File.exist? APP_CONFIG_DIR - lockfname = File.join APP_CONFIG_DIR, "lock" - fd = IO::sysopen( lockfname, - Fcntl::O_WRONLY | Fcntl::O_EXCL | Fcntl::O_CREAT) - 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 + def lock_set begin + # create lock + have_lock = true + + FileUtils.mkdir_p APP_CONFIG_DIR unless File.exist? APP_CONFIG_DIR + lockfname = File.join APP_CONFIG_DIR, "lock" + fd = IO::sysopen( lockfname, + Fcntl::O_WRONLY | Fcntl::O_EXCL | Fcntl::O_CREAT) + f = IO.open(fd) + f.syswrite( "#{Process.pid}\n" ) + f.close + rescue Errno::EEXIST => e + # test if the other process still exist + masterpid = File.read(lockfname).strip # 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 + # # From c576b59d1624f943358e9a5eb7d618b54cddb653 Mon Sep 17 00:00:00 2001 From: "Glenn Y. Rolland" Date: Fri, 27 Jul 2012 11:41:34 +0200 Subject: [PATCH 2/4] parse_map now checks if directory exists. --- lib/qasim/config.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/qasim/config.rb b/lib/qasim/config.rb index 4b74ef9..0162c06 100644 --- a/lib/qasim/config.rb +++ b/lib/qasim/config.rb @@ -35,7 +35,10 @@ module Qasim #rdebug "Config: #{@config_dir}/config" @maps = [] - Find.find( @config_dir, APP_SYSCONFIG_DIR ) do |path| + map_dirs = [@config_dir, APP_SYSCONFIG_DIR].select{ |d| + File.exists? d and File.directory? d + } + Find.find( *map_dirs ) do |path| if File.file? path if File.basename( path ) =~ /.map$/ begin From ac482410ce45840ed485cbf3ea8f82d186dd1af7 Mon Sep 17 00:00:00 2001 From: "Glenn Y. Rolland" Date: Fri, 27 Jul 2012 11:46:58 +0200 Subject: [PATCH 3/4] Makefile: fix installation paths. --- Makefile | 6 +----- lib/qasim/Makefile | 4 ---- 2 files changed, 1 insertion(+), 9 deletions(-) delete mode 100644 lib/qasim/Makefile diff --git a/Makefile b/Makefile index bb3fc37..f83adfc 100644 --- a/Makefile +++ b/Makefile @@ -10,10 +10,6 @@ RUBYVERSION=1.8 RDOC=rdoc$(RUBYVERSION) all: - $(MAKE) -C $(NAME) - -clean: - $(MAKE) -C $(NAME) clean doc: build-doc @@ -50,7 +46,7 @@ install-bin: #install -D -o root -g root -m 755 $(CURDIR)/bin/$(NAME)-gui.rb $(BINDIR)/$(NAME)-gui install-lib: - for libfile in $(NAME)/*.rb ; do \ + for libfile in lib/*.rb lib/**/*.rb ; do \ install -D -o root -g root -m 644 $$libfile $(SHAREDIR)/$(NAME)/$$libfile; \ done diff --git a/lib/qasim/Makefile b/lib/qasim/Makefile deleted file mode 100644 index c2e8812..0000000 --- a/lib/qasim/Makefile +++ /dev/null @@ -1,4 +0,0 @@ - -clean: - - From 39788ae5cbed4c00dff859a9d937605704ccba96 Mon Sep 17 00:00:00 2001 From: "Glenn Y. Rolland" Date: Fri, 27 Jul 2012 11:50:34 +0200 Subject: [PATCH 4/4] Makefile: added clean rule. --- Makefile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Makefile b/Makefile index f83adfc..e0c94d9 100644 --- a/Makefile +++ b/Makefile @@ -11,6 +11,8 @@ RDOC=rdoc$(RUBYVERSION) all: +clean: + doc: build-doc .PHONY: build-doc