diff options
author | Matthew Wild <mwild1@gmail.com> | 2010-01-11 00:14:33 +0000 |
---|---|---|
committer | Matthew Wild <mwild1@gmail.com> | 2010-01-11 00:14:33 +0000 |
commit | 815222417a3a085c87380f429f0507f43eedd2e5 (patch) | |
tree | c0898165ef6059d3ae7ae92805328ae040f5d45b | |
parent | 886d6d168fdc777c4017011e6acaf382aa628456 (diff) | |
download | prosody-815222417a3a085c87380f429f0507f43eedd2e5.tar.gz prosody-815222417a3a085c87380f429f0507f43eedd2e5.zip |
util.prosodyctl: Report Prosody as not running if the pidfile isn't locked
-rw-r--r-- | util/prosodyctl.lua | 11 |
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; |