Mercurial > prosody-hg
comparison plugins/mod_posix.lua @ 3340:0769cc5f34b6
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.
| author | Brian Cully <bjc@junctionnetworks.com> |
|---|---|
| date | Fri, 09 Jul 2010 01:16:09 +0100 |
| parents | 0c7beabfed5b |
| children | a8a3e662fea7 |
comparison
equal
deleted
inserted
replaced
| 3339:7893055e54d1 | 3340:0769cc5f34b6 |
|---|---|
| 93 local other_pid = pidfile_handle:read("*a"); | 93 local other_pid = pidfile_handle:read("*a"); |
| 94 module:log("error", "Another Prosody instance seems to be running with PID %s, quitting", other_pid); | 94 module:log("error", "Another Prosody instance seems to be running with PID %s, quitting", other_pid); |
| 95 pidfile_handle = nil; | 95 pidfile_handle = nil; |
| 96 prosody.shutdown("Prosody already running"); | 96 prosody.shutdown("Prosody already running"); |
| 97 else | 97 else |
| 98 pidfile_handle, err = io.open(pidfile, "w+"); | |
| 99 if not pidfile_handle then | |
| 100 module:log("error", "Couldn't write pidfile at %s; %s", pidfile, err); | |
| 101 prosody.shutdown("Couldn't write pidfile"); | |
| 102 end | |
| 98 pidfile_handle:write(tostring(pposix.getpid())); | 103 pidfile_handle:write(tostring(pposix.getpid())); |
| 99 pidfile_handle:flush(); | 104 pidfile_handle:flush(); |
| 100 end | 105 end |
| 101 end | 106 end |
| 102 end | 107 end |
