From 37ba438ad9c4cc135dea4043ae57be1d929a4569 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sat, 10 Nov 2012 23:39:22 +0100 Subject: mod_posix: Remove console and stdout logging sinks before daemonizing --- plugins/mod_posix.lua | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/plugins/mod_posix.lua b/plugins/mod_posix.lua index db594ccc..ed64fc34 100644 --- a/plugins/mod_posix.lua +++ b/plugins/mod_posix.lua @@ -136,8 +136,16 @@ if daemonize == nil then end end +local function remove_log_sinks() + local lm = require "core.loggingmanager"; + lm.register_sink_type("console", nil); + lm.register_sink_type("stdout", nil); + lm.reload_logging(); +end + if daemonize then local function daemonize_server() + remove_log_sinks(); local ok, ret = pposix.daemonize(); if not ok then module:log("error", "Failed to daemonize: %s", ret); -- cgit v1.2.3 From acbda76a756d27c406591f0a8ca24e27f3c3f8b8 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sat, 10 Nov 2012 23:41:53 +0100 Subject: util.pposix: Prevent FDs 0, 1 and 2 from being assigned to connections --- util-src/pposix.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/util-src/pposix.c b/util-src/pposix.c index 191e276e..05303d99 100644 --- a/util-src/pposix.c +++ b/util-src/pposix.c @@ -89,6 +89,10 @@ static int lc_daemonize(lua_State *L) close(0); close(1); close(2); + /* Make sure accidental use of FDs 0, 1, 2 don't cause weirdness */ + open("/dev/null", O_RDONLY); + open("/dev/null", O_WRONLY); + open("/dev/null", O_WRONLY); /* Final fork, use it wisely */ if(fork()) -- cgit v1.2.3 From 8f3a73f5c58b6e2ef954fc61f8ae84ae71d1ff86 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sun, 11 Nov 2012 23:44:56 +0100 Subject: mod_posix: Log a message explaining that we are detaching from the console --- plugins/mod_posix.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/mod_posix.lua b/plugins/mod_posix.lua index ed64fc34..e871e5cf 100644 --- a/plugins/mod_posix.lua +++ b/plugins/mod_posix.lua @@ -145,6 +145,7 @@ end if daemonize then local function daemonize_server() + module:log("info", "Prosody is about to detach from the console, disabling further console output"); remove_log_sinks(); local ok, ret = pposix.daemonize(); if not ok then -- cgit v1.2.3