aboutsummaryrefslogtreecommitdiffstats
path: root/util
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2010-01-11 00:14:33 +0000
committerMatthew Wild <mwild1@gmail.com>2010-01-11 00:14:33 +0000
commit815222417a3a085c87380f429f0507f43eedd2e5 (patch)
treec0898165ef6059d3ae7ae92805328ae040f5d45b /util
parent886d6d168fdc777c4017011e6acaf382aa628456 (diff)
downloadprosody-815222417a3a085c87380f429f0507f43eedd2e5.tar.gz
prosody-815222417a3a085c87380f429f0507f43eedd2e5.zip
util.prosodyctl: Report Prosody as not running if the pidfile isn't locked
Diffstat (limited to 'util')
-rw-r--r--util/prosodyctl.lua11
1 files changed, 9 insertions, 2 deletions
diff --git a/util/prosodyctl.lua b/util/prosodyctl.lua
index b24e194d..4d2c68ee 100644
--- a/util/prosodyctl.lua
+++ b/util/prosodyctl.lua
@@ -12,6 +12,7 @@ local encodings = require "util.encodings";
local stringprep = encodings.stringprep;
local usermanager = require "core.usermanager";
local signal = require "util.signal";
+local lfs = require "lfs";
local nodeprep, nameprep = stringprep.nodeprep, stringprep.nameprep;
@@ -64,11 +65,17 @@ function getpid()
return false, "no-pidfile";
end
- local file, err = io.open(pidfile);
+ local file, err = io.open(pidfile, "w");
if not file then
return false, "pidfile-read-failed", err;
end
+ local locked, err = lfs.lock(file, "w");
+ if locked then
+ file:close();
+ return false, "pidfile-not-locked";
+ end
+
local pid = tonumber(file:read("*a"));
file:close();
@@ -82,7 +89,7 @@ end
function isrunning()
local ok, pid, err = _M.getpid();
if not ok then
- if pid == "pidfile-read-failed" then
+ if pid == "pidfile-read-failed" or pid == "pidfile-not-locked" then
-- Report as not running, since we can't open the pidfile
-- (it probably doesn't exist)
return true, false;