If the daemon is unable to fork a child to accept a connection, print
authorMartin Pool <mbp@samba.org>
Mon, 18 Feb 2002 22:38:03 +0000 (22:38 +0000)
committerMartin Pool <mbp@samba.org>
Mon, 18 Feb 2002 22:38:03 +0000 (22:38 +0000)
an error message.  (Colin Walters)

NEWS
socket.c

diff --git a/NEWS b/NEWS
index ee002893524b3781db437c6f4e5f6f10ce4e8078..3457da165b3d6f0e177188d91a251f039b3a8f3a 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -30,4 +30,7 @@ rsync 2.5.3 (not released yet)
     * Added --no-whole-file and --no-blocking-io options (Dave Dykstra)
 
     * Made the --write-batch and --read-batch options actually work
-       and added documentation in the man page (Jos Backus)
+      and added documentation in the man page (Jos Backus)
+
+    * If the daemon is unable to fork a child to accept a connection,
+      print an error message.  (Colin Walters)
index 344c42e087ab517082b168bba12e3dfb621aeede..843c19b6873531e5b650f89480011a724144dcf4 100644 (file)
--- 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,12 +419,22 @@ 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);
                }
 
                close(fd);