diff --git a/config.h.in b/config.h.in index aa7ce2d23..c396b2f40 100644 --- a/config.h.in +++ b/config.h.in @@ -28,6 +28,9 @@ /* Define to 1 if you have the `chroot' function. */ #undef HAVE_CHROOT +/* Define to 1 if you have the `daemon' function. */ +#undef HAVE_DAEMON + /* Define to 1 if you have the header file. */ #undef HAVE_DLFCN_H diff --git a/configure b/configure index 3d4b28c30..6efbac7ce 100755 --- a/configure +++ b/configure @@ -25283,7 +25283,8 @@ fi -for ac_func in tzset sigprocmask fcntl getpwnam getrlimit setsid sbrk chroot kill sleep usleep random srandom recvmsg sendmsg writev setresuid setreuid setresgid setregid glob initgroups + +for ac_func in tzset sigprocmask fcntl getpwnam getrlimit setsid sbrk chroot kill sleep usleep random srandom recvmsg sendmsg writev setresuid setreuid setresgid setregid glob initgroups daemon do as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh` { echo "$as_me:$LINENO: checking for $ac_func" >&5 diff --git a/configure.ac b/configure.ac index 91202521b..5cd331b2b 100644 --- a/configure.ac +++ b/configure.ac @@ -854,7 +854,7 @@ AC_CHECK_GETADDRINFO_WITH_INCLUDES if test $ac_cv_func_getaddrinfo = no; then AC_LIBOBJ([fake-rfc2553]) fi -AC_CHECK_FUNCS([tzset sigprocmask fcntl getpwnam getrlimit setsid sbrk chroot kill sleep usleep random srandom recvmsg sendmsg writev setresuid setreuid setresgid setregid glob initgroups]) +AC_CHECK_FUNCS([tzset sigprocmask fcntl getpwnam getrlimit setsid sbrk chroot kill sleep usleep random srandom recvmsg sendmsg writev setresuid setreuid setresgid setregid glob initgroups daemon]) # check if setreuid en setregid fail, on MacOSX10.4(darwin8). if echo $build_os | grep darwin8 > /dev/null; then diff --git a/daemon/unbound.c b/daemon/unbound.c index 6c5fb6f28..5fc3d6217 100644 --- a/daemon/unbound.c +++ b/daemon/unbound.c @@ -294,6 +294,11 @@ checkoldpid(char* pidfile, int inchroot) static void detach(void) { +#ifdef HAVE_DAEMON + /* use POSIX daemon(3) function */ + if(daemon(1, 0) != 0) + fatal_exit("daemon failed: %s", strerror(errno)); +#else /* no HAVE_DAEMON */ #ifdef HAVE_WORKING_FORK int fd; /* Take off... */ @@ -319,6 +324,7 @@ detach(void) (void)close(fd); } #endif /* HAVE_WORKING_FORK */ +#endif /* HAVE_DAEMON */ } /** daemonize, drop user priviliges and chroot if needed */ diff --git a/doc/Changelog b/doc/Changelog index bd76d2549..7e7140d92 100644 --- a/doc/Changelog +++ b/doc/Changelog @@ -15,6 +15,7 @@ inluded ldns package with the unbound source. The -I include is put before the others, so it avoids bad include files from an older ldns install. + - daemon(3) posix call is used when available. 4 February 2009: Wouter - tag for release 1.2.1. diff --git a/doc/TODO b/doc/TODO index fdd2177bb..9484292cb 100644 --- a/doc/TODO +++ b/doc/TODO @@ -69,7 +69,6 @@ o unbound_control forward [addr {addr}] | [off] o #231: unbound_checkconf options to output config file data. o config entry to denote that a zone is to be treated as unsigned (even if a DS exists to higher trust anchor). -o see if we can use daemon(3), cleaner posix usage. o see if we can include the python bindings (contrib). o see if we can suport var:value (nospace) by parser. o remote control read ssl information while priviledged.