From 1fa52221141265c249bc1dc2e86aa72a8b5f9e34 Mon Sep 17 00:00:00 2001 From: Paul Leader Date: Wed, 25 Feb 2015 22:52:25 +0000 Subject: [PATCH] Fix PidFile.pid to use the default pidfile path. If a path is not passed to PidFile.pid then use the default pidfile path. --- lib/pidfile.rb | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/pidfile.rb b/lib/pidfile.rb index fa104b4..9863345 100644 --- a/lib/pidfile.rb +++ b/lib/pidfile.rb @@ -95,8 +95,14 @@ def locktime # Class Methods #-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=# + # Return the default pidfile path + def self.default_pidfile + File.join(DEFAULT_OPTIONS[:piddir], DEFAULT_OPTIONS[:pidfile]) + end + # Returns the PID, if any, of the instantiating process def self.pid(path=nil) + path ||= default_pidfile if pidfile_exists?(path) open(path, 'r').read.to_i end @@ -104,7 +110,7 @@ def self.pid(path=nil) # class method for determining the existence of pidfile def self.pidfile_exists?(path=nil) - path ||= File.join(DEFAULT_OPTIONS[:piddir], DEFAULT_OPTIONS[:pidfile]) + path ||= default_pidfile File.exists?(path) end @@ -112,7 +118,7 @@ def self.pidfile_exists?(path=nil) # boolean stating whether the calling program is already running def self.running?(path=nil) calling_pid = nil - path ||= File.join(DEFAULT_OPTIONS[:piddir], DEFAULT_OPTIONS[:pidfile]) + path ||= default_pidfile if pidfile_exists?(path) calling_pid = pid(path)