From: sapier Date: Sat, 31 May 2014 22:41:48 +0000 (+0200) Subject: Redirect stdin/stderr/stdout to /dev/null in daemon mode X-Git-Url: http://81.2.79.47:8989/gitweb/?a=commitdiff_plain;h=c5f00c38da336ed929a5b1613a4b2e7fef42adbe;p=zefram%2Fminetest%2Fminetest_engine.git Redirect stdin/stderr/stdout to /dev/null in daemon mode --- 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; }