Changeset

2795:d6fcd13c07e7

mod_posix: Adjust file open mode depending on whether file exists (take that fopen designers!!!)
author Matthew Wild <mwild1@gmail.com>
date Wed, 13 Jan 2010 00:03:22 +0000
parents 2794:5f14cd94a563
children 2796:1e287badd033
files plugins/mod_posix.lua
diffstat 1 files changed, 3 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/plugins/mod_posix.lua	Mon Jan 11 00:14:33 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;
 
@@ -78,7 +79,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");