aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/mod_posix.lua
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/mod_posix.lua')
-rw-r--r--plugins/mod_posix.lua80
1 files changed, 35 insertions, 45 deletions
diff --git a/plugins/mod_posix.lua b/plugins/mod_posix.lua
index b289fa44..fccc7a2b 100644
--- a/plugins/mod_posix.lua
+++ b/plugins/mod_posix.lua
@@ -1,24 +1,26 @@
-- Prosody IM
-- Copyright (C) 2008-2010 Matthew Wild
-- Copyright (C) 2008-2010 Waqas Hussain
---
+--
-- This project is MIT/X11 licensed. Please see the
-- COPYING file in the source package for more information.
--
-local want_pposix_version = "0.3.6";
+local want_pposix_version = "0.4.0";
local pposix = assert(require "util.pposix");
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);
+ 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
+local format = require "util.format".format;
local lfs = require "lfs";
local stat = lfs.attributes;
@@ -26,38 +28,38 @@ local prosody = _G.prosody;
module:set_global(); -- we're a global module
-local umask = module:get_option("umask") or "027";
+local umask = module:get_option_string("umask", "027");
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
local suid = module:get_option("setuid");
if not suid or suid == 0 or suid == "root" then
- if pposix.getuid() == 0 and not module:get_option("run_as_root") then
+ if pposix.getuid() == 0 and not module:get_option_boolean("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");
prosody.shutdown("Refusing to run as root");
@@ -80,7 +82,7 @@ local function write_pidfile()
if pidfile_handle then
remove_pidfile();
end
- pidfile = module:get_option_string("pidfile");
+ pidfile = module:get_option_path("pidfile", nil, "data");
if pidfile then
local err;
local mode = stat(pidfile) and "r+" or "w+";
@@ -112,31 +114,19 @@ local function write_pidfile()
end
local syslog_opened;
-function syslog_sink_maker(config)
+function syslog_sink_maker(config) -- luacheck: ignore 212/config
if not syslog_opened then
pposix.syslog_open("prosody", module:get_option_string("syslog_facility"));
syslog_opened = true;
end
- local syslog, format = pposix.syslog_log, string.format;
+ local syslog = pposix.syslog_log;
return function (name, level, message, ...)
- if ... then
- syslog(level, name, format(message, ...));
- else
- syslog(level, name, message);
- end
+ syslog(level, name, format(message, ...));
end;
end
require "core.loggingmanager".register_sink_type("syslog", syslog_sink_maker);
-local daemonize = module:get_option("daemonize");
-if daemonize == nil then
- local no_daemonize = module:get_option("no_daemonize"); --COMPAT w/ 0.5
- daemonize = not no_daemonize;
- if no_daemonize ~= nil then
- module:log("warn", "The 'no_daemonize' option is now replaced by 'daemonize'");
- module:log("warn", "Update your config from 'no_daemonize = %s' to 'daemonize = %s'", tostring(no_daemonize), tostring(daemonize));
- end
-end
+local daemonize = module:get_option("daemonize", prosody.installed);
local function remove_log_sinks()
local lm = require "core.loggingmanager";
@@ -170,7 +160,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();
@@ -183,7 +173,7 @@ if signal.signal then
prosody.reload_config();
prosody.reopen_logfiles();
end);
-
+
signal.signal("SIGINT", function ()
module:log("info", "Received SIGINT");
prosody.unlock_globals();