usermanager, mod_auth_internal_hashed, mod_legacyauth: New order of parameters for...
[prosody.git] / plugins / mod_posix.lua
index 52b1e0e6e510533ca87987ce01da71b0a1d02177..77b2f2a4ee25ae16d23d7198e834be09f7b13e10 100644 (file)
@@ -95,8 +95,17 @@ local function write_pidfile()
                                pidfile_handle = nil;
                                prosody.shutdown("Prosody already running");
                        else
-                               pidfile_handle:write(tostring(pposix.getpid()));
-                               pidfile_handle:flush();
+                               pidfile_handle:close();
+                               pidfile_handle, err = io.open(pidfile, "w+");
+                               if not pidfile_handle then
+                                       module:log("error", "Couldn't write pidfile at %s; %s", pidfile, err);
+                                       prosody.shutdown("Couldn't write pidfile");
+                               else
+                                       if lfs.lock(pidfile_handle, "w") then
+                                               pidfile_handle:write(tostring(pposix.getpid()));
+                                               pidfile_handle:flush();
+                                       end
+                               end
                        end
                end
        end