LIBOBJ=lib/getopt.o lib/fnmatch.o lib/zlib.o lib/compat.o
OBJS1=rsync.o exclude.o util.o md4.o main.o checksum.o match.o syscall.o
-OBJS=$(OBJS1) flist.o io.o compat.o hlink.o token.o uidlist.o $(LIBOBJ)
+OBJS=$(OBJS1) flist.o io.o compat.o hlink.o token.o uidlist.o socket.o $(LIBOBJ)
# note that the -I. is needed to handle config.h when using VPATH
.c.o:
if (remote_version < MIN_PROTOCOL_VERSION ||
remote_version > MAX_PROTOCOL_VERSION) {
- fprintf(FERROR,"protocol version mismatch - is your shell clean?\n");
+ rprintf(FERROR,"protocol version mismatch - is your shell clean?\n");
exit_cleanup(1);
}
if (verbose > 2)
- fprintf(FINFO, "local_version=%d remote_version=%d\n",
+ rprintf(FINFO, "local_version=%d remote_version=%d\n",
PROTOCOL_VERSION, remote_version);
if (remote_version >= 12) {
AC_FUNC_UTIME_NULL
AC_CHECK_FUNCS(waitpid strtok pipe getcwd mkdir strdup strerror chown chmod mknod)
AC_CHECK_FUNCS(fchmod fstat strchr bcopy bzero readlink link utime utimes)
-AC_CHECK_FUNCS(memmove getopt_long lchown setlinebuf)
+AC_CHECK_FUNCS(memmove getopt_long lchown setlinebuf vsnprintf)
echo $ac_n "checking for working fnmatch... $ac_c"
AC_TRY_RUN([#include <fnmatch.h>
#include "rsync.h"
extern int verbose;
-extern int am_server;
static char **exclude_list;
if (strcmp(pattern,"!") == 0) {
if (verbose > 2)
- fprintf(FINFO,"clearing exclude list\n");
+ rprintf(FINFO,"clearing exclude list\n");
while ((len)--)
free((*list)[len]);
free((*list));
out_of_memory("add_exclude");
if (verbose > 2)
- fprintf(FINFO,"add_exclude(%s)\n",pattern);
+ rprintf(FINFO,"add_exclude(%s)\n",pattern);
(*list)[len+1] = NULL;
}
char line[MAXPATHLEN];
if (!f) {
if (fatal) {
- fprintf(FERROR,"%s : %s\n",fname,strerror(errno));
+ rprintf(FERROR,"%s : %s\n",fname,strerror(errno));
exit_cleanup(1);
}
return list;
{
if (check_exclude(fname,local_exclude_list)) {
if (verbose > 2)
- fprintf(FINFO,"excluding file %s\n",fname);
+ rprintf(FINFO,"excluding file %s\n",fname);
return 0;
}
return 1;
if (link_stat(fname,&st) != 0) {
io_error = 1;
- fprintf(FERROR,"%s: %s\n",
+ rprintf(FERROR,"%s: %s\n",
fname,strerror(errno));
return NULL;
}
if (S_ISDIR(st.st_mode) && !recurse) {
- fprintf(FINFO,"skipping directory %s\n",fname);
+ rprintf(FINFO,"skipping directory %s\n",fname);
return NULL;
}
return NULL;
if (verbose > 2)
- fprintf(FINFO,"make_file(%s)\n",fname);
+ rprintf(FINFO,"make_file(%s)\n",fname);
file = (struct file_struct *)malloc(sizeof(*file));
if (!file) out_of_memory("make_file");
char lnk[MAXPATHLEN];
if ((l=readlink(fname,lnk,MAXPATHLEN-1)) == -1) {
io_error=1;
- fprintf(FERROR,"readlink %s : %s\n",
+ rprintf(FERROR,"readlink %s : %s\n",
fname,strerror(errno));
return NULL;
}
d = opendir(dir);
if (!d) {
io_error = 1;
- fprintf(FERROR,"%s: %s\n",
+ rprintf(FERROR,"%s: %s\n",
dir,strerror(errno));
return;
}
if (fname[l-1] != '/') {
if (l == MAXPATHLEN-1) {
io_error = 1;
- fprintf(FERROR,"skipping long-named directory %s\n",fname);
+ rprintf(FERROR,"skipping long-named directory %s\n",fname);
closedir(d);
return;
}
local_exclude_list = make_exclude_list(fname,NULL,0);
} else {
io_error = 1;
- fprintf(FINFO,"cannot cvs-exclude in long-named directory %s\n",fname);
+ rprintf(FINFO,"cannot cvs-exclude in long-named directory %s\n",fname);
}
}
struct file_list *flist;
if (verbose && recurse && !am_server && f != -1) {
- fprintf(FINFO,"building file list ... ");
- fflush(FINFO);
+ rprintf(FINFO,"building file list ... ");
+ rflush(FINFO);
}
flist = (struct file_list *)malloc(sizeof(flist[0]));
if (link_stat(fname,&st) != 0) {
io_error=1;
- fprintf(FERROR,"%s : %s\n",fname,strerror(errno));
+ rprintf(FERROR,"%s : %s\n",fname,strerror(errno));
continue;
}
if (S_ISDIR(st.st_mode) && !recurse) {
- fprintf(FINFO,"skipping directory %s\n",fname);
+ rprintf(FINFO,"skipping directory %s\n",fname);
continue;
}
if (dir && *dir) {
if (getcwd(dbuf,MAXPATHLEN-1) == NULL) {
- fprintf(FERROR,"getwd : %s\n",strerror(errno));
+ rprintf(FERROR,"getwd : %s\n",strerror(errno));
exit_cleanup(1);
}
if (chdir(dir) != 0) {
io_error=1;
- fprintf(FERROR,"chdir %s : %s\n",
+ rprintf(FERROR,"chdir %s : %s\n",
dir,strerror(errno));
continue;
}
send_file_name(f,flist,fname,recurse,FLAG_DELETE);
flist_dir = NULL;
if (chdir(dbuf) != 0) {
- fprintf(FERROR,"chdir %s : %s\n",
+ rprintf(FERROR,"chdir %s : %s\n",
dbuf,strerror(errno));
exit_cleanup(1);
}
}
if (verbose && recurse && !am_server && f != -1)
- fprintf(FINFO,"done\n");
+ rprintf(FINFO,"done\n");
clean_flist(flist);
}
if (verbose > 2)
- fprintf(FINFO,"send_file_list done\n");
+ rprintf(FINFO,"send_file_list done\n");
return flist;
}
unsigned char flags;
if (verbose && recurse && !am_server) {
- fprintf(FINFO,"receiving file list ... ");
- fflush(FINFO);
+ rprintf(FINFO,"receiving file list ... ");
+ rflush(FINFO);
}
flist = (struct file_list *)malloc(sizeof(flist[0]));
flist->count++;
if (verbose > 2)
- fprintf(FINFO,"recv_file_name(%s)\n",f_name(flist->files[i]));
+ rprintf(FINFO,"recv_file_name(%s)\n",f_name(flist->files[i]));
}
if (verbose > 2)
- fprintf(FINFO,"received %d names\n",flist->count);
+ rprintf(FINFO,"received %d names\n",flist->count);
clean_flist(flist);
if (verbose && recurse && !am_server) {
- fprintf(FINFO,"done\n");
+ rprintf(FINFO,"done\n");
}
/* now recv the uid/gid list. This was introduced in protocol version 15 */
}
if (verbose > 2)
- fprintf(FINFO,"recv_file_list done\n");
+ rprintf(FINFO,"recv_file_list done\n");
return flist;
strcmp(f_name(flist->files[i]),
f_name(flist->files[i-1])) == 0) {
if (verbose > 1 && !am_server)
- fprintf(FINFO,"removing duplicate name %s from file list %d\n",
+ rprintf(FINFO,"removing duplicate name %s from file list %d\n",
f_name(flist->files[i-1]),i-1);
free_file(flist->files[i]);
}
#include "rsync.h"
-extern int am_server;
extern int dry_run;
extern int verbose;
if (link_stat(f_name(&hlink_list[i]),&st2) != 0) {
if (do_link(f_name(&hlink_list[i-1]),f_name(&hlink_list[i])) != 0) {
if (verbose > 0)
- fprintf(FINFO,"link %s => %s : %s\n",
+ rprintf(FINFO,"link %s => %s : %s\n",
f_name(&hlink_list[i]),
f_name(&hlink_list[i-1]),strerror(errno));
return;
if (do_unlink(f_name(&hlink_list[i])) != 0 ||
do_link(f_name(&hlink_list[i-1]),f_name(&hlink_list[i])) != 0) {
if (verbose > 0)
- fprintf(FINFO,"link %s => %s : %s\n",
+ rprintf(FINFO,"link %s => %s : %s\n",
f_name(&hlink_list[i]),
f_name(&hlink_list[i-1]),strerror(errno));
return;
}
}
if (verbose > 0)
- fprintf(FINFO,"%s => %s\n",
+ rprintf(FINFO,"%s => %s\n",
f_name(&hlink_list[i]),f_name(&hlink_list[i-1]));
}
#endif
t = time(NULL);
if (last_io && io_timeout && (t-last_io)>io_timeout) {
- fprintf(FERROR,"read timeout after %d second - exiting\n",
+ rprintf(FERROR,"read timeout after %d second - exiting\n",
(int)(t-last_io));
exit_cleanup(1);
}
char b[4];
if ((ret=readfd(f,b,4)) != 4) {
if (verbose > 1)
- fprintf(FERROR,"(%d) Error reading %d bytes : %s\n",
+ rprintf(FERROR,"(%d) Error reading %d bytes : %s\n",
getpid(),4,ret==-1?strerror(errno):"EOF");
exit_cleanup(1);
}
if ((int32)ret != (int32)0xffffffff) return ret;
#ifdef NO_INT64
- fprintf(FERROR,"Integer overflow - attempted 64 bit offset\n");
+ rprintf(FERROR,"Integer overflow - attempted 64 bit offset\n");
exit_cleanup(1);
#else
if (remote_version >= 16) {
if ((ret=readfd(f,b,8)) != 8) {
if (verbose > 1)
- fprintf(FERROR,"(%d) Error reading %d bytes : %s\n",
+ rprintf(FERROR,"(%d) Error reading %d bytes : %s\n",
getpid(),8,ret==-1?strerror(errno):"EOF");
exit_cleanup(1);
}
int ret;
if ((ret=readfd(f,buf,len)) != len) {
if (verbose > 1)
- fprintf(FERROR,"(%d) Error reading %d bytes : %s\n",
+ rprintf(FERROR,"(%d) Error reading %d bytes : %s\n",
getpid(),len,ret==-1?strerror(errno):"EOF");
exit_cleanup(1);
}
systems it seems (eg. IRIX) */
u_sleep(1000);
#if 0
- fprintf(FERROR,"write exception\n");
+ rprintf(FERROR,"write exception\n");
exit_cleanup(1);
#endif
}
&w_fds,NULL,&tv);
if (count == -1 && errno != EINTR) {
if (verbose > 1)
- fprintf(FERROR,"select error: %s\n", strerror(errno));
+ rprintf(FERROR,"select error: %s\n", strerror(errno));
exit_cleanup(1);
}
char b[4];
SIVAL(b,0,x);
if ((ret=writefd(f,b,4)) != 4) {
- fprintf(FERROR,"write_int failed : %s\n",
+ rprintf(FERROR,"write_int failed : %s\n",
ret==-1?strerror(errno):"EOF");
exit_cleanup(1);
}
SIVAL(b,4,((x>>32)&0xFFFFFFFF));
if ((ret=writefd(f,b,8)) != 8) {
- fprintf(FERROR,"write_longint failed : %s\n",
+ rprintf(FERROR,"write_longint failed : %s\n",
ret==-1?strerror(errno):"EOF");
exit_cleanup(1);
}
{
int ret;
if ((ret=writefd(f,buf,len)) != len) {
- fprintf(FERROR,"write_buf failed : %s\n",
+ rprintf(FERROR,"write_buf failed : %s\n",
ret==-1?strerror(errno):"EOF");
exit_cleanup(1);
}
int force_delete = 0;
int io_timeout = 0;
int io_error = 0;
+static int port = RSYNC_PORT;
static char *shell_cmd;
int am_server = 0;
int am_sender;
int recurse = 0;
+int am_daemon;
-static void usage(FILE *f);
+static void usage(int fd);
static void report(int f)
{
args[argc] = NULL;
if (verbose > 3) {
- fprintf(FINFO,"cmd=");
+ rprintf(FINFO,"cmd=");
for (i=0;i<argc;i++)
- fprintf(FINFO,"%s ",args[i]);
- fprintf(FINFO,"\n");
+ rprintf(FINFO,"%s ",args[i]);
+ rprintf(FINFO,"\n");
}
if (local_server) {
if (do_stat(name,&st) == 0) {
if (S_ISDIR(st.st_mode)) {
if (chdir(name) != 0) {
- fprintf(FERROR,"chdir %s : %s (1)\n",name,strerror(errno));
+ rprintf(FERROR,"chdir %s : %s (1)\n",name,strerror(errno));
exit_cleanup(1);
}
return NULL;
}
if (flist->count > 1) {
- fprintf(FERROR,"ERROR: destination must be a directory when copying more than 1 file\n");
+ rprintf(FERROR,"ERROR: destination must be a directory when copying more than 1 file\n");
exit_cleanup(1);
}
return name;
return NULL;
if (do_mkdir(name,0777 & ~orig_umask) != 0) {
- fprintf(FERROR,"mkdir %s : %s (1)\n",name,strerror(errno));
+ rprintf(FERROR,"mkdir %s : %s (1)\n",name,strerror(errno));
exit_cleanup(1);
} else {
- fprintf(FINFO,"created directory %s\n",name);
+ rprintf(FINFO,"created directory %s\n",name);
}
if (chdir(name) != 0) {
- fprintf(FERROR,"chdir %s : %s (2)\n",name,strerror(errno));
+ rprintf(FERROR,"chdir %s : %s (2)\n",name,strerror(errno));
exit_cleanup(1);
}
-void do_server_sender(int argc,char *argv[])
+static void do_server_sender(int f_in, int f_out, int argc,char *argv[])
{
int i;
struct file_list *flist;
char *dir = argv[0];
if (verbose > 2)
- fprintf(FINFO,"server_sender starting pid=%d\n",(int)getpid());
+ rprintf(FINFO,"server_sender starting pid=%d\n",(int)getpid());
if (!relative_paths && chdir(dir) != 0) {
- fprintf(FERROR,"chdir %s: %s (3)\n",dir,strerror(errno));
+ rprintf(FERROR,"chdir %s: %s (3)\n",dir,strerror(errno));
exit_cleanup(1);
}
argc--;
}
- flist = send_file_list(STDOUT_FILENO,argc,argv);
- send_files(flist,STDOUT_FILENO,STDIN_FILENO);
- report(STDOUT_FILENO);
+ flist = send_file_list(f_out,argc,argv);
+ send_files(flist,f_out,f_in);
+ report(f_out);
exit_cleanup(0);
}
init_hard_links(flist);
if (pipe(recv_pipe) < 0) {
- fprintf(FERROR,"pipe failed in do_recv\n");
+ rprintf(FERROR,"pipe failed in do_recv\n");
exit(1);
}
if ((pid=do_fork()) == 0) {
recv_files(f_in,flist,local_name,recv_pipe[1]);
if (verbose > 2)
- fprintf(FINFO,"receiver read %ld\n",(long)read_total());
+ rprintf(FINFO,"receiver read %ld\n",(long)read_total());
exit_cleanup(0);
}
}
-void do_server_recv(int argc,char *argv[])
+static void do_server_recv(int f_in, int f_out, int argc,char *argv[])
{
int status;
struct file_list *flist;
char *dir = NULL;
if (verbose > 2)
- fprintf(FINFO,"server_recv(%d) starting pid=%d\n",argc,(int)getpid());
+ rprintf(FINFO,"server_recv(%d) starting pid=%d\n",argc,(int)getpid());
if (argc > 0) {
dir = argv[0];
argc--;
argv++;
if (chdir(dir) != 0) {
- fprintf(FERROR,"chdir %s : %s (4)\n",
+ rprintf(FERROR,"chdir %s : %s (4)\n",
dir,strerror(errno));
exit_cleanup(1);
}
}
if (delete_mode)
- recv_exclude_list(STDIN_FILENO);
+ recv_exclude_list(f_in);
- flist = recv_file_list(STDIN_FILENO);
+ flist = recv_file_list(f_in);
if (!flist || flist->count == 0) {
- fprintf(FERROR,"nothing to do\n");
+ rprintf(FERROR,"nothing to do\n");
exit_cleanup(1);
}
local_name = get_local_name(flist,argv[0]);
}
- status = do_recv(STDIN_FILENO,STDOUT_FILENO,flist,local_name);
+ status = do_recv(f_in,f_out,flist,local_name);
exit_cleanup(status);
}
-void start_server(int argc, char *argv[])
+void start_server(int f_in, int f_out, int argc, char *argv[])
{
- setup_protocol(STDOUT_FILENO,STDIN_FILENO);
+ setup_protocol(f_out, f_in);
if (am_sender) {
- recv_exclude_list(STDIN_FILENO);
+ recv_exclude_list(f_in);
if (cvs_exclude)
add_cvs_excludes();
- do_server_sender(argc,argv);
+ do_server_sender(f_in, f_out, argc, argv);
} else {
- do_server_recv(argc,argv);
+ do_server_recv(f_in, f_out, argc, argv);
}
exit_cleanup(0);
}
+static int client_run(int f_in, int f_out, int pid, int argc, char *argv[])
+{
+ struct file_list *flist;
+ int status = 0, status2 = 0;
+ char *local_name = NULL;
+
+ setup_protocol(f_out,f_in);
+
+ if (am_sender) {
+ if (cvs_exclude)
+ add_cvs_excludes();
+ if (delete_mode)
+ send_exclude_list(f_out);
+ flist = send_file_list(f_out,argc,argv);
+ if (verbose > 3)
+ rprintf(FINFO,"file list sent\n");
+ send_files(flist,f_out,f_in);
+ if (pid != -1) {
+ if (verbose > 3)
+ rprintf(FINFO,"waiting on %d\n",pid);
+ waitpid(pid, &status, 0);
+ }
+ report(-1);
+ exit_cleanup(status);
+ }
+
+ send_exclude_list(f_out);
+
+ flist = recv_file_list(f_in);
+ if (!flist || flist->count == 0) {
+ rprintf(FINFO,"nothing to do\n");
+ exit_cleanup(0);
+ }
+
+ local_name = get_local_name(flist,argv[0]);
+
+ status2 = do_recv(f_in,f_out,flist,local_name);
+
+ report(f_in);
+
+ if (pid != -1) {
+ waitpid(pid, &status, 0);
+ }
+
+ return status | status2;
+}
+
+
+int start_socket_client(char *host, char *path, int argc, char *argv[])
+{
+ int fd;
+ char *sargs[100];
+ int sargc=0;
+
+ fd = open_socket_out(host, port);
+ if (fd == -1) {
+ rprintf(FERROR,"failed to connect to %s - %s\n", host, strerror(errno));
+ exit_cleanup(1);
+ }
+
+ server_options(sargs,&sargc);
+
+ sargs[sargc++] = ".";
+
+ if (path && *path)
+ sargs[sargc++] = path;
+
+ sargs[sargc] = NULL;
+
+ return client_run(fd, fd, -1, argc, argv);
+}
+
int start_client(int argc, char *argv[])
{
char *p;
char *shell_machine = NULL;
char *shell_path = NULL;
char *shell_user = NULL;
- int pid, status = 0, status2 = 0;
+ int pid;
int f_in,f_out;
- struct file_list *flist;
- char *local_name = NULL;
p = strchr(argv[0],':');
if (p) {
+ if (p[1] == ':') {
+ *p = 0;
+ return start_socket_client(argv[0], p+2, argc-1, argv+1);
+ }
am_sender = 0;
*p = 0;
shell_machine = argv[0];
argv++;
} else {
am_sender = 1;
-
+
p = strchr(argv[argc-1],':');
if (!p) {
local_server = 1;
+ } else if (p[1] == ':') {
+ *p = 0;
+ return start_socket_client(argv[argc-1], p+2, argc-1, argv);
}
-
+
if (local_server) {
shell_machine = NULL;
shell_path = argv[argc-1];
}
if (verbose > 3) {
- fprintf(FINFO,"cmd=%s machine=%s user=%s path=%s\n",
+ rprintf(FINFO,"cmd=%s machine=%s user=%s path=%s\n",
shell_cmd?shell_cmd:"",
shell_machine?shell_machine:"",
shell_user?shell_user:"",
pid = do_cmd(shell_cmd,shell_machine,shell_user,shell_path,&f_in,&f_out);
- setup_protocol(f_out,f_in);
-
#if HAVE_SETLINEBUF
- setlinebuf(FINFO);
- setlinebuf(FERROR);
+ setlinebuf(stdout);
+ setlinebuf(stderr);
#endif
-
- if (verbose > 3)
- fprintf(FINFO,"parent=%d child=%d sender=%d recurse=%d\n",
- (int)getpid(),pid,am_sender,recurse);
-
- if (am_sender) {
- if (cvs_exclude)
- add_cvs_excludes();
- if (delete_mode)
- send_exclude_list(f_out);
- flist = send_file_list(f_out,argc,argv);
- if (verbose > 3)
- fprintf(FINFO,"file list sent\n");
- send_files(flist,f_out,f_in);
- if (verbose > 3)
- fprintf(FINFO,"waiting on %d\n",pid);
- waitpid(pid, &status, 0);
- report(-1);
- exit_cleanup(status);
- }
-
- send_exclude_list(f_out);
-
- flist = recv_file_list(f_in);
- if (!flist || flist->count == 0) {
- fprintf(FINFO,"nothing to do\n");
- exit_cleanup(0);
- }
-
- local_name = get_local_name(flist,argv[0]);
-
- status2 = do_recv(f_in,f_out,flist,local_name);
-
- report(f_in);
-
- waitpid(pid, &status, 0);
-
- return status | status2;
+
+ return client_run(f_in, f_out, pid, argc, argv);
}
-static void usage(FILE *f)
+static void usage(int F)
{
- fprintf(f,"rsync version %s Copyright Andrew Tridgell and Paul Mackerras\n\n",
+ rprintf(F,"rsync version %s Copyright Andrew Tridgell and Paul Mackerras\n\n",
VERSION);
- fprintf(f,"Usage:\t%s [options] src user@host:dest\nOR",RSYNC_NAME);
- fprintf(f,"\t%s [options] user@host:src dest\n\n",RSYNC_NAME);
- fprintf(f,"Options:\n");
- fprintf(f,"-v, --verbose increase verbosity\n");
- fprintf(f,"-c, --checksum always checksum\n");
- fprintf(f,"-a, --archive archive mode (same as -rlptDog)\n");
- fprintf(f,"-r, --recursive recurse into directories\n");
- fprintf(f,"-R, --relative use relative path names\n");
- fprintf(f,"-b, --backup make backups (default ~ extension)\n");
- fprintf(f,"-u, --update update only (don't overwrite newer files)\n");
- fprintf(f,"-l, --links preserve soft links\n");
- fprintf(f,"-L, --copy-links treat soft links like regular files\n");
- fprintf(f,"-H, --hard-links preserve hard links\n");
- fprintf(f,"-p, --perms preserve permissions\n");
- fprintf(f,"-o, --owner preserve owner (root only)\n");
- fprintf(f,"-g, --group preserve group\n");
- fprintf(f,"-D, --devices preserve devices (root only)\n");
- fprintf(f,"-t, --times preserve times\n");
- fprintf(f,"-S, --sparse handle sparse files efficiently\n");
- fprintf(f,"-n, --dry-run show what would have been transferred\n");
- fprintf(f,"-W, --whole-file copy whole files, no incremental checks\n");
- fprintf(f,"-x, --one-file-system don't cross filesystem boundaries\n");
- fprintf(f,"-B, --block-size SIZE checksum blocking size\n");
- fprintf(f,"-e, --rsh COMMAND specify rsh replacement\n");
- fprintf(f," --rsync-path PATH specify path to rsync on the remote machine\n");
- fprintf(f,"-C, --cvs-exclude auto ignore files in the same way CVS does\n");
- fprintf(f," --delete delete files that don't exist on the sending side\n");
- fprintf(f," --force force deletion of directories even if not empty\n");
- fprintf(f," --numeric-ids don't map uid/gid values by user/group name\n");
- fprintf(f," --timeout TIME set IO timeout in seconds\n");
- fprintf(f,"-I, --ignore-times don't exclude files that match length and time\n");
- fprintf(f,"-T --temp-dir DIR create temporary files in directory DIR\n");
- fprintf(f,"-z, --compress compress file data\n");
- fprintf(f," --exclude FILE exclude file FILE\n");
- fprintf(f," --exclude-from FILE exclude files listed in FILE\n");
- fprintf(f," --suffix SUFFIX override backup suffix\n");
- fprintf(f," --version print version number\n");
-
- fprintf(f,"\n");
- fprintf(f,"the backup suffix defaults to %s\n",BACKUP_SUFFIX);
- fprintf(f,"the block size defaults to %d\n",BLOCK_SIZE);
+ rprintf(F,"Usage:\t%s [options] src user@host:dest\nOR",RSYNC_NAME);
+ rprintf(F,"\t%s [options] user@host:src dest\n\n",RSYNC_NAME);
+ rprintf(F,"Options:\n");
+ rprintf(F,"-v, --verbose increase verbosity\n");
+ rprintf(F,"-c, --checksum always checksum\n");
+ rprintf(F,"-a, --archive archive mode (same as -rlptDog)\n");
+ rprintf(F,"-r, --recursive recurse into directories\n");
+ rprintf(F,"-R, --relative use relative path names\n");
+ rprintf(F,"-b, --backup make backups (default ~ extension)\n");
+ rprintf(F,"-u, --update update only (don't overwrite newer files)\n");
+ rprintf(F,"-l, --links preserve soft links\n");
+ rprintf(F,"-L, --copy-links treat soft links like regular files\n");
+ rprintf(F,"-H, --hard-links preserve hard links\n");
+ rprintf(F,"-p, --perms preserve permissions\n");
+ rprintf(F,"-o, --owner preserve owner (root only)\n");
+ rprintf(F,"-g, --group preserve group\n");
+ rprintf(F,"-D, --devices preserve devices (root only)\n");
+ rprintf(F,"-t, --times preserve times\n");
+ rprintf(F,"-S, --sparse handle sparse files efficiently\n");
+ rprintf(F,"-n, --dry-run show what would have been transferred\n");
+ rprintf(F,"-W, --whole-file copy whole files, no incremental checks\n");
+ rprintf(F,"-x, --one-file-system don't cross filesystem boundaries\n");
+ rprintf(F,"-B, --block-size SIZE checksum blocking size\n");
+ rprintf(F,"-e, --rsh COMMAND specify rsh replacement\n");
+ rprintf(F," --rsync-path PATH specify path to rsync on the remote machine\n");
+ rprintf(F,"-C, --cvs-exclude auto ignore files in the same way CVS does\n");
+ rprintf(F," --delete delete files that don't exist on the sending side\n");
+ rprintf(F," --force force deletion of directories even if not empty\n");
+ rprintf(F," --numeric-ids don't map uid/gid values by user/group name\n");
+ rprintf(F," --timeout TIME set IO timeout in seconds\n");
+ rprintf(F,"-I, --ignore-times don't exclude files that match length and time\n");
+ rprintf(F,"-T --temp-dir DIR create temporary files in directory DIR\n");
+ rprintf(F,"-z, --compress compress file data\n");
+ rprintf(F," --exclude FILE exclude file FILE\n");
+ rprintf(F," --exclude-from FILE exclude files listed in FILE\n");
+ rprintf(F," --suffix SUFFIX override backup suffix\n");
+ rprintf(F," --version print version number\n");
+
+ rprintf(F,"\n");
+ rprintf(F,"the backup suffix defaults to %s\n",BACKUP_SUFFIX);
+ rprintf(F,"the block size defaults to %d\n",BLOCK_SIZE);
}
enum {OPT_VERSION,OPT_SUFFIX,OPT_SENDER,OPT_SERVER,OPT_EXCLUDE,
OPT_EXCLUDE_FROM,OPT_DELETE,OPT_NUMERIC_IDS,OPT_RSYNC_PATH,
- OPT_FORCE,OPT_TIMEOUT};
+ OPT_FORCE,OPT_TIMEOUT,OPT_DAEMON};
static char *short_options = "oblLWHpguDCtcahvrRIxnSe:B:T:z";
{"timeout", 1, 0, OPT_TIMEOUT},
{"temp-dir", 1, 0, 'T'},
{"compress", 0, 0, 'z'},
+ {"daemon", 0, 0, OPT_DAEMON},
{0,0,0,0}};
RETSIGTYPE sigusr1_handler(int val) {
#if SUPPORT_HARD_LINKS
preserve_hard_links=1;
#else
- fprintf(FERROR,"ERROR: hard links not supported on this platform\n");
+ rprintf(FERROR,"ERROR: hard links not supported on this platform\n");
exit_cleanup(1);
#endif
break;
do_compression = 1;
break;
+ case OPT_DAEMON:
+ am_daemon = 1;
+ break;
+
default:
- /* fprintf(FERROR,"bad option -%c\n",opt); */
+ /* rprintf(FERROR,"bad option -%c\n",opt); */
exit_cleanup(1);
}
}
#ifndef SUPPORT_LINKS
if (!am_server && preserve_links) {
- fprintf(FERROR,"ERROR: symbolic links not supported\n");
+ rprintf(FERROR,"ERROR: symbolic links not supported\n");
exit_cleanup(1);
}
#endif
if (am_server) {
- start_server(argc, argv);
+ start_server(STDIN_FILENO, STDOUT_FILENO, argc, argv);
}
if (argc < 2) {
int j;
if (verbose > 2 && i >= 0)
- fprintf(FINFO,"match at %d last_match=%d j=%d len=%d n=%d\n",
+ rprintf(FINFO,"match at %d last_match=%d j=%d len=%d n=%d\n",
(int)offset,(int)last_match,i,(int)s->sums[i].len,(int)n);
send_token(f,i,buf,last_match,n,i==-1?0:s->sums[i].len);
schar *map;
if (verbose > 2)
- fprintf(FINFO,"hash search b=%d len=%d\n",s->n,(int)len);
+ rprintf(FINFO,"hash search b=%d len=%d\n",s->n,(int)len);
k = MIN(len, s->n);
s1 = sum & 0xFFFF;
s2 = sum >> 16;
if (verbose > 3)
- fprintf(FINFO, "sum=%.8x k=%d\n", sum, k);
+ rprintf(FINFO, "sum=%.8x k=%d\n", sum, k);
offset = 0;
end = len + 1 - s->sums[s->count-1].len;
if (verbose > 3)
- fprintf(FINFO,"hash search s->n=%d len=%d count=%d\n",
+ rprintf(FINFO,"hash search s->n=%d len=%d count=%d\n",
s->n,(int)len,s->count);
do {
j = tag_table[t];
if (verbose > 4)
- fprintf(FINFO,"offset=%d sum=%08x\n",(int)offset,sum);
+ rprintf(FINFO,"offset=%d sum=%08x\n",(int)offset,sum);
if (j == NULL_TAG) {
goto null_tag;
if (sum != s->sums[i].sum1) continue;
if (verbose > 3)
- fprintf(FINFO,"potential match at %d target=%d %d sum=%08x\n",
+ rprintf(FINFO,"potential match at %d target=%d %d sum=%08x\n",
(int)offset,j,i,sum);
if (!done_csum2) {
build_hash_table(s);
if (verbose > 2)
- fprintf(FINFO,"built hash table\n");
+ rprintf(FINFO,"built hash table\n");
hash_search(f,s,buf,len);
if (verbose > 2)
- fprintf(FINFO,"done hash search\n");
+ rprintf(FINFO,"done hash search\n");
} else {
matched(f,s,buf,len,-1);
}
if (remote_version >= 14) {
if (verbose > 2)
- fprintf(FINFO,"sending file_sum\n");
+ rprintf(FINFO,"sending file_sum\n");
write_buf(f,file_sum,MD4_SUM_LENGTH);
}
}
if (verbose > 2)
- fprintf(FINFO, "false_alarms=%d tag_hits=%d matches=%d\n",
+ rprintf(FINFO, "false_alarms=%d tag_hits=%d matches=%d\n",
false_alarms, tag_hits, matches);
total_tag_hits += tag_hits;
if (verbose <= 1)
return;
- fprintf(FINFO,
+ rprintf(FINFO,
"total: matches=%d tag_hits=%d false_alarms=%d data=%ld\n",
total_matches,total_tag_hits,
total_false_alarms,(long)total_data_transfer);
if (count == 0 && MDp->done) return;
/* check to see if MD is already done and report error */
if (MDp->done)
- { fprintf(FERROR,"\nError: MDupdate MD already done."); return; }
+ { rprintf(FERROR,"\nError: MDupdate MD already done."); return; }
/* Add count to MDp->count */
tmp = count;
p = MDp->count;
MDblock(MDp,(unsigned int *)X);
}
else if (count > 512) /* Check for count too large */
- { fprintf(FERROR,"\nError: MDupdate called with illegal count value %d."
+ { rprintf(FERROR,"\nError: MDupdate called with illegal count value %d."
,count);
return;
}
ret = do_stat(fname, &st);
#endif
if (ret) {
- fprintf(FERROR,"stat(%s) : %s\n", fname, strerror(errno));
+ rprintf(FERROR,"stat(%s) : %s\n", fname, strerror(errno));
return -1;
}
if (!S_ISDIR(st.st_mode)) {
- fprintf(FERROR,"unlink(%s) : %s\n", fname, strerror(errno));
+ rprintf(FERROR,"unlink(%s) : %s\n", fname, strerror(errno));
return -1;
}
if (do_rmdir(fname) == 0 || errno == ENOENT) return 0;
if (!force_delete || (errno != ENOTEMPTY && errno != EEXIST)) {
- fprintf(FERROR,"rmdir(%s) : %s\n", fname, strerror(errno));
+ rprintf(FERROR,"rmdir(%s) : %s\n", fname, strerror(errno));
return -1;
}
/* now we do a recsursive delete on the directory ... */
d = opendir(fname);
if (!d) {
- fprintf(FERROR,"opendir(%s): %s\n",
+ rprintf(FERROR,"opendir(%s): %s\n",
fname,strerror(errno));
return -1;
}
strcat(buf, dname);
buf[MAXPATHLEN-1] = 0;
if (verbose > 0)
- fprintf(FINFO,"deleting %s\n", buf);
+ rprintf(FINFO,"deleting %s\n", buf);
if (delete_file(buf) != 0) {
closedir(d);
return -1;
closedir(d);
if (do_rmdir(fname) != 0) {
- fprintf(FERROR,"rmdir(%s) : %s\n", fname, strerror(errno));
+ rprintf(FERROR,"rmdir(%s) : %s\n", fname, strerror(errno));
return -1;
}
}
if (verbose > 3)
- fprintf(FINFO,"count=%d rem=%d n=%d flength=%d\n",
+ rprintf(FINFO,"count=%d rem=%d n=%d flength=%d\n",
s->count,s->remainder,s->n,(int)s->flength);
s->sums = (struct sum_buf *)malloc(sizeof(s->sums[0])*s->count);
s->sums[i].i = i;
if (verbose > 3)
- fprintf(FINFO,"chunk[%d] offset=%d len=%d sum1=%08x\n",
+ rprintf(FINFO,"chunk[%d] offset=%d len=%d sum1=%08x\n",
i,(int)s->sums[i].offset,s->sums[i].len,s->sums[i].sum1);
len -= n1;
s->sums = NULL;
if (verbose > 3)
- fprintf(FINFO,"count=%d n=%d rem=%d\n",
+ rprintf(FINFO,"count=%d n=%d rem=%d\n",
s->count,s->n,s->remainder);
if (s->count == 0)
offset += s->sums[i].len;
if (verbose > 3)
- fprintf(FINFO,"chunk[%d] len=%d offset=%d sum1=%08x\n",
+ rprintf(FINFO,"chunk[%d] len=%d offset=%d sum1=%08x\n",
i,s->sums[i].len,(int)s->sums[i].offset,s->sums[i].sum1);
}
if (!st) {
if (link_stat(fname,&st2) != 0) {
- fprintf(FERROR,"stat %s : %s\n",fname,strerror(errno));
+ rprintf(FERROR,"stat %s : %s\n",fname,strerror(errno));
return 0;
}
st = &st2;
st->st_mtime != file->modtime) {
updated = 1;
if (set_modtime(fname,file->modtime) != 0) {
- fprintf(FERROR,"failed to set times on %s : %s\n",
+ rprintf(FERROR,"failed to set times on %s : %s\n",
fname,strerror(errno));
return 0;
}
st->st_mode != file->mode) {
updated = 1;
if (do_chmod(fname,file->mode) != 0) {
- fprintf(FERROR,"failed to set permissions on %s : %s\n",
+ rprintf(FERROR,"failed to set permissions on %s : %s\n",
fname,strerror(errno));
return 0;
}
if (preserve_uid && st->st_uid != file->uid)
updated = 1;
if (verbose>1 || preserve_uid)
- fprintf(FERROR,"chown %s : %s\n",
+ rprintf(FERROR,"chown %s : %s\n",
fname,strerror(errno));
return updated;
}
if (verbose > 1 && report) {
if (updated)
- fprintf(FINFO,"%s\n",fname);
+ rprintf(FINFO,"%s\n",fname);
else
- fprintf(FINFO,"%s is uptodate\n",fname);
+ rprintf(FINFO,"%s is uptodate\n",fname);
}
return updated;
}
struct file_struct *file = flist->files[i];
if (verbose > 2)
- fprintf(FINFO,"recv_generator(%s,%d)\n",fname,i);
+ rprintf(FINFO,"recv_generator(%s,%d)\n",fname,i);
statret = link_stat(fname,&st);
if (dry_run) return;
if (statret == 0 && !S_ISDIR(st.st_mode)) {
if (do_unlink(fname) != 0) {
- fprintf(FERROR,"unlink %s : %s\n",fname,strerror(errno));
+ rprintf(FERROR,"unlink %s : %s\n",fname,strerror(errno));
return;
}
statret = -1;
if (!(relative_paths && errno==ENOENT &&
create_directory_path(fname)==0 &&
do_mkdir(fname,file->mode)==0)) {
- fprintf(FERROR,"mkdir %s : %s (2)\n",
+ rprintf(FERROR,"mkdir %s : %s (2)\n",
fname,strerror(errno));
}
}
if (set_perms(fname,file,NULL,0) && verbose)
- fprintf(FINFO,"%s/\n",fname);
+ rprintf(FINFO,"%s/\n",fname);
return;
}
}
delete_file(fname);
if (do_symlink(file->link,fname) != 0) {
- fprintf(FERROR,"link %s -> %s : %s\n",
+ rprintf(FERROR,"link %s -> %s : %s\n",
fname,file->link,strerror(errno));
} else {
set_perms(fname,file,NULL,0);
if (verbose)
- fprintf(FINFO,"%s -> %s\n",
+ rprintf(FINFO,"%s -> %s\n",
fname,file->link);
}
#endif
st.st_rdev != file->rdev) {
delete_file(fname);
if (verbose > 2)
- fprintf(FINFO,"mknod(%s,0%o,0x%x)\n",
+ rprintf(FINFO,"mknod(%s,0%o,0x%x)\n",
fname,(int)file->mode,(int)file->rdev);
if (do_mknod(fname,file->mode,file->rdev) != 0) {
- fprintf(FERROR,"mknod %s : %s\n",fname,strerror(errno));
+ rprintf(FERROR,"mknod %s : %s\n",fname,strerror(errno));
} else {
set_perms(fname,file,NULL,0);
if (verbose)
- fprintf(FINFO,"%s\n",fname);
+ rprintf(FINFO,"%s\n",fname);
}
} else {
set_perms(fname,file,&st,1);
if (preserve_hard_links && check_hard_link(file)) {
if (verbose > 1)
- fprintf(FINFO,"%s is a hard link\n",f_name(file));
+ rprintf(FINFO,"%s is a hard link\n",f_name(file));
return;
}
if (!S_ISREG(file->mode)) {
- fprintf(FINFO,"skipping non-regular file %s\n",fname);
+ rprintf(FINFO,"skipping non-regular file %s\n",fname);
return;
}
if (!dry_run) send_sums(NULL,f_out);
} else {
if (verbose > 1)
- fprintf(FERROR,"recv_generator failed to open %s\n",fname);
+ rprintf(FERROR,"recv_generator failed to open %s\n",fname);
}
return;
}
if (update_only && st.st_mtime > file->modtime) {
if (verbose > 1)
- fprintf(FINFO,"%s is newer\n",fname);
+ rprintf(FINFO,"%s is newer\n",fname);
return;
}
fd = open(fname,O_RDONLY);
if (fd == -1) {
- fprintf(FERROR,"failed to open %s : %s\n",fname,strerror(errno));
- fprintf(FERROR,"skipping %s\n",fname);
+ rprintf(FERROR,"failed to open %s : %s\n",fname,strerror(errno));
+ rprintf(FERROR,"skipping %s\n",fname);
return;
}
}
if (verbose > 3)
- fprintf(FINFO,"gen mapped %s of size %d\n",fname,(int)st.st_size);
+ rprintf(FINFO,"gen mapped %s of size %d\n",fname,(int)st.st_size);
s = generate_sums(buf,st.st_size,adapt_block_size(file, block_size));
if (verbose > 2)
- fprintf(FINFO,"sending sums for %d\n",i);
+ rprintf(FINFO,"sending sums for %d\n",i);
write_int(f_out,i);
send_sums(s,f_out);
for (i=recv_token(f_in,&data); i != 0; i=recv_token(f_in,&data)) {
if (i > 0) {
if (verbose > 3)
- fprintf(FINFO,"data recv %d at %d\n",i,(int)offset);
+ rprintf(FINFO,"data recv %d at %d\n",i,(int)offset);
sum_update(data,i);
if (fd != -1 && write_file(fd,data,i) != i) {
- fprintf(FERROR,"write failed on %s : %s\n",fname,strerror(errno));
+ rprintf(FERROR,"write failed on %s : %s\n",fname,strerror(errno));
exit_cleanup(1);
}
offset += i;
len = remainder;
if (verbose > 3)
- fprintf(FINFO,"chunk[%d] of size %d at %d offset=%d\n",
+ rprintf(FINFO,"chunk[%d] of size %d at %d offset=%d\n",
i,len,(int)offset2,(int)offset);
map = map_ptr(buf,offset2,len);
sum_update(map,len);
if (fd != -1 && write_file(fd,map,len) != len) {
- fprintf(FERROR,"write failed on %s : %s\n",fname,strerror(errno));
+ rprintf(FERROR,"write failed on %s : %s\n",fname,strerror(errno));
exit_cleanup(1);
}
offset += len;
}
if (fd != -1 && offset > 0 && sparse_end(fd) != 0) {
- fprintf(FERROR,"write failed on %s : %s\n",fname,strerror(errno));
+ rprintf(FERROR,"write failed on %s : %s\n",fname,strerror(errno));
exit_cleanup(1);
}
if (remote_version >= 14) {
read_buf(f_in,file_sum2,MD4_SUM_LENGTH);
if (verbose > 2)
- fprintf(FINFO,"got file_sum\n");
+ rprintf(FINFO,"got file_sum\n");
if (fd != -1 && memcmp(file_sum1,file_sum2,MD4_SUM_LENGTH) != 0)
return 0;
}
{
if (!S_ISDIR(f->mode)) {
if (do_unlink(f_name(f)) != 0) {
- fprintf(FERROR,"unlink %s : %s\n",f_name(f),strerror(errno));
+ rprintf(FERROR,"unlink %s : %s\n",f_name(f),strerror(errno));
} else if (verbose) {
- fprintf(FINFO,"deleting %s\n",f_name(f));
+ rprintf(FINFO,"deleting %s\n",f_name(f));
}
} else {
if (do_rmdir(f_name(f)) != 0) {
if (errno != ENOTEMPTY && errno != EEXIST)
- fprintf(FERROR,"rmdir %s : %s\n",f_name(f),strerror(errno));
+ rprintf(FERROR,"rmdir %s : %s\n",f_name(f),strerror(errno));
} else if (verbose) {
- fprintf(FINFO,"deleting directory %s\n",f_name(f));
+ rprintf(FINFO,"deleting directory %s\n",f_name(f));
}
}
}
dlist_len++;
if (verbose > 3)
- fprintf(FINFO,"added %s to delete list\n", f_name(file));
+ rprintf(FINFO,"added %s to delete list\n", f_name(file));
}
/* yuck! This function wouldn't have been necessary if I had the sorting
add_cvs_excludes();
if (io_error) {
- fprintf(FINFO,"IO error encountered - skipping file deletion\n");
+ rprintf(FINFO,"IO error encountered - skipping file deletion\n");
return;
}
}
if (verbose > 1)
- fprintf(FINFO,"deleting in %s\n", name);
+ rprintf(FINFO,"deleting in %s\n", name);
for (i=local_file_list->count-1;i>=0;i--) {
if (!local_file_list->files[i]->basename) continue;
int recv_ok;
if (verbose > 2) {
- fprintf(FINFO,"recv_files(%d) starting\n",flist->count);
+ rprintf(FINFO,"recv_files(%d) starting\n",flist->count);
}
if (recurse && delete_mode && !local_name && flist->count>0) {
phase++;
csum_length = SUM_LENGTH;
if (verbose > 2)
- fprintf(FINFO,"recv_files phase=%d\n",phase);
+ rprintf(FINFO,"recv_files phase=%d\n",phase);
write_int(f_gen,-1);
write_flush(f_gen);
continue;
}
if (verbose > 2)
- fprintf(FINFO,"recv_files(%s)\n",fname);
+ rprintf(FINFO,"recv_files(%s)\n",fname);
/* open the file */
fd1 = open(fname,O_RDONLY);
if (fd1 != -1 && do_fstat(fd1,&st) != 0) {
- fprintf(FERROR,"fstat %s : %s\n",fname,strerror(errno));
+ rprintf(FERROR,"fstat %s : %s\n",fname,strerror(errno));
receive_data(f_in,NULL,-1,NULL);
close(fd1);
continue;
}
if (fd1 != -1 && !S_ISREG(st.st_mode)) {
- fprintf(FERROR,"%s : not a regular file (recv_files)\n",fname);
+ rprintf(FERROR,"%s : not a regular file (recv_files)\n",fname);
receive_data(f_in,NULL,-1,NULL);
close(fd1);
continue;
if (fd1 != -1 && st.st_size > 0) {
buf = map_file(fd1,st.st_size);
if (verbose > 2)
- fprintf(FINFO,"recv mapped %s of size %d\n",fname,(int)st.st_size);
+ rprintf(FINFO,"recv mapped %s of size %d\n",fname,(int)st.st_size);
} else {
buf = NULL;
}
/* open tmp file */
if (strlen(fname) > (MAXPATHLEN-8)) {
- fprintf(FERROR,"filename too long\n");
+ rprintf(FERROR,"filename too long\n");
if (buf) unmap_file(buf);
close(fd1);
continue;
sprintf(fnametmp,"%s.XXXXXX",fname);
}
if (NULL == do_mktemp(fnametmp)) {
- fprintf(FERROR,"mktemp %s failed\n",fnametmp);
+ rprintf(FERROR,"mktemp %s failed\n",fnametmp);
receive_data(f_in,buf,-1,NULL);
if (buf) unmap_file(buf);
close(fd1);
fd2 = do_open(fnametmp,O_WRONLY|O_CREAT|O_EXCL,file->mode);
}
if (fd2 == -1) {
- fprintf(FERROR,"open %s : %s\n",fnametmp,strerror(errno));
+ rprintf(FERROR,"open %s : %s\n",fnametmp,strerror(errno));
receive_data(f_in,buf,-1,NULL);
if (buf) unmap_file(buf);
close(fd1);
close(fd2);
if (verbose > 2)
- fprintf(FINFO,"renaming %s to %s\n",fnametmp,fname);
+ rprintf(FINFO,"renaming %s to %s\n",fnametmp,fname);
if (make_backups) {
char fnamebak[MAXPATHLEN];
if (strlen(fname) + strlen(backup_suffix) > (MAXPATHLEN-1)) {
- fprintf(FERROR,"backup filename too long\n");
+ rprintf(FERROR,"backup filename too long\n");
continue;
}
sprintf(fnamebak,"%s%s",fname,backup_suffix);
if (do_rename(fname,fnamebak) != 0 && errno != ENOENT) {
- fprintf(FERROR,"rename %s %s : %s\n",fname,fnamebak,strerror(errno));
+ rprintf(FERROR,"rename %s %s : %s\n",fname,fnamebak,strerror(errno));
continue;
}
}
/* rename failed on cross-filesystem link.
Copy the file instead. */
if (copy_file(fnametmp,fname, file->mode)) {
- fprintf(FERROR,"copy %s -> %s : %s\n",
+ rprintf(FERROR,"copy %s -> %s : %s\n",
fnametmp,fname,strerror(errno));
} else {
set_perms(fname,file,NULL,0);
}
do_unlink(fnametmp);
} else {
- fprintf(FERROR,"rename %s -> %s : %s\n",
+ rprintf(FERROR,"rename %s -> %s : %s\n",
fnametmp,fname,strerror(errno));
do_unlink(fnametmp);
}
if (!recv_ok) {
if (csum_length == SUM_LENGTH) {
- fprintf(FERROR,"ERROR: file corruption in %s. File changed during transfer?\n",
+ rprintf(FERROR,"ERROR: file corruption in %s. File changed during transfer?\n",
fname);
} else {
if (verbose > 1)
- fprintf(FINFO,"redoing %s(%d)\n",fname,i);
+ rprintf(FINFO,"redoing %s(%d)\n",fname,i);
write_int(f_gen,i);
}
}
}
if (verbose > 2)
- fprintf(FINFO,"recv_files finished\n");
+ rprintf(FINFO,"recv_files finished\n");
return 0;
}
int offset=0;
if (verbose > 2)
- fprintf(FINFO,"send_files starting\n");
+ rprintf(FINFO,"send_files starting\n");
setup_nonblocking(f_in,f_out);
write_int(f_out,-1);
write_flush(f_out);
if (verbose > 2)
- fprintf(FINFO,"send_files phase=%d\n",phase);
+ rprintf(FINFO,"send_files phase=%d\n",phase);
continue;
}
break;
fname[MAXPATHLEN-1] = 0;
if (strlen(fname) == MAXPATHLEN-1) {
io_error = 1;
- fprintf(FERROR, "send_files failed on long-named directory %s\n",
+ rprintf(FERROR, "send_files failed on long-named directory %s\n",
fname);
return;
}
strncat(fname,f_name(file),MAXPATHLEN-strlen(fname));
if (verbose > 2)
- fprintf(FINFO,"send_files(%d,%s)\n",i,fname);
+ rprintf(FINFO,"send_files(%d,%s)\n",i,fname);
if (dry_run) {
if (!am_server && verbose)
s = receive_sums(f_in);
if (!s) {
io_error = 1;
- fprintf(FERROR,"receive_sums failed\n");
+ rprintf(FERROR,"receive_sums failed\n");
return;
}
fd = open(fname,O_RDONLY);
if (fd == -1) {
io_error = 1;
- fprintf(FERROR,"send_files failed to open %s: %s\n",
+ rprintf(FERROR,"send_files failed to open %s: %s\n",
fname,strerror(errno));
free_sums(s);
continue;
/* map the local file */
if (do_fstat(fd,&st) != 0) {
io_error = 1;
- fprintf(FERROR,"fstat failed : %s\n",strerror(errno));
+ rprintf(FERROR,"fstat failed : %s\n",strerror(errno));
free_sums(s);
close(fd);
return;
}
if (verbose > 2)
- fprintf(FINFO,"send_files mapped %s of size %d\n",
+ rprintf(FINFO,"send_files mapped %s of size %d\n",
fname,(int)st.st_size);
write_int(f_out,i);
write_int(f_out,s->remainder);
if (verbose > 2)
- fprintf(FINFO,"calling match_sums %s\n",fname);
+ rprintf(FINFO,"calling match_sums %s\n",fname);
if (!am_server && verbose)
printf("%s\n",fname+offset);
free_sums(s);
if (verbose > 2)
- fprintf(FINFO,"sender finished %s\n",fname);
+ rprintf(FINFO,"sender finished %s\n",fname);
}
if (verbose > 2)
- fprintf(FINFO,"send files finished\n");
+ rprintf(FINFO,"send files finished\n");
match_report();
int phase=0;
if (verbose > 2)
- fprintf(FINFO,"generator starting pid=%d count=%d\n",
+ rprintf(FINFO,"generator starting pid=%d count=%d\n",
(int)getpid(),flist->count);
for (i = 0; i < flist->count; i++) {
ignore_times=1;
if (verbose > 2)
- fprintf(FINFO,"generate_files phase=%d\n",phase);
+ rprintf(FINFO,"generate_files phase=%d\n",phase);
write_int(f,-1);
write_flush(f);
phase++;
if (verbose > 2)
- fprintf(FINFO,"generate_files phase=%d\n",phase);
+ rprintf(FINFO,"generate_files phase=%d\n",phase);
write_int(f,-1);
write_flush(f);
if (verbose > 2)
- fprintf(FINFO,"generator wrote %ld\n",(long)write_total());
+ rprintf(FINFO,"generator wrote %ld\n",(long)write_total());
}
#define MIN_PROTOCOL_VERSION 11
#define MAX_PROTOCOL_VERSION 30
+#define RSYNC_PORT 873
+
#define SPARSE_WRITE_SIZE (1024)
#define WRITE_SIZE (32*1024)
#define CHUNK_SIZE (32*1024)
#define BLOCKING_TIMEOUT 10
-#define FERROR stderr
-#define FINFO (am_server?stderr:stdout)
+#define FERROR 1
+#define FINFO 2
#include "config.h"
#include <pwd.h>
#include <grp.h>
+#include <stdarg.h>
+
#ifndef S_IFLNK
#define S_IFLNK 0120000
#endif
tx_strm.zfree = z_free;
if (deflateInit2(&tx_strm, Z_DEFAULT_COMPRESSION, 8,
-15, 8, Z_DEFAULT_STRATEGY) != Z_OK) {
- fprintf(FERROR, "compression init failed\n");
+ rprintf(FERROR, "compression init failed\n");
exit_cleanup(1);
}
if ((obuf = malloc(MAX_DATA_COUNT+2)) == NULL)
}
r = deflate(&tx_strm, nb? Z_NO_FLUSH: Z_PACKET_FLUSH);
if (r != Z_OK) {
- fprintf(FERROR, "deflate returned %d\n", r);
+ rprintf(FERROR, "deflate returned %d\n", r);
exit_cleanup(1);
}
if (nb == 0 || tx_strm.avail_out == 0) {
tx_strm.avail_out = 2 * toklen;
r = deflate(&tx_strm, Z_INSERT_ONLY);
if (r != Z_OK || tx_strm.avail_in != 0) {
- fprintf(FERROR, "deflate on token returned %d (%d bytes left)\n",
+ rprintf(FERROR, "deflate on token returned %d (%d bytes left)\n",
r, tx_strm.avail_in);
exit_cleanup(1);
}
rx_strm.zalloc = z_alloc;
rx_strm.zfree = z_free;
if (inflateInit2(&rx_strm, -15) != Z_OK) {
- fprintf(FERROR, "inflate init failed\n");
+ rprintf(FERROR, "inflate init failed\n");
exit_cleanup(1);
}
if ((cbuf = malloc(MAX_DATA_COUNT)) == NULL
r = inflate(&rx_strm, Z_PACKET_FLUSH);
n = CHUNK_SIZE - rx_strm.avail_out;
if (r != Z_OK) {
- fprintf(FERROR, "inflate flush returned %d (%d bytes)\n",
+ rprintf(FERROR, "inflate flush returned %d (%d bytes)\n",
r, n);
exit_cleanup(1);
}
r = inflate(&rx_strm, Z_NO_FLUSH);
n = CHUNK_SIZE - rx_strm.avail_out;
if (r != Z_OK) {
- fprintf(FERROR, "inflate returned %d (%d bytes)\n", r, n);
+ rprintf(FERROR, "inflate returned %d (%d bytes)\n", r, n);
exit_cleanup(1);
}
if (rx_strm.avail_in == 0)
rx_strm.avail_in = len;
r = inflateIncomp(&rx_strm);
if (r != Z_OK) {
- fprintf(FERROR, "inflateIncomp returned %d\n", r);
+ rprintf(FERROR, "inflateIncomp returned %d\n", r);
exit_cleanup(1);
}
}
if (do_lseek(map->fd,offset,SEEK_SET) != offset ||
(nread=read(map->fd,map->p,len)) != len) {
- fprintf(FERROR,"EOF in map_ptr! (offset=%d len=%d nread=%d errno=%d)\n",
+ rprintf(FERROR,"EOF in map_ptr! (offset=%d len=%d nread=%d errno=%d)\n",
(int)offset, len, nread, errno);
exit_cleanup(1);
}
if (pipe(to_child_pipe) < 0 ||
pipe(from_child_pipe) < 0) {
- fprintf(FERROR,"pipe: %s\n",strerror(errno));
+ rprintf(FERROR,"pipe: %s\n",strerror(errno));
exit_cleanup(1);
}
pid = do_fork();
if (pid < 0) {
- fprintf(FERROR,"fork: %s\n",strerror(errno));
+ rprintf(FERROR,"fork: %s\n",strerror(errno));
exit_cleanup(1);
}
close(to_child_pipe[1]) < 0 ||
close(from_child_pipe[0]) < 0 ||
dup2(from_child_pipe[1], STDOUT_FILENO) < 0) {
- fprintf(FERROR,"Failed to dup/close : %s\n",strerror(errno));
+ rprintf(FERROR,"Failed to dup/close : %s\n",strerror(errno));
exit_cleanup(1);
}
if (to_child_pipe[0] != STDIN_FILENO) close(to_child_pipe[0]);
if (from_child_pipe[1] != STDOUT_FILENO) close(from_child_pipe[1]);
umask(orig_umask);
execvp(command[0], command);
- fprintf(FERROR,"Failed to exec %s : %s\n",
+ rprintf(FERROR,"Failed to exec %s : %s\n",
command[0],strerror(errno));
exit_cleanup(1);
}
if (close(from_child_pipe[1]) < 0 ||
close(to_child_pipe[0]) < 0) {
- fprintf(FERROR,"Failed to close : %s\n",strerror(errno));
+ rprintf(FERROR,"Failed to close : %s\n",strerror(errno));
exit_cleanup(1);
}
if (pipe(to_child_pipe) < 0 ||
pipe(from_child_pipe) < 0) {
- fprintf(FERROR,"pipe: %s\n",strerror(errno));
+ rprintf(FERROR,"pipe: %s\n",strerror(errno));
exit_cleanup(1);
}
pid = do_fork();
if (pid < 0) {
- fprintf(FERROR,"fork: %s\n",strerror(errno));
+ rprintf(FERROR,"fork: %s\n",strerror(errno));
exit_cleanup(1);
}
close(to_child_pipe[1]) < 0 ||
close(from_child_pipe[0]) < 0 ||
dup2(from_child_pipe[1], STDOUT_FILENO) < 0) {
- fprintf(FERROR,"Failed to dup/close : %s\n",strerror(errno));
+ rprintf(FERROR,"Failed to dup/close : %s\n",strerror(errno));
exit_cleanup(1);
}
if (to_child_pipe[0] != STDIN_FILENO) close(to_child_pipe[0]);
if (from_child_pipe[1] != STDOUT_FILENO) close(from_child_pipe[1]);
- start_server(argc, argv);
+ start_server(STDIN_FILENO, STDOUT_FILENO, argc, argv);
}
if (close(from_child_pipe[1]) < 0 ||
close(to_child_pipe[0]) < 0) {
- fprintf(FERROR,"Failed to close : %s\n",strerror(errno));
+ rprintf(FERROR,"Failed to close : %s\n",strerror(errno));
exit_cleanup(1);
}
void out_of_memory(char *str)
{
- fprintf(FERROR,"ERROR: out of memory in %s\n",str);
+ rprintf(FERROR,"ERROR: out of memory in %s\n",str);
exit_cleanup(1);
}
void overflow(char *str)
{
- fprintf(FERROR,"ERROR: buffer overflow in %s\n",str);
+ rprintf(FERROR,"ERROR: buffer overflow in %s\n",str);
exit_cleanup(1);
}
ifd = open(source, O_RDONLY);
if (ifd == -1) {
- fprintf(FERROR,"open %s: %s\n",
+ rprintf(FERROR,"open %s: %s\n",
source,strerror(errno));
return -1;
}
if (do_unlink(dest) && errno != ENOENT) {
- fprintf(FERROR,"unlink %s: %s\n",
+ rprintf(FERROR,"unlink %s: %s\n",
dest,strerror(errno));
return -1;
}
ofd = do_open(dest, O_WRONLY | O_CREAT | O_TRUNC | O_EXCL, mode);
if (ofd < 0) {
- fprintf(FERROR,"open %s: %s\n",
+ rprintf(FERROR,"open %s: %s\n",
dest,strerror(errno));
close(ifd);
return -1;
while ((len = safe_read(ifd, buf, sizeof(buf))) > 0) {
if (full_write(ofd, buf, len) < 0) {
- fprintf(FERROR,"write %s: %s\n",
+ rprintf(FERROR,"write %s: %s\n",
dest,strerror(errno));
close(ifd);
close(ofd);
close(ofd);
if (len < 0) {
- fprintf(FERROR,"read %s: %s\n",
+ rprintf(FERROR,"read %s: %s\n",
source,strerror(errno));
return -1;
}
kill(all_pids[i], sig);
}
}
+
+/* this is the rsync debugging function. Call it with FINFO or FERROR */
+void rprintf(int fd, const char *format, ...)
+{
+ va_list ap;
+ char buf[1024];
+ int len;
+ FILE *f=NULL;
+
+ va_start(ap, format);
+
+#if HAVE_VSNPRINTF
+ len = vsnprintf(buf, sizeof(buf)-1, format, ap);
+#else
+ len = vsprintf(buf, format, ap);
+#endif
+ va_end(ap);
+
+ if (len < 0) exit_cleanup(1);
+
+ if (fd == FERROR) {
+ f = stderr;
+ }
+
+ if (fd == FINFO) {
+ extern int am_server;
+ if (am_server)
+ f = stderr;
+ else
+ f = stdout;
+ }
+
+ if (!f) exit_cleanup(1);
+
+ if (fwrite(buf, len, 1, f) != 1) exit_cleanup(1);
+}
+
+void rflush(int fd)
+{
+ FILE *f = NULL;
+
+ if (fd == FERROR) {
+ f = stderr;
+ }
+
+ if (fd == FINFO) {
+ extern int am_server;
+ if (am_server)
+ f = stderr;
+ else
+ f = stdout;
+ }
+
+ if (!f) exit_cleanup(1);
+ fflush(f);
+}