Matt McCutchen's Web Site
/
rsync
/
rsync.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Fix error handling for failing to fork after accepting a connection --
[rsync/rsync.git]
/
socket.c
diff --git
a/socket.c
b/socket.c
index
9ac182d
..
c4420ba
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;
for each incoming connection */
while (1) {
fd_set fds;
+ pid_t pid;
int fd;
struct sockaddr_storage addr;
socklen_t addrlen = sizeof addr;
int fd;
struct sockaddr_storage addr;
socklen_t addrlen = sizeof addr;
@@
-418,15
+419,25
@@
void start_accept_loop(int port, int (*fn)(int ))
while (waitpid(-1, NULL, WNOHANG) > 0);
#endif
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));
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 {
+ close(fd);
}
}
-
- close(fd);
}
}
}
}
@@
-590,7
+601,7
@@
static int socketpair_tcp(int fd[2])
if ((listener = socket(PF_INET, SOCK_STREAM, 0)) == -1) goto failed;
memset(&sock2, 0, sizeof(sock2));
if ((listener = socket(PF_INET, SOCK_STREAM, 0)) == -1) goto failed;
memset(&sock2, 0, sizeof(sock2));
-#ifdef HAVE_SOCK
_SIN
_LEN
+#ifdef HAVE_SOCK
ADDR
_LEN
sock2.sin_len = sizeof(sock2);
#endif
sock2.sin_family = PF_INET;
sock2.sin_len = sizeof(sock2);
#endif
sock2.sin_family = PF_INET;