Use daemon(3) function where available.

svn:r665
This commit is contained in:
Nick Mathewson 2003-10-23 14:28:44 +00:00
parent 71e5ad714b
commit faa0f7ffe7
2 changed files with 8 additions and 2 deletions

View File

@ -136,7 +136,7 @@ dnl These headers are not essential
AC_CHECK_HEADERS(stdint.h sys/types.h inttypes.h sys/wait.h netinet/in.h arpa/inet.h) AC_CHECK_HEADERS(stdint.h sys/types.h inttypes.h sys/wait.h netinet/in.h arpa/inet.h)
AC_CHECK_FUNCS(gettimeofday ftime socketpair uname) AC_CHECK_FUNCS(gettimeofday ftime socketpair uname daemon)
dnl In case we aren't given a working stdint.h, we'll need to grow our own. dnl In case we aren't given a working stdint.h, we'll need to grow our own.
dnl Watch out. dnl Watch out.

View File

@ -548,7 +548,13 @@ get_uname(void)
} }
void daemonize(void) { void daemonize(void) {
#ifndef MS_WINDOWS #ifdef HAVE_DAEMON
if (daemon(0 /* chdir to / */,
0 /* Redirect std* to /dev/null */)) {
log_fn(LOG_ERR, "Daemon returned an error: %s", strerror(errno));
exit(1);
}
#elif ! defined(MS_WINDOWS)
/* Fork; parent exits. */ /* Fork; parent exits. */
if (fork()) if (fork())
exit(0); exit(0);