From: pk910 Date: Sun, 5 Feb 2012 12:11:00 +0000 (+0100) Subject: redirect stdin/stdout/stderr to /dev/null after forking into background && close... X-Git-Tag: v5.3~24 X-Git-Url: http://git.pk910.de/?p=NeonServV5.git;a=commitdiff_plain;h=c0b34c53149d6d3a796d5dbdc1de379289281c7d redirect stdin/stdout/stderr to /dev/null after forking into background && close log file on exit --- diff --git a/src/main.c b/src/main.c index dc76d7a..fb8abce 100644 --- a/src/main.c +++ b/src/main.c @@ -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: