aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrian Cully <bjc@junctionnetworks.com>2010-07-09 01:16:09 +0100
committerBrian Cully <bjc@junctionnetworks.com>2010-07-09 01:16:09 +0100
commitd77e181372113179273c8c03cec766ac1cf3a768 (patch)
tree6403b6a8eab53ab0806b0baeb9d819c0598c5198
parented0cef77181841ce3063dccbb79f13ee85a14cae (diff)
downloadprosody-d77e181372113179273c8c03cec766ac1cf3a768.tar.gz
prosody-d77e181372113179273c8c03cec766ac1cf3a768.zip
mod_posix: Truncate the pidfile before writing to ensure that we never overwrite with a PID shorter than the previous, and end with an invalid PID in the file.
-rw-r--r--plugins/mod_posix.lua5
1 files changed, 5 insertions, 0 deletions
diff --git a/plugins/mod_posix.lua b/plugins/mod_posix.lua
index 52b1e0e6..11e3c418 100644
--- a/plugins/mod_posix.lua
+++ b/plugins/mod_posix.lua
@@ -95,6 +95,11 @@ local function write_pidfile()
pidfile_handle = nil;
prosody.shutdown("Prosody already running");
else
+ pidfile_handle, err = io.open(pidfile, "w+");
+ if not pidfile_handle then
+ module:log("error", "Couldn't write pidfile at %s; %s", pidfile, err);
+ prosody.shutdown("Couldn't write pidfile");
+ end
pidfile_handle:write(tostring(pposix.getpid()));
pidfile_handle:flush();
end