960ede5bf36048659177f7f706350128e296e817 kent Fri Apr 26 19:23:29 2013 -0700 Making logDaemonize code be a little more robust. diff --git src/lib/log.c src/lib/log.c index 0ad9b32..16086fe 100644 --- src/lib/log.c +++ src/lib/log.c @@ -317,27 +317,35 @@ logDebugVa(format, args); va_end(args); } void logDaemonize(char *progName) /* daemonize parasol server process, closing open file descriptors and * starting logging based on the -logFacility and -log command line options . * if -debug is supplied , don't fork. */ { if (!optionExists("debug")) { int i, maxFiles = getdtablesize(); if (mustFork() != 0) exit(0); /* parent goes away */ + /* Put self in our own process group. */ + setsid(); + /* Close all open files first (before logging) */ for (i = 0; i < maxFiles; i++) close(i); + + /* Reopen standard files to /dev/null just in case somebody uses them. */ + int nullFd = open("/dev/null", O_RDWR); // Opens stdin + dup(nullFd); // Stdout goes also to /dev/null + dup(nullFd); // Stderr goes also to /dev/null } /* Set up log handler. */ if (optionExists("log")) logOpenFile(progName, optionVal("log", NULL)); else logOpenSyslog(progName, optionVal("logFacility", NULL)); }