Matt McCutchen's Web Site
/
rsync
/
rsync.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
in local->local mode don't use exec to start the "remote" rsync,
[rsync/rsync.git]
/
main.c
diff --git
a/main.c
b/main.c
index
ec40818
..
41d8a6b
100644
(file)
--- a/
main.c
+++ b/
main.c
@@
-22,7
+22,7
@@
int verbose = 0;
int always_checksum = 0;
time_t starttime;
int verbose = 0;
int always_checksum = 0;
time_t starttime;
-
off_t
total_size = 0;
+
int64
total_size = 0;
int block_size=BLOCK_SIZE;
char *backup_suffix = BACKUP_SUFFIX;
int block_size=BLOCK_SIZE;
char *backup_suffix = BACKUP_SUFFIX;
@@
-54,23
+54,26
@@
int am_root=0;
int orig_umask=0;
int relative_paths=0;
int numeric_ids = 0;
int orig_umask=0;
int relative_paths=0;
int numeric_ids = 0;
+int force_delete = 0;
+int io_timeout = 0;
+int io_error = 0;
extern int csum_length;
int am_server = 0;
extern int csum_length;
int am_server = 0;
-
static int
sender;
+
int am_
sender;
int recurse = 0;
static void usage(FILE *f);
static void report(int f)
{
int recurse = 0;
static void usage(FILE *f);
static void report(int f)
{
-
off_t
in,out,tsize;
+
int64
in,out,tsize;
time_t t = time(NULL);
if (!verbose) return;
time_t t = time(NULL);
if (!verbose) return;
- if (am_server && sender) {
+ if (am_server &&
am_
sender) {
write_longint(f,read_total());
write_longint(f,write_total());
write_longint(f,total_size);
write_longint(f,read_total());
write_longint(f,write_total());
write_longint(f,total_size);
@@
-78,7
+81,7
@@
static void report(int f)
return;
}
return;
}
- if (sender) {
+ if (
am_
sender) {
in = read_total();
out = write_total();
tsize = total_size;
in = read_total();
out = write_total();
tsize = total_size;
@@
-107,11
+110,12
@@
static void server_options(char **args,int *argc)
int ac = *argc;
static char argstr[50];
static char bsize[30];
int ac = *argc;
static char argstr[50];
static char bsize[30];
+ static char iotime[30];
int i, x;
args[ac++] = "--server";
int i, x;
args[ac++] = "--server";
- if (!sender)
+ if (!
am_
sender)
args[ac++] = "--sender";
x = 1;
args[ac++] = "--sender";
x = 1;
@@
-167,6
+171,11
@@
static void server_options(char **args,int *argc)
args[ac++] = bsize;
}
args[ac++] = bsize;
}
+ if (io_timeout) {
+ sprintf(iotime,"--timeout=%d",io_timeout);
+ args[ac++] = iotime;
+ }
+
if (strcmp(backup_suffix, BACKUP_SUFFIX)) {
args[ac++] = "--suffix";
args[ac++] = backup_suffix;
if (strcmp(backup_suffix, BACKUP_SUFFIX)) {
args[ac++] = "--suffix";
args[ac++] = backup_suffix;
@@
-175,6
+184,9
@@
static void server_options(char **args,int *argc)
if (delete_mode)
args[ac++] = "--delete";
if (delete_mode)
args[ac++] = "--delete";
+ if (force_delete)
+ args[ac++] = "--force";
+
if (numeric_ids)
args[ac++] = "--numeric-ids";
if (numeric_ids)
args[ac++] = "--numeric-ids";
@@
-190,65
+202,70
@@
static void server_options(char **args,int *argc)
static int do_cmd(char *cmd,char *machine,char *user,char *path,int *f_in,int *f_out)
{
static int do_cmd(char *cmd,char *machine,char *user,char *path,int *f_in,int *f_out)
{
- char *args[100];
- int i,argc=0, ret;
-
char *tok,*p
,*dir=NULL;
-
- if (!local_server) {
- if (!cmd)
- cmd = getenv(RSYNC_RSH_ENV);
- if (!cmd)
- cmd = RSYNC_RSH;
- cmd = strdup(cmd);
- if (!cmd)
- goto oom;
-
- for (tok=strtok(cmd," ");tok;tok=strtok(NULL," ")) {
- args[argc++] = tok;
- }
+
char *args[100];
+
int i,argc=0, ret;
+
char *tok
,*dir=NULL;
+
+
if (!local_server) {
+
if (!cmd)
+
cmd = getenv(RSYNC_RSH_ENV);
+
if (!cmd)
+
cmd = RSYNC_RSH;
+
cmd = strdup(cmd);
+
if (!cmd)
+
goto oom;
+
+
for (tok=strtok(cmd," ");tok;tok=strtok(NULL," ")) {
+
args[argc++] = tok;
+
}
#if HAVE_REMSH
#if HAVE_REMSH
- /* remsh (on HPUX) takes the arguments the other way around */
- args[argc++] = machine;
- if (user) {
- args[argc++] = "-l";
- args[argc++] = user;
- }
+
/* remsh (on HPUX) takes the arguments the other way around */
+
args[argc++] = machine;
+
if (user) {
+
args[argc++] = "-l";
+
args[argc++] = user;
+
}
#else
#else
- if (user) {
- args[argc++] = "-l";
- args[argc++] = user;
- }
- args[argc++] = machine;
+
if (user) {
+
args[argc++] = "-l";
+
args[argc++] = user;
+
}
+
args[argc++] = machine;
#endif
#endif
- }
- args[argc++] = rsync_path;
+
args[argc++] = rsync_path;
- server_options(args,&argc);
+ server_options(args,&argc);
+ }
- args[argc++] = ".";
+
args[argc++] = ".";
- if (path && *path)
- args[argc++] = path;
+
if (path && *path)
+
args[argc++] = path;
- args[argc] = NULL;
+
args[argc] = NULL;
- if (verbose > 3) {
- fprintf(FERROR,"cmd=");
- for (i=0;i<argc;i++)
- fprintf(FERROR,"%s ",args[i]);
- fprintf(FERROR,"\n");
- }
+ if (verbose > 3) {
+ fprintf(FINFO,"cmd=");
+ for (i=0;i<argc;i++)
+ fprintf(FINFO,"%s ",args[i]);
+ fprintf(FINFO,"\n");
+ }
+
+ if (local_server) {
+ ret = local_child(argc, args, f_in, f_out);
+ } else {
+ ret = piped_child(args,f_in,f_out);
+ }
- ret = piped_child(args,f_in,f_out);
- if (dir) free(dir);
+ if (dir) free(dir);
- return ret;
+
return ret;
oom:
oom:
- out_of_memory("do_cmd");
- return 0; /* not reached */
+
out_of_memory("do_cmd");
+
return 0; /* not reached */
}
}
@@
-304,7
+321,7
@@
void do_server_sender(int argc,char *argv[])
char *dir = argv[0];
if (verbose > 2)
char *dir = argv[0];
if (verbose > 2)
- fprintf(F
ERROR
,"server_sender starting pid=%d\n",(int)getpid());
+ fprintf(F
INFO
,"server_sender starting pid=%d\n",(int)getpid());
if (!relative_paths && chdir(dir) != 0) {
fprintf(FERROR,"chdir %s: %s (3)\n",dir,strerror(errno));
if (!relative_paths && chdir(dir) != 0) {
fprintf(FERROR,"chdir %s: %s (3)\n",dir,strerror(errno));
@@
-353,7
+370,7
@@
static int do_recv(int f_in,int f_out,struct file_list *flist,char *local_name)
if ((pid=do_fork()) == 0) {
recv_files(f_in,flist,local_name,recv_pipe[1]);
if (verbose > 2)
if ((pid=do_fork()) == 0) {
recv_files(f_in,flist,local_name,recv_pipe[1]);
if (verbose > 2)
- fprintf(F
ERROR
,"receiver read %ld\n",(long)read_total());
+ fprintf(F
INFO
,"receiver read %ld\n",(long)read_total());
exit_cleanup(0);
}
exit_cleanup(0);
}
@@
-373,7
+390,7
@@
void do_server_recv(int argc,char *argv[])
char *dir = NULL;
if (verbose > 2)
char *dir = NULL;
if (verbose > 2)
- fprintf(F
ERROR
,"server_recv(%d) starting pid=%d\n",argc,(int)getpid());
+ fprintf(F
INFO
,"server_recv(%d) starting pid=%d\n",argc,(int)getpid());
if (argc > 0) {
dir = argv[0];
if (argc > 0) {
dir = argv[0];
@@
-408,6
+425,22
@@
void do_server_recv(int argc,char *argv[])
}
}
+void start_server(int argc, char *argv[])
+{
+ setup_protocol(STDOUT_FILENO,STDIN_FILENO);
+
+ if (am_sender) {
+ recv_exclude_list(STDIN_FILENO);
+ if (cvs_exclude)
+ add_cvs_excludes();
+ do_server_sender(argc,argv);
+ } else {
+ do_server_recv(argc,argv);
+ }
+ exit_cleanup(0);
+}
+
+
static void usage(FILE *f)
{
fprintf(f,"rsync version %s Copyright Andrew Tridgell and Paul Mackerras\n\n",
static void usage(FILE *f)
{
fprintf(f,"rsync version %s Copyright Andrew Tridgell and Paul Mackerras\n\n",
@@
-439,7
+472,9
@@
static void usage(FILE *f)
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," --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," --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,"-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");
@@
-454,7
+489,8
@@
static void usage(FILE *f)
}
enum {OPT_VERSION,OPT_SUFFIX,OPT_SENDER,OPT_SERVER,OPT_EXCLUDE,
}
enum {OPT_VERSION,OPT_SUFFIX,OPT_SENDER,OPT_SERVER,OPT_EXCLUDE,
- OPT_EXCLUDE_FROM,OPT_DELETE,OPT_NUMERIC_IDS,OPT_RSYNC_PATH};
+ OPT_EXCLUDE_FROM,OPT_DELETE,OPT_NUMERIC_IDS,OPT_RSYNC_PATH,
+ OPT_FORCE,OPT_TIMEOUT};
static char *short_options = "oblLWHpguDCtcahvrRIxnSe:B:T:z";
static char *short_options = "oblLWHpguDCtcahvrRIxnSe:B:T:z";
@@
-463,6
+499,7
@@
static struct option long_options[] = {
{"server", 0, 0, OPT_SERVER},
{"sender", 0, 0, OPT_SENDER},
{"delete", 0, 0, OPT_DELETE},
{"server", 0, 0, OPT_SERVER},
{"sender", 0, 0, OPT_SENDER},
{"delete", 0, 0, OPT_DELETE},
+ {"force", 0, 0, OPT_FORCE},
{"numeric-ids", 0, 0, OPT_NUMERIC_IDS},
{"exclude", 1, 0, OPT_EXCLUDE},
{"exclude-from",1, 0, OPT_EXCLUDE_FROM},
{"numeric-ids", 0, 0, OPT_NUMERIC_IDS},
{"exclude", 1, 0, OPT_EXCLUDE},
{"exclude-from",1, 0, OPT_EXCLUDE_FROM},
@@
-492,6
+529,7
@@
static struct option long_options[] = {
{"rsh", 1, 0, 'e'},
{"suffix", 1, 0, OPT_SUFFIX},
{"block-size", 1, 0, 'B'},
{"rsh", 1, 0, 'e'},
{"suffix", 1, 0, OPT_SUFFIX},
{"block-size", 1, 0, 'B'},
+ {"timeout", 1, 0, OPT_TIMEOUT},
{"temp-dir", 1, 0, 'T'},
{"compress", 0, 0, 'z'},
{0,0,0,0}};
{"temp-dir", 1, 0, 'T'},
{"compress", 0, 0, 'z'},
{0,0,0,0}};
@@
-553,6
+591,10
@@
int main(int argc,char *argv[])
delete_mode = 1;
break;
delete_mode = 1;
break;
+ case OPT_FORCE:
+ force_delete = 1;
+ break;
+
case OPT_NUMERIC_IDS:
numeric_ids = 1;
break;
case OPT_NUMERIC_IDS:
numeric_ids = 1;
break;
@@
-661,7
+703,7
@@
int main(int argc,char *argv[])
usage(FERROR);
exit_cleanup(1);
}
usage(FERROR);
exit_cleanup(1);
}
- sender = 1;
+
am_
sender = 1;
break;
case 'r':
break;
case 'r':
@@
-680,6
+722,10
@@
int main(int argc,char *argv[])
block_size = atoi(optarg);
break;
block_size = atoi(optarg);
break;
+ case OPT_TIMEOUT:
+ io_timeout = atoi(optarg);
+ break;
+
case 'T':
tmpdir = optarg;
break;
case 'T':
tmpdir = optarg;
break;
@@
-715,17
+761,7
@@
int main(int argc,char *argv[])
#endif
if (am_server) {
#endif
if (am_server) {
- setup_protocol(STDOUT_FILENO,STDIN_FILENO);
-
- if (sender) {
- recv_exclude_list(STDIN_FILENO);
- if (cvs_exclude)
- add_cvs_excludes();
- do_server_sender(argc,argv);
- } else {
- do_server_recv(argc,argv);
- }
- exit_cleanup(0);
+ start_server(argc, argv);
}
if (argc < 2) {
}
if (argc < 2) {
@@
-736,14
+772,14
@@
int main(int argc,char *argv[])
p = strchr(argv[0],':');
if (p) {
p = strchr(argv[0],':');
if (p) {
- sender = 0;
+
am_
sender = 0;
*p = 0;
shell_machine = argv[0];
shell_path = p+1;
argc--;
argv++;
} else {
*p = 0;
shell_machine = argv[0];
shell_path = p+1;
argc--;
argv++;
} else {
- sender = 1;
+
am_
sender = 1;
p = strchr(argv[argc-1],':');
if (!p) {
p = strchr(argv[argc-1],':');
if (!p) {
@@
-771,14
+807,14
@@
int main(int argc,char *argv[])
}
if (verbose > 3) {
}
if (verbose > 3) {
- fprintf(F
ERROR
,"cmd=%s machine=%s user=%s path=%s\n",
+ fprintf(F
INFO
,"cmd=%s machine=%s user=%s path=%s\n",
shell_cmd?shell_cmd:"",
shell_machine?shell_machine:"",
shell_user?shell_user:"",
shell_path?shell_path:"");
}
shell_cmd?shell_cmd:"",
shell_machine?shell_machine:"",
shell_user?shell_user:"",
shell_path?shell_path:"");
}
- if (!sender && argc != 1) {
+ if (!
am_
sender && argc != 1) {
usage(FERROR);
exit_cleanup(1);
}
usage(FERROR);
exit_cleanup(1);
}
@@
-793,20
+829,20
@@
int main(int argc,char *argv[])
#endif
if (verbose > 3)
#endif
if (verbose > 3)
- fprintf(F
ERROR
,"parent=%d child=%d sender=%d recurse=%d\n",
- (int)getpid(),pid,sender,recurse);
+ fprintf(F
INFO
,"parent=%d child=%d sender=%d recurse=%d\n",
+ (int)getpid(),pid,
am_
sender,recurse);
- if (sender) {
+ 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)
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(F
ERROR
,"file list sent\n");
+ fprintf(F
INFO
,"file list sent\n");
send_files(flist,f_out,f_in);
if (verbose > 3)
send_files(flist,f_out,f_in);
if (verbose > 3)
- fprintf(F
ERROR
,"waiting on %d\n",pid);
+ fprintf(F
INFO
,"waiting on %d\n",pid);
waitpid(pid, &status, 0);
report(-1);
exit_cleanup(status);
waitpid(pid, &status, 0);
report(-1);
exit_cleanup(status);
@@
-816,7
+852,7
@@
int main(int argc,char *argv[])
flist = recv_file_list(f_in);
if (!flist || flist->count == 0) {
flist = recv_file_list(f_in);
if (!flist || flist->count == 0) {
- fprintf(F
ERROR
,"nothing to do\n");
+ fprintf(F
INFO
,"nothing to do\n");
exit_cleanup(0);
}
exit_cleanup(0);
}