I think I might havefinally fixed the rsync hanging bug. It was caused
authorAndrew Tridgell <tridge@samba.org>
Mon, 20 Jul 1998 05:36:25 +0000 (05:36 +0000)
committerAndrew Tridgell <tridge@samba.org>
Mon, 20 Jul 1998 05:36:25 +0000 (05:36 +0000)
by a read during an io_flush() triggered during a readfd(). A simple
logic bug in the io code :(

io.c
rsync.c
socket.c
util.c

diff --git a/io.c b/io.c
index 3ea09e1..70c6a22 100644 (file)
--- 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 5ca73e2..f5a1f48 100644 (file)
--- 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;
                }
       
index f8d4659..674e3d7 100644 (file)
--- 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 bfa35f1..cc626d7 100644 (file)
--- 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);