Compare commits

...

5 Commits

Author SHA1 Message Date
rsync-bugs
e2d1033d5d preparing for release of 2.1.0 1998-07-20 05:43:51 +00:00
Andrew Tridgell
c46ded4621 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 :(
1998-07-20 05:36:25 +00:00
Andrew Tridgell
8cd9fd4e8c always use a timeout to select, even if --timeout is not
specified. This makes things easier to debug.
1998-07-19 10:51:26 +00:00
Andrew Tridgell
41979ff87c - defer the error message from the options parsing until after the
socket is multiplexed. This allows clients sending new options which
the remote server doesn't understand to get a sensible error message.
1998-07-19 05:22:05 +00:00
Andrew Tridgell
b11ed3b150 - close stdout and stderr and reopen then as /dev/null when running as
a daemon. This prevents library functions (such as getopt) stuffing up
our protocol stream when errors are detected.

- defer the error message from the options parsing until after the
socket is multiplexed. This allows clients sending new options which
the remote server doesn't understand to get a sensible error message.
1998-07-19 04:50:48 +00:00
9 changed files with 62 additions and 33 deletions

View File

@@ -118,6 +118,7 @@ static int rsync_module(int fd, int i)
char *name = lp_name(i);
char *user;
int start_glob=0;
int ret;
char *request=NULL;
extern int am_sender;
extern int remote_version;
@@ -251,7 +252,7 @@ static int rsync_module(int fd, int i)
}
}
parse_arguments(argc, argv);
ret = parse_arguments(argc, argv);
if (request) {
if (*user) {
@@ -276,6 +277,11 @@ static int rsync_module(int fd, int i)
if (remote_version > 17 && am_sender)
io_start_multiplex_out(fd);
if (!ret) {
rprintf(FERROR,"Error parsing options (unsupported option?) - aborting\n");
exit_cleanup(1);
}
start_server(fd, fd, argc, argp);
return 0;
@@ -375,7 +381,15 @@ int daemon_main(void)
push_dir("/", 0);
if (is_a_socket(STDIN_FILENO)) {
/* we are running via inetd */
int i;
/* we are running via inetd - close off stdout and
stderr so that library functions (and getopt) don't
try to use them. Redirect them to /dev/null */
for (i=1;i<3;i++) {
close(i);
open("/dev/null", O_RDWR);
}
return start_daemon(STDIN_FILENO);
}

25
io.c
View File

@@ -24,6 +24,9 @@
*/
#include "rsync.h"
/* if no timeout is specified then use a 60 second select timeout */
#define SELECT_TIMEOUT 60
static int io_multiplexing_out;
static int io_multiplexing_in;
static int multiplex_in_fd;
@@ -67,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
@@ -75,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;
@@ -83,11 +89,10 @@ static int read_timeout(int fd, char *buf, int len)
FD_ZERO(&fds);
FD_SET(fd, &fds);
tv.tv_sec = io_timeout;
tv.tv_sec = io_timeout?io_timeout:SELECT_TIMEOUT;
tv.tv_usec = 0;
if (select(fd+1, &fds, NULL, NULL,
io_timeout?&tv:NULL) != 1) {
if (select(fd+1, &fds, NULL, NULL, &tv) != 1) {
check_timeout();
continue;
}
@@ -252,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;
@@ -318,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++;
@@ -329,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);
@@ -338,13 +347,13 @@ static void writefd_unbuffered(int fd,char *buf,int len)
fd_count = buffer_f_in+1;
}
tv.tv_sec = io_timeout;
tv.tv_sec = io_timeout?io_timeout:SELECT_TIMEOUT;
tv.tv_usec = 0;
count = select(fd_count,
reading?&r_fds:NULL,
&w_fds,NULL,
io_timeout?&tv:NULL);
&tv);
if (count <= 0) {
check_timeout();

4
main.c
View File

@@ -566,7 +566,9 @@ int main(int argc,char *argv[])
carried across */
orig_umask = (int)umask(0);
parse_arguments(argc, argv);
if (!parse_arguments(argc, argv)) {
exit_cleanup(1);
}
argc -= optind;
argv += optind;

View File

@@ -197,7 +197,8 @@ static struct option long_options[] = {
{"port", 1, 0, OPT_PORT},
{0,0,0,0}};
void parse_arguments(int argc, char *argv[])
int parse_arguments(int argc, char *argv[])
{
int opt;
int option_index;
@@ -301,7 +302,7 @@ void parse_arguments(int argc, char *argv[])
preserve_hard_links=1;
#else
rprintf(FERROR,"ERROR: hard links not supported on this platform\n");
exit_cleanup(1);
return 0;
#endif
break;
@@ -412,10 +413,10 @@ void parse_arguments(int argc, char *argv[])
break;
default:
/* rprintf(FERROR,"bad option -%c\n",opt); */
exit_cleanup(1);
return 0;
}
}
return 1;
}

View File

@@ -1,10 +1,10 @@
Summary: Program for efficient remote updates of files.
Name: rsync
Version: 2.0.19
Version: 2.1.0
Release: 1
Copyright: GPL
Group: Applications/Networking
Source: ftp://samba.anu.edu.au/pub/rsync/rsync-2.0.19.tar.gz
Source: ftp://samba.anu.edu.au/pub/rsync/rsync-2.1.0.tar.gz
URL: http://samba.anu.edu.au/rsync/
Packager: Andrew Tridgell <tridge@samba.anu.edu.au>
BuildRoot: /tmp/rsync

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

@@ -281,27 +281,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);
}
}
/*******************************************************************

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

View File

@@ -1 +1 @@
#define VERSION "2.0.19"
#define VERSION "2.1.0"