(patch) check for the return value of fork()
Colin Walters
walters at debian.org
Tue Jan 15 08:19:07 EST 2002
I noticed we're not checking for a failure to fork() in socket.c. This
patch should address the problem.
-------------- next part --------------
Index: socket.c
===================================================================
RCS file: /cvsroot/rsync/socket.c,v
retrieving revision 1.54
diff -u -u -r1.54 socket.c
--- socket.c 11 Jan 2002 08:24:34 -0000 1.54
+++ socket.c 14 Jan 2002 21:20:52 -0000
@@ -385,6 +385,7 @@
for each incoming connection */
while (1) {
fd_set fds;
+ pid_t pid;
int fd;
struct sockaddr_storage addr;
int addrlen = sizeof(addr);
@@ -416,12 +417,17 @@
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, "could not create child process: %s\n",
+ strerror(errno));
+ close(fd);
+ sleep(2);
}
close(fd);
More information about the rsync
mailing list