]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
[Bug 2856] ntpd should wait() on terminated child processes. Paul Green.
authorHarlan Stenn <stenn@ntp.org>
Sat, 27 Jun 2015 05:58:07 +0000 (01:58 -0400)
committerHarlan Stenn <stenn@ntp.org>
Sat, 27 Jun 2015 05:58:07 +0000 (01:58 -0400)
bk: 558e3b6f4EZVr1wF7yYuhOOUYmTstQ

ChangeLog
libntp/work_fork.c

index d35dd9422937d522ab953fe39730b55fe5447a20..76f00a4431ae80ea84b7f9859205fb372a4eda6d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,6 +2,7 @@
 
 * [Bug 2855] Parser fix for conditional leap smear code.  Harlan Stenn.
 * [Bug 2855] Report leap smear in the REFID.  Harlan Stenn.
+* [Bug 2856] ntpd should wait() on terminated child processes.  Paul Green.
 * refidsmear test cleanup.  Tomasz Flendrich.
 * refidsmear function support and tests.  Harlan Stenn.
 * sntp/tests/Makefile.am: remove g_nameresolution.cpp as it tested
index dab02bc6af1484180fab997ef0c93c464f20a412..96c550e98594369a022ec26f359699e592d93af4 100644 (file)
@@ -8,6 +8,7 @@
 #include <stdio.h>
 #include <ctype.h>
 #include <signal.h>
+#include <sys/wait.h>
 
 #include "iosignal.h"
 #include "ntp_stdlib.h"
@@ -111,6 +112,23 @@ interrupt_worker_sleep(void)
 }
 
 
+/*
+ * harvest_child_status() runs in the parent.
+ */
+static void
+harvest_child_status(
+       blocking_child *        c
+       )
+{
+       if (c->pid)
+       {
+               /* Wait on the child so it can finish terminating */
+               if (waitpid(c->pid, NULL, 0) == c->pid)
+                       TRACE(4, ("harvested child %d\n", c->pid));
+               else msyslog(LOG_ERR, "error waiting on child %d: %m", c->pid);
+       }
+}
+
 /*
  * req_child_exit() runs in the parent.
  */
@@ -124,6 +142,8 @@ req_child_exit(
                c->req_write_pipe = -1;
                return 0;
        }
+       /* Closing the pipe forces the child to exit */
+       harvest_child_status(c);
        return -1;
 }
 
@@ -136,10 +156,7 @@ cleanup_after_child(
        blocking_child *        c
        )
 {
-       if (-1 != c->req_write_pipe) {
-               close(c->req_write_pipe);
-               c->req_write_pipe = -1;
-       }
+       harvest_child_status(c);
        if (-1 != c->resp_read_pipe) {
                (*addremove_io_fd)(c->resp_read_pipe, c->ispipe, TRUE);
                close(c->resp_read_pipe);
@@ -209,6 +226,8 @@ send_blocking_req_internal(
                        "send_blocking_req_internal: short write %d of %d",
                        rc, octets);
 
+       /* Fatal error.  Clean up the child process.  */
+       req_child_exit(c);
        exit(1);        /* otherwise would be return -1 */
 }