]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Use daemon(3) function where available.
authorNick Mathewson <nickm@torproject.org>
Thu, 23 Oct 2003 14:28:44 +0000 (14:28 +0000)
committerNick Mathewson <nickm@torproject.org>
Thu, 23 Oct 2003 14:28:44 +0000 (14:28 +0000)
svn:r665

configure.in
src/common/util.c

index 7933cf767852dc590e1d7aec240f38e23f12a31b..bb8fa12f47dd92fb2940d8d3c340caefc6f2d4fe 100644 (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_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.
index a85e22ae8a03d0a56baf6afcb5d4f51acce56425..3d20f81049b8b7b3c5eb03d2f068b273f3c8ef2c 100644 (file)
@@ -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);