# HG changeset patch # User Matthew Wild # Date 1263341002 0 # Node ID 260601859c9fdbde9f51d900049e15a3964c71a0 # Parent 0b3184f3c9e42c8dd017c3c5ae647cbbd037634f mod_posix: Adjust file open mode depending on whether file exists (take that fopen designers!!!) diff -r 0b3184f3c9e4 -r 260601859c9f plugins/mod_posix.lua --- a/plugins/mod_posix.lua Tue Jan 12 15:35:36 2010 +0000 +++ b/plugins/mod_posix.lua Wed Jan 13 00:03:22 2010 +0000 @@ -20,6 +20,7 @@ local logger_set = require "util.logger".setwriter; local lfs = require "lfs"; +local stat = lfs.attributes; local prosody = _G.prosody; @@ -81,7 +82,8 @@ 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");