diff options
author | Cy Schubert <cy@FreeBSD.org> | 2015-07-05 15:42:16 +0000 |
---|---|---|
committer | Cy Schubert <cy@FreeBSD.org> | 2015-07-05 15:42:16 +0000 |
commit | 276da39af92f48350aa01091a2b8b3e735217eea (patch) | |
tree | fb96356e3ef85aaa8d1f5939a9decd315a7ca596 /contrib/ntp/libntp/work_fork.c | |
parent | 31c98473c1337a238b00342edd7ef85dfb378e24 (diff) | |
parent | 873997f35a991eee09ed91148a0cf332360380da (diff) |
Notes
Diffstat (limited to 'contrib/ntp/libntp/work_fork.c')
-rw-r--r-- | contrib/ntp/libntp/work_fork.c | 27 |
1 files changed, 23 insertions, 4 deletions
diff --git a/contrib/ntp/libntp/work_fork.c b/contrib/ntp/libntp/work_fork.c index dab02bc6af148..96c550e985943 100644 --- a/contrib/ntp/libntp/work_fork.c +++ b/contrib/ntp/libntp/work_fork.c @@ -8,6 +8,7 @@ #include <stdio.h> #include <ctype.h> #include <signal.h> +#include <sys/wait.h> #include "iosignal.h" #include "ntp_stdlib.h" @@ -112,6 +113,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. */ int @@ -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 */ } |