From faa0f7ffe757043fb1b7ddb7b0643816a554dadc Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Thu, 23 Oct 2003 14:28:44 +0000 Subject: [PATCH] Use daemon(3) function where available. svn:r665 --- configure.in | 2 +- src/common/util.c | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/configure.in b/configure.in index 7933cf7678..bb8fa12f47 100644 --- a/configure.in +++ b/configure.in @@ -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_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 Watch out. diff --git a/src/common/util.c b/src/common/util.c index a85e22ae8a..3d20f81049 100644 --- a/src/common/util.c +++ b/src/common/util.c @@ -548,7 +548,13 @@ get_uname(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. */ if (fork()) exit(0);