From d77e181372113179273c8c03cec766ac1cf3a768 Mon Sep 17 00:00:00 2001 From: Brian Cully Date: Fri, 9 Jul 2010 01:16:09 +0100 Subject: 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. --- plugins/mod_posix.lua | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'plugins/mod_posix.lua') 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 -- cgit v1.2.3