Redirect stdin/stderr/stdout to /dev/null in daemon mode
authorsapier <Sapier at GMX dot net>
Sat, 31 May 2014 22:41:48 +0000 (00:41 +0200)
committersapier <Sapier at GMX dot net>
Sat, 31 May 2014 22:41:48 +0000 (00:41 +0200)
src/porting.cpp

index ef461242d28cad1afb37e34c889d3d9df55cfe71..ca43452a85439f56d494518fefc0eb008e0adedd 100644 (file)
@@ -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;
        }