aboutsummaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2010-01-13 00:03:22 +0000
committerMatthew Wild <mwild1@gmail.com>2010-01-13 00:03:22 +0000
commit275444ab8281377a6711f99d806bdc09bb907299 (patch)
treec2eb3b53f2257d71fce2b39bb294cd8ecb2ba0dc /plugins
parent815222417a3a085c87380f429f0507f43eedd2e5 (diff)
downloadprosody-275444ab8281377a6711f99d806bdc09bb907299.tar.gz
prosody-275444ab8281377a6711f99d806bdc09bb907299.zip
mod_posix: Adjust file open mode depending on whether file exists (take that fopen designers!!!)
Diffstat (limited to 'plugins')
-rw-r--r--plugins/mod_posix.lua4
1 files changed, 3 insertions, 1 deletions
diff --git a/plugins/mod_posix.lua b/plugins/mod_posix.lua
index 8b0bd399..ed0dbd87 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;
@@ -78,7 +79,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");