Merge 0.10->trunk
[prosody.git] / plugins / mod_posix.lua
index c9b9f3aa03986506831fa35c29aae9bf5ddd43d7..7333fe47cbb8b18860612b7fbbc6ccf4cff60e1d 100644 (file)
@@ -14,8 +14,8 @@ if pposix._VERSION ~= want_pposix_version then
        module:log("warn", "Unknown version (%s) of binary pposix module, expected %s. Perhaps you need to recompile?", tostring(pposix._VERSION), want_pposix_version);
 end
 
-local signal = select(2, pcall(require, "util.signal"));
-if type(signal) == "string" then
+local have_signal, signal = pcall(require, "util.signal");
+if not have_signal then
        module:log("warn", "Couldn't load signal library, won't respond to SIGTERM");
 end
 
@@ -31,27 +31,27 @@ pposix.umask(umask);
 
 -- Allow switching away from root, some people like strange ports.
 module:hook("server-started", function ()
-               local uid = module:get_option("setuid");
-               local gid = module:get_option("setgid");
-               if gid then
-                       local success, msg = pposix.setgid(gid);
-                       if success then
-                               module:log("debug", "Changed group to %s successfully.", gid);
-                       else
-                               module:log("error", "Failed to change group to %s. Error: %s", gid, msg);
-                               prosody.shutdown("Failed to change group to %s", gid);
-                       end
+       local uid = module:get_option("setuid");
+       local gid = module:get_option("setgid");
+       if gid then
+               local success, msg = pposix.setgid(gid);
+               if success then
+                       module:log("debug", "Changed group to %s successfully.", gid);
+               else
+                       module:log("error", "Failed to change group to %s. Error: %s", gid, msg);
+                       prosody.shutdown("Failed to change group to %s", gid);
                end
-               if uid then
-                       local success, msg = pposix.setuid(uid);
-                       if success then
-                               module:log("debug", "Changed user to %s successfully.", uid);
-                       else
-                               module:log("error", "Failed to change user to %s. Error: %s", uid, msg);
-                               prosody.shutdown("Failed to change user to %s", uid);
-                       end
+       end
+       if uid then
+               local success, msg = pposix.setuid(uid);
+               if success then
+                       module:log("debug", "Changed user to %s successfully.", uid);
+               else
+                       module:log("error", "Failed to change user to %s. Error: %s", uid, msg);
+                       prosody.shutdown("Failed to change user to %s", uid);
                end
-       end);
+       end
+end);
 
 -- Don't even think about it!
 if not prosody.start_time then -- server-starting
@@ -59,7 +59,7 @@ if not prosody.start_time then -- server-starting
        if not suid or suid == 0 or suid == "root" then
                if pposix.getuid() == 0 and not module:get_option("run_as_root") then
                        module:log("error", "Danger, Will Robinson! Prosody doesn't need to be run as root, so don't do it!");
-                       module:log("error", "For more information on running Prosody as root, see http://prosody.im/doc/root");
+                       module:log("error", "For more information on running Prosody as root, see https://prosody.im/doc/root");
                        prosody.shutdown("Refusing to run as root");
                end
        end
@@ -162,7 +162,7 @@ end
 module:hook("server-stopped", remove_pidfile);
 
 -- Set signal handlers
-if signal.signal then
+if have_signal then
        signal.signal("SIGTERM", function ()
                module:log("warn", "Received SIGTERM");
                prosody.unlock_globals();