X-Git-Url: https://mattmccutchen.net/rsync/rsync.git/blobdiff_plain/31f440e68b1a087093f1c34be1ad3444f911d7d9..6e4fb64e6141727b8144bb77265bf0a4a8450a39:/socket.c diff --git a/socket.c b/socket.c index 98093fcf..6551df43 100644 --- a/socket.c +++ b/socket.c @@ -54,6 +54,8 @@ int open_socket_out(char *host, int port) return -1; } + set_nonblocking(res); + return res; } @@ -110,9 +112,9 @@ determine if a file descriptor is in fact a socket ****************************************************************************/ int is_a_socket(int fd) { - int v,l; - l = sizeof(int); - return(getsockopt(fd, SOL_SOCKET, SO_TYPE, (char *)&v, &l) == 0); + int v,l; + l = sizeof(int); + return(getsockopt(fd, SOL_SOCKET, SO_TYPE, (char *)&v, &l) == 0); } @@ -165,6 +167,8 @@ void start_accept_loop(int port, int (*fn)(int )) if (fork()==0) { close(s); + set_nonblocking(fd); + _exit(fn(fd)); } @@ -281,27 +285,30 @@ become a daemon, discarding the controlling terminal ****************************************************************************/ void become_daemon(void) { - if (fork()) + int i; + + if (fork()) { _exit(0); + } /* detach from the terminal */ #ifdef HAVE_SETSID setsid(); #else #ifdef TIOCNOTTY - { - int i = open("/dev/tty", O_RDWR); - if (i >= 0) - { - ioctl(i, (int) TIOCNOTTY, (char *)0); - close(i); - } + i = open("/dev/tty", O_RDWR); + if (i >= 0) { + ioctl(i, (int) TIOCNOTTY, (char *)0); + close(i); } #endif /* TIOCNOTTY */ #endif - close(0); - close(1); - close(2); + /* make sure that stdin, stdout an stderr don't stuff things + up (library functions, for example) */ + for (i=0;i<3;i++) { + close(i); + open("/dev/null", O_RDWR); + } } /*******************************************************************