diff options
author | Cy Schubert <cy@FreeBSD.org> | 2015-07-01 03:12:13 +0000 |
---|---|---|
committer | Cy Schubert <cy@FreeBSD.org> | 2015-07-01 03:12:13 +0000 |
commit | 873997f35a991eee09ed91148a0cf332360380da (patch) | |
tree | 5b1ffa3ad0e56e0e9f2991011729791ee86d7632 /libntp/work_fork.c | |
parent | 4ba32eb5a8bf3455c09d1513ed2af8d2c861a6ba (diff) |
Notes
Diffstat (limited to 'libntp/work_fork.c')
-rw-r--r-- | libntp/work_fork.c | 27 |
1 files changed, 23 insertions, 4 deletions
diff --git a/libntp/work_fork.c b/libntp/work_fork.c index dab02bc6af14..96c550e98594 100644 --- a/libntp/work_fork.c +++ b/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 */ } |