diff options
author | Matthew Wild <mwild1@gmail.com> | 2010-01-13 00:03:22 +0000 |
---|---|---|
committer | Matthew Wild <mwild1@gmail.com> | 2010-01-13 00:03:22 +0000 |
commit | 40216063d254b9d7fdf7d1ed3fc0c6b94ce85d03 (patch) | |
tree | 9970d5b88e05286d50c195b9ee4978fdf52648ce /plugins/mod_posix.lua | |
parent | cafffad5b85f50aab315bec3867d9eec4f4d50f1 (diff) | |
download | prosody-40216063d254b9d7fdf7d1ed3fc0c6b94ce85d03.tar.gz prosody-40216063d254b9d7fdf7d1ed3fc0c6b94ce85d03.zip |
mod_posix: Adjust file open mode depending on whether file exists (take that fopen designers!!!)
Diffstat (limited to 'plugins/mod_posix.lua')
-rw-r--r-- | plugins/mod_posix.lua | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/plugins/mod_posix.lua b/plugins/mod_posix.lua index ab3a8a26..55d52ccd 100644 --- a/plugins/mod_posix.lua +++ b/plugins/mod_posix.lua @@ -20,6 +20,7 @@ end local logger_set = require "util.logger".setwriter; local lfs = require "lfs"; +local stat = lfs.attributes; local prosody = _G.prosody; @@ -81,7 +82,8 @@ local function write_pidfile() end pidfile = module:get_option("pidfile"); if pidfile then - pidfile_handle, err = io.open(pidfile, "a+"); + local mode = stat(pidfile) and "r+" or "w+"; + pidfile_handle, err = io.open(pidfile, mode); if not pidfile_handle then module:log("error", "Couldn't write pidfile at %s; %s", pidfile, err); prosody.shutdown("Couldn't write pidfile"); |