Comparison

plugins/mod_posix.lua @ 6888:39c5c49616ab

Merge 0.10->trunk
author Kim Alvefur <zash@zash.se>
date Sun, 27 Sep 2015 00:37:18 +0200
parent 6875:12d68f7b1be0
child 7359:a5a080c12c96
child 7731:a0ee83c4a82c
comparison
equal deleted inserted replaced
6871:e4b5885b7712 6888:39c5c49616ab
12 local pposix = assert(require "util.pposix"); 12 local pposix = assert(require "util.pposix");
13 if pposix._VERSION ~= want_pposix_version then 13 if pposix._VERSION ~= want_pposix_version then
14 module:log("warn", "Unknown version (%s) of binary pposix module, expected %s. Perhaps you need to recompile?", tostring(pposix._VERSION), want_pposix_version); 14 module:log("warn", "Unknown version (%s) of binary pposix module, expected %s. Perhaps you need to recompile?", tostring(pposix._VERSION), want_pposix_version);
15 end 15 end
16 16
17 local signal = select(2, pcall(require, "util.signal")); 17 local have_signal, signal = pcall(require, "util.signal");
18 if type(signal) == "string" then 18 if not have_signal then
19 module:log("warn", "Couldn't load signal library, won't respond to SIGTERM"); 19 module:log("warn", "Couldn't load signal library, won't respond to SIGTERM");
20 end 20 end
21 21
22 local lfs = require "lfs"; 22 local lfs = require "lfs";
23 local stat = lfs.attributes; 23 local stat = lfs.attributes;
29 local umask = module:get_option("umask") or "027"; 29 local umask = module:get_option("umask") or "027";
30 pposix.umask(umask); 30 pposix.umask(umask);
31 31
32 -- Allow switching away from root, some people like strange ports. 32 -- Allow switching away from root, some people like strange ports.
33 module:hook("server-started", function () 33 module:hook("server-started", function ()
34 local uid = module:get_option("setuid"); 34 local uid = module:get_option("setuid");
35 local gid = module:get_option("setgid"); 35 local gid = module:get_option("setgid");
36 if gid then 36 if gid then
37 local success, msg = pposix.setgid(gid); 37 local success, msg = pposix.setgid(gid);
38 if success then 38 if success then
39 module:log("debug", "Changed group to %s successfully.", gid); 39 module:log("debug", "Changed group to %s successfully.", gid);
40 else 40 else
41 module:log("error", "Failed to change group to %s. Error: %s", gid, msg); 41 module:log("error", "Failed to change group to %s. Error: %s", gid, msg);
42 prosody.shutdown("Failed to change group to %s", gid); 42 prosody.shutdown("Failed to change group to %s", gid);
43 end
44 end 43 end
45 if uid then 44 end
46 local success, msg = pposix.setuid(uid); 45 if uid then
47 if success then 46 local success, msg = pposix.setuid(uid);
48 module:log("debug", "Changed user to %s successfully.", uid); 47 if success then
49 else 48 module:log("debug", "Changed user to %s successfully.", uid);
50 module:log("error", "Failed to change user to %s. Error: %s", uid, msg); 49 else
51 prosody.shutdown("Failed to change user to %s", uid); 50 module:log("error", "Failed to change user to %s. Error: %s", uid, msg);
52 end 51 prosody.shutdown("Failed to change user to %s", uid);
53 end 52 end
54 end); 53 end
54 end);
55 55
56 -- Don't even think about it! 56 -- Don't even think about it!
57 if not prosody.start_time then -- server-starting 57 if not prosody.start_time then -- server-starting
58 local suid = module:get_option("setuid"); 58 local suid = module:get_option("setuid");
59 if not suid or suid == 0 or suid == "root" then 59 if not suid or suid == 0 or suid == "root" then
160 end 160 end
161 161
162 module:hook("server-stopped", remove_pidfile); 162 module:hook("server-stopped", remove_pidfile);
163 163
164 -- Set signal handlers 164 -- Set signal handlers
165 if signal.signal then 165 if have_signal then
166 signal.signal("SIGTERM", function () 166 signal.signal("SIGTERM", function ()
167 module:log("warn", "Received SIGTERM"); 167 module:log("warn", "Received SIGTERM");
168 prosody.unlock_globals(); 168 prosody.unlock_globals();
169 prosody.shutdown("Received SIGTERM"); 169 prosody.shutdown("Received SIGTERM");
170 prosody.lock_globals(); 170 prosody.lock_globals();