From c5f00c38da336ed929a5b1613a4b2e7fef42adbe Mon Sep 17 00:00:00 2001 From: sapier Date: Sun, 1 Jun 2014 00:41:48 +0200 Subject: [PATCH] Redirect stdin/stderr/stdout to /dev/null in daemon mode --- src/porting.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/porting.cpp b/src/porting.cpp index ef461242..ca43452a 100644 --- a/src/porting.cpp +++ b/src/porting.cpp @@ -635,6 +635,7 @@ void daemonize() pidfile = 0; } + pid_t pid = fork(); if (pid > 0) { @@ -648,8 +649,9 @@ void daemonize() } exit (0); } else if (pid == 0) { - fclose(stdout); - fclose(stderr); + freopen("/dev/null","w",stdout); + freopen("/dev/null","w",stderr); + freopen("/dev/null","r",stdout); return; } -- 2.30.2