From: Harlan Stenn Date: Sat, 27 Jun 2015 05:58:07 +0000 (-0400) Subject: [Bug 2856] ntpd should wait() on terminated child processes. Paul Green. X-Git-Tag: NTP_4_2_8P3_RC3~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ee05c29ee873b861ca37102ba10ef56851db3562;p=thirdparty%2Fntp.git [Bug 2856] ntpd should wait() on terminated child processes. Paul Green. bk: 558e3b6f4EZVr1wF7yYuhOOUYmTstQ --- diff --git a/ChangeLog b/ChangeLog index d35dd9422..76f00a443 100644 --- 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 diff --git a/libntp/work_fork.c b/libntp/work_fork.c index dab02bc6a..96c550e98 100644 --- a/libntp/work_fork.c +++ b/libntp/work_fork.c @@ -8,6 +8,7 @@ #include #include #include +#include #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 */ }