redirect stdin/stdout/stderr to /dev/null after forking into background && close...
[NeonServV5.git] / src / main.c
index dc76d7a661043e0fe36f98114a7a8744268f92f2..fb8abcebbf7e51aace68d7d0950f9a2fcc860c07 100644 (file)
@@ -149,6 +149,10 @@ void exit_daemon() {
     if(daemonized) {
         remove(PID_FILE);
     }
+    if(log_fptr) {
+        fclose(log_fptr);
+        log_fptr = NULL;
+    }
 }
 
 int main(int argc, char *argv[]) {
@@ -194,6 +198,7 @@ int main(int argc, char *argv[]) {
     }
     check_firstrun();
     if (run_as_daemon) {
+        #ifndef WIN32
         /* Attempt to fork into the background if daemon mode is on. */
         pid_t pid = fork();
         if (pid < 0) {
@@ -214,9 +219,10 @@ int main(int argc, char *argv[]) {
             fprintf(pidfile, "%i\n", (int)getpid());
             fclose(pidfile);
         }
-        fclose(stdin);
-        fclose(stdout);
-        fclose(stderr);
+        fclose(stdin); fopen("/dev/null", "r");
+        fclose(stdout); fopen("/dev/null", "w");
+        fclose(stderr); fopen("/dev/null", "w");
+        #endif
     }
     
 main: