MUC: No need to call is_admin twice now, global admins are admins on hosts
[prosody.git] / plugins / mod_posix.lua
index 11e3c418b90831502cd3ad9f55038cf98433c304..77b2f2a4ee25ae16d23d7198e834be09f7b13e10 100644 (file)
@@ -95,13 +95,17 @@ local function write_pidfile()
                                pidfile_handle = nil;
                                prosody.shutdown("Prosody already running");
                        else
+                               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
-                               pidfile_handle:write(tostring(pposix.getpid()));
-                               pidfile_handle:flush();
                        end
                end
        end