File ntp-fork.patch of Package ntp.2324
--- ntp-4.2.8p6.orig/libntp/work_fork.c
+++ ntp-4.2.8p6/libntp/work_fork.c
@@ -451,7 +451,7 @@
}
}
-#ifdef HAVE_DROPROOT
+#if defined(HAVE_DROPROOT) && !defined(NEED_EARLY_FORK)
/* defer the fork until after root is dropped */
if (droproot && !root_dropped)
return;
@@ -461,8 +461,6 @@
fflush(stdout);
fflush(stderr);
- signal_no_reset(SIGCHLD, SIG_IGN);
-
childpid = fork();
if (-1 == childpid) {
msyslog(LOG_ERR, "unable to fork worker: %m");
--- ntp-4.2.8p6.orig/ntpd/ntp_timer.c
+++ ntp-4.2.8p6/ntpd/ntp_timer.c
@@ -276,6 +276,12 @@
u_int seconds /* 0 cancels */
)
{
+#if defined(HAVE_DROPROOT) && defined(NEED_EARLY_FORK)
+ if (droproot) {
+ worker_idle_timer = 0;
+ return;
+ }
+#endif
if (0 == seconds) {
worker_idle_timer = 0;
return;
--- ntp-4.2.8p6.orig/ntpd/ntpd.c
+++ ntp-4.2.8p6/ntpd/ntpd.c
@@ -332,6 +332,16 @@
#endif /*defined(NEED_PTHREAD_WARMUP)*/
+#ifdef NEED_EARLY_FORK
+static void
+dummy_callback(void) { return; }
+
+static void
+fork_nonchroot_worker(void) {
+ getaddrinfo_sometime("localhost", "ntp", NULL, INITIAL_DNS_RETRY,
+ (gai_sometime_callback)&dummy_callback, NULL);
+}
+#endif /* NEED_EARLY_FORK */
void
parse_cmdline_opts(
@@ -931,6 +941,11 @@
# ifdef HAVE_DROPROOT
if (droproot) {
+
+#ifdef NEED_EARLY_FORK
+ fork_nonchroot_worker();
+#endif
+
/* Drop super-user privileges and chroot now if the OS supports this */
# ifdef HAVE_LINUX_CAPABILITIES
--- ntp-4.2.8p6.orig/sntp/m4/ntp_libntp.m4
+++ ntp-4.2.8p6/sntp/m4/ntp_libntp.m4
@@ -163,6 +163,7 @@
# include <sys/socket.h>
#endif
])
+ AC_DEFINE([NEED_EARLY_FORK], [1], [having to fork the DNS worker early when doing chroot?])
esac
AC_CHECK_HEADERS([arpa/nameser.h sys/param.h sys/time.h sys/timers.h])