X-Git-Url: https://mattmccutchen.net/rsync/rsync.git/blobdiff_plain/39993af514cadf3764c355fe687110d5ea9b0b01..7352b8736b94a7cb375cc2789fba6728d5c35955:/socket.c diff --git a/socket.c b/socket.c index fa8e4572..a19542f8 100644 --- a/socket.c +++ b/socket.c @@ -374,6 +374,15 @@ int is_a_socket(int fd) } +static RETSIGTYPE sigchld_handler(UNUSED(int val)) +{ + signal(SIGCHLD, sigchld_handler); +#ifdef WNOHANG + while (waitpid(-1, NULL, WNOHANG) > 0) {} +#endif +} + + void start_accept_loop(int port, int (*fn)(int, int)) { int s; @@ -419,21 +428,17 @@ void start_accept_loop(int port, int (*fn)(int, int)) if (fd == -1) continue; - signal(SIGCHLD, SIG_IGN); - - /* we shouldn't have any children left hanging around - but I have had reports that on Digital Unix zombies - are produced, so this ensures that they are reaped */ -#ifdef WNOHANG - while (waitpid(-1, NULL, WNOHANG) > 0); -#endif + signal(SIGCHLD, sigchld_handler); if ((pid = fork()) == 0) { + int ret; close(s); /* open log file in child before possibly giving up privileges */ log_open(); - _exit(fn(fd, fd)); + ret = fn(fd, fd); + close_all(); + _exit(ret); } else if (pid < 0) { rprintf(FERROR, RSYNC_NAME