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 :(
This commit is contained in:
Andrew Tridgell
1998-07-20 05:36:25 +00:00
parent 8cd9fd4e8c
commit c46ded4621
4 changed files with 20 additions and 15 deletions

13
io.c
View File

@@ -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);

View File

@@ -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;
}

View File

@@ -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

2
util.c
View File

@@ -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);