From c46ded46212c2ea55e43ec661b5a724718a63ec2 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 20 Jul 1998 05:36:25 +0000 Subject: [PATCH] I think I might havefinally fixed the rsync hanging bug. It was caused by a read during an io_flush() triggered during a readfd(). A simple logic bug in the io code :( --- io.c | 13 ++++++++++--- rsync.c | 6 +++--- socket.c | 14 ++++++-------- util.c | 2 +- 4 files changed, 20 insertions(+), 15 deletions(-) diff --git a/io.c b/io.c index 3ea09e12..70c6a22f 100644 --- a/io.c +++ b/io.c @@ -70,6 +70,7 @@ static char *read_buffer_p; static int read_buffer_len; static int read_buffer_size; static int no_flush; +static int no_flush_read; /* read from a socket with IO timeout. return the number of bytes read. If no bytes can be read then exit, never return @@ -78,7 +79,9 @@ static int read_timeout(int fd, char *buf, int len) { int n, ret=0; + no_flush_read++; io_flush(); + no_flush_read--; while (ret == 0) { fd_set fds; @@ -254,7 +257,9 @@ static void readfd(int fd,char *buffer,int N) continue; } + no_flush_read++; io_flush(); + no_flush_read--; ret = read_unbuffered(fd,buffer + total,N-total); total += ret; @@ -320,7 +325,7 @@ static void writefd_unbuffered(int fd,char *buf,int len) fd_set w_fds, r_fds; int fd_count, count; struct timeval tv; - int reading; + int reading=0; int blocked=0; no_flush++; @@ -331,8 +336,10 @@ static void writefd_unbuffered(int fd,char *buf,int len) FD_SET(fd,&w_fds); fd_count = fd+1; - reading = (buffer_f_in != -1 && - read_buffer_len < MAX_READ_BUFFER); + if (!no_flush_read) { + reading = (buffer_f_in != -1 && + read_buffer_len < MAX_READ_BUFFER); + } if (reading) { FD_SET(buffer_f_in,&r_fds); diff --git a/rsync.c b/rsync.c index 5ca73e2b..f5a1f48c 100644 --- a/rsync.c +++ b/rsync.c @@ -961,7 +961,7 @@ int recv_files(int f_in,struct file_list *flist,char *local_name,int f_gen) if (!get_tmpname(fnametmp,fname)) { if (buf) unmap_file(buf); - close(fd1); + if (fd1 != -1) close(fd1); continue; } @@ -969,7 +969,7 @@ int recv_files(int f_in,struct file_list *flist,char *local_name,int f_gen) rprintf(FERROR,"mktemp %s failed\n",fnametmp); receive_data(f_in,buf,-1,NULL,file->length); if (buf) unmap_file(buf); - close(fd1); + if (fd1 != -1) close(fd1); continue; } @@ -990,7 +990,7 @@ int recv_files(int f_in,struct file_list *flist,char *local_name,int f_gen) rprintf(FERROR,"open %s : %s\n",fnametmp,strerror(errno)); receive_data(f_in,buf,-1,NULL,file->length); if (buf) unmap_file(buf); - close(fd1); + if (fd1 != -1) close(fd1); continue; } diff --git a/socket.c b/socket.c index f8d46590..674e3d7f 100644 --- a/socket.c +++ b/socket.c @@ -283,21 +283,19 @@ void become_daemon(void) { int i; - if (fork()) + 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 diff --git a/util.c b/util.c index bfa35f18..cc626d79 100644 --- a/util.c +++ b/util.c @@ -291,7 +291,7 @@ int copy_file(char *source, char *dest, mode_t mode) } ofd = do_open(dest, O_WRONLY | O_CREAT | O_TRUNC | O_EXCL, mode); - if (ofd < 0) { + if (ofd == -1) { rprintf(FERROR,"open %s: %s\n", dest,strerror(errno)); close(ifd); -- 2.34.1