X-Git-Url: https://mattmccutchen.net/rsync/rsync.git/blobdiff_plain/7bea78ced6f9156a8b5c37c4ae8cb15698ead4cd..7352b8736b94a7cb375cc2789fba6728d5c35955:/socket.c diff --git a/socket.c b/socket.c index ccc79cfe..a19542f8 100644 --- a/socket.c +++ b/socket.c @@ -34,8 +34,10 @@ #include "rsync.h" -/* Establish a proxy connection on an open socket to a web roxy by - * using the CONNECT method. */ +/** + * Establish a proxy connection on an open socket to a web proxy by + * using the HTTP CONNECT method. + **/ static int establish_proxy_connection(int fd, char *host, int port) { char buffer[1024]; @@ -68,7 +70,7 @@ static int establish_proxy_connection(int fd, char *host, int port) buffer); return -1; } - for (cp = &buffer[5]; isdigit(*cp) || (*cp == '.'); cp++) + for (cp = &buffer[5]; isdigit(* (unsigned char *) cp) || (*cp == '.'); cp++) ; while (*cp == ' ') cp++; @@ -122,12 +124,14 @@ int try_bind_local(int s, for (r = bres_all; r; r = r->ai_next) { if (bind(s, r->ai_addr, r->ai_addrlen) == -1) continue; + freeaddrinfo(bres_all); return s; } /* no error message; there might be some problem that allows * creation of the socket but not binding, perhaps if the * machine has no ipv6 address of this name. */ + freeaddrinfo(bres_all); return -1; } @@ -329,7 +333,8 @@ static int open_socket_in(int type, int port, const char *bind_address, close(s); continue; } - + + freeaddrinfo(all_ai); return s; } @@ -369,7 +374,16 @@ int is_a_socket(int fd) } -void start_accept_loop(int port, int (*fn)(int )) +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; extern char *bind_address; @@ -414,21 +428,17 @@ void start_accept_loop(int port, int (*fn)(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)); + ret = fn(fd, fd); + close_all(); + _exit(ret); } else if (pid < 0) { rprintf(FERROR, RSYNC_NAME @@ -491,9 +501,9 @@ struct -/**************************************************************************** -set user socket options -****************************************************************************/ +/** + * Set user socket options + **/ void set_socket_options(int fd, char *options) { char *tok; @@ -551,9 +561,9 @@ void set_socket_options(int fd, char *options) free(options); } -/**************************************************************************** -become a daemon, discarding the controlling terminal -****************************************************************************/ +/** + * Become a daemon, discarding the controlling terminal + **/ void become_daemon(void) { int i; @@ -583,14 +593,15 @@ void become_daemon(void) } -/******************************************************************* -this is like socketpair but uses tcp. It is used by the Samba -regression test code -The function guarantees that nobody else can attach to the socket, -or if they do that this function fails and the socket gets closed -returns 0 on success, -1 on failure -the resulting file descriptors are symmetrical - ******************************************************************/ +/** + * This is like socketpair but uses tcp. It is used by the Samba + * regression test code. + * + * The function guarantees that nobody else can attach to the socket, + * or if they do that this function fails and the socket gets closed + * returns 0 on success, -1 on failure the resulting file descriptors + * are symmetrical. + **/ static int socketpair_tcp(int fd[2]) { int listener;