X-Git-Url: https://mattmccutchen.net/rsync/rsync.git/blobdiff_plain/145794936fc7e87c500dd809e8e67313105825fb..79845f28349b27e9b08ee1965337c12de927be2a:/socket.c diff --git a/socket.c b/socket.c index 344c42e0..d69e4cf3 100644 --- a/socket.c +++ b/socket.c @@ -387,6 +387,7 @@ void start_accept_loop(int port, int (*fn)(int )) for each incoming connection */ while (1) { fd_set fds; + pid_t pid; int fd; struct sockaddr_storage addr; socklen_t addrlen = sizeof addr; @@ -418,15 +419,26 @@ void start_accept_loop(int port, int (*fn)(int )) while (waitpid(-1, NULL, WNOHANG) > 0); #endif - if (fork()==0) { + if ((pid = fork()) == 0) { close(s); /* open log file in child before possibly giving up privileges */ log_open(); _exit(fn(fd)); + } else if (pid < 0) { + rprintf(FERROR, + RSYNC_NAME + ": could not create child server process: %s\n", + strerror(errno)); + close(fd); + /* This might have happened because we're + * overloaded. Sleep briefly before trying to + * accept again. */ + sleep(2); + } else { + /* Parent doesn't need this fd anymore. */ + close(fd); } - - close(fd); } }