Commit | Line | Data |
---|---|---|
bd8bf8b1 | 1 | --- io.c 16 Jan 2004 16:31:47 -0000 1.119 |
103bcb1d | 2 | +++ io.c 24 Apr 2004 07:49:11 -0000 |
b0aa8860 | 3 | @@ -47,6 +47,7 @@ static time_t last_io; |
c70898d5 WD |
4 | static int no_flush; |
5 | ||
6 | extern int bwlimit; | |
7 | +extern int timelimit; | |
8 | extern int verbose; | |
9 | extern int io_timeout; | |
10 | extern int am_server; | |
b0aa8860 | 11 | @@ -759,6 +760,26 @@ static void sleep_for_bwlimit(int bytes_ |
c70898d5 WD |
12 | select(0, NULL, NULL, NULL, &tv); |
13 | } | |
14 | ||
15 | +/* | |
16 | + * When --timelimit is used, compare rsync_start_time and the current time | |
17 | + * and return 1 when the timelimit has been reached. | |
18 | + */ | |
19 | +static int has_timelimit_expired() | |
20 | +{ | |
21 | + struct timeval tv; | |
22 | + time_t start_time = 0; | |
23 | + time_t expiration_time = 0; | |
24 | + | |
25 | + assert(timelimit > 0); | |
26 | + | |
27 | + start_time = get_rsync_start_time(); | |
28 | + assert(start_time > 0); | |
29 | + | |
30 | + gettimeofday(&tv, NULL); | |
31 | + expiration_time = start_time + (timelimit * 60); | |
32 | + | |
33 | + return tv.tv_sec > expiration_time; | |
34 | +} | |
35 | ||
36 | /** | |
37 | * Write len bytes to the file descriptor @p fd. | |
b0aa8860 | 38 | @@ -837,6 +858,11 @@ static void writefd_unbuffered(int fd,ch |
c70898d5 WD |
39 | } |
40 | ||
41 | sleep_for_bwlimit(ret); | |
42 | + | |
43 | + if (timelimit && has_timelimit_expired()) { | |
44 | + rprintf(FERROR, RSYNC_NAME ": \n%d minute time limit exceeded.\n", timelimit); | |
45 | + exit_cleanup(RERR_PARTIAL); | |
46 | + } | |
47 | ||
48 | total += ret; | |
49 | ||
bd8bf8b1 | 50 | --- options.c 17 Apr 2004 17:07:23 -0000 1.147 |
103bcb1d | 51 | +++ options.c 24 Apr 2004 07:49:11 -0000 |
b0aa8860 | 52 | @@ -83,6 +83,7 @@ int safe_symlinks = 0; |
c70898d5 WD |
53 | int copy_unsafe_links = 0; |
54 | int size_only = 0; | |
55 | int bwlimit = 0; | |
56 | +int timelimit = 0; | |
57 | int delete_after = 0; | |
58 | int only_existing = 0; | |
59 | int opt_ignore_existing = 0; | |
b0aa8860 | 60 | @@ -288,6 +289,7 @@ void usage(enum logcode F) |
c70898d5 WD |
61 | rprintf(F," --log-format=FORMAT log file transfers using specified format\n"); |
62 | rprintf(F," --password-file=FILE get password from FILE\n"); | |
63 | rprintf(F," --bwlimit=KBPS limit I/O bandwidth, KBytes per second\n"); | |
64 | + rprintf(F," --timelimit=MINS Stop rsync after MINS minutes\n"); | |
65 | rprintf(F," --write-batch=PREFIX write batch fileset starting with PREFIX\n"); | |
66 | rprintf(F," --read-batch=PREFIX read batch fileset starting with PREFIX\n"); | |
67 | rprintf(F," -h, --help show this help screen\n"); | |
b0aa8860 | 68 | @@ -377,6 +379,7 @@ static struct poptOption long_options[] |
c70898d5 WD |
69 | {"port", 0, POPT_ARG_INT, &rsync_port, 0, 0, 0 }, |
70 | {"log-format", 0, POPT_ARG_STRING, &log_format, 0, 0, 0 }, | |
71 | {"bwlimit", 0, POPT_ARG_INT, &bwlimit, 0, 0, 0 }, | |
72 | + {"timelimit", 0, POPT_ARG_INT, &timelimit, 0, 0, 0 }, | |
73 | {"address", 0, POPT_ARG_STRING, &bind_address, 0, 0, 0 }, | |
74 | {"backup-dir", 0, POPT_ARG_STRING, &backup_dir, 0, 0, 0 }, | |
75 | {"hard-links", 'H', POPT_ARG_NONE, &preserve_hard_links, 0, 0, 0 }, | |
b0aa8860 | 76 | @@ -881,6 +884,12 @@ void server_options(char **args,int *arg |
c70898d5 WD |
77 | |
78 | if (bwlimit) { | |
79 | if (asprintf(&arg, "--bwlimit=%d", bwlimit) < 0) | |
80 | + goto oom; | |
81 | + args[ac++] = arg; | |
82 | + } | |
83 | + | |
84 | + if (timelimit) { | |
85 | + if (asprintf(&arg, "--timelimit=%d", timelimit) < 0) | |
86 | goto oom; | |
87 | args[ac++] = arg; | |
88 | } | |
bd8bf8b1 | 89 | --- proto.h 22 Apr 2004 09:58:09 -0000 1.189 |
103bcb1d | 90 | +++ proto.h 24 Apr 2004 07:49:11 -0000 |
b0aa8860 | 91 | @@ -266,6 +266,7 @@ int u_strcmp(const char *cs1, const char |
c70898d5 WD |
92 | int unsafe_symlink(const char *dest, const char *src); |
93 | char *timestring(time_t t); | |
94 | int msleep(int t); | |
95 | +time_t get_rsync_start_time(void); | |
96 | int cmp_modtime(time_t file1, time_t file2); | |
97 | int _Insure_trap_error(int a1, int a2, int a3, int a4, int a5, int a6); | |
98 | void *_new_array(unsigned int size, unsigned long num); | |
103bcb1d WD |
99 | --- rsync.yo 24 Apr 2004 06:16:04 -0000 1.164 |
100 | +++ rsync.yo 24 Apr 2004 07:49:12 -0000 | |
b0aa8860 | 101 | @@ -346,6 +346,7 @@ verb( |
c70898d5 WD |
102 | --log-format=FORMAT log file transfers using specified format |
103 | --password-file=FILE get password from FILE | |
104 | --bwlimit=KBPS limit I/O bandwidth, KBytes per second | |
105 | + --timelimit=MINS Stop rsync after MINS minutes | |
106 | --write-batch=PREFIX write batch fileset starting with PREFIX | |
107 | --read-batch=PREFIX read batch fileset starting with PREFIX | |
108 | -h, --help show this help screen | |
103bcb1d | 109 | @@ -888,6 +889,10 @@ of rsync transfers, blocks of data are s |
c70898d5 WD |
110 | transfer was too fast, it will wait before sending the next data block. The |
111 | result is an average transfer rate equaling the specified limit. A value | |
112 | of zero specifies no limit. | |
113 | + | |
114 | +dit(bf(--timelimit=MINS)) This option allows you to specify the maximum | |
115 | +number of minutes rsync will run for. Ths time starts when the first | |
116 | +file starts transferring. | |
117 | ||
118 | dit(bf(--write-batch=PREFIX)) Generate a set of files that can be | |
119 | transferred as a batch update. Each filename in the set starts with | |
bd8bf8b1 | 120 | --- util.c 22 Apr 2004 22:17:15 -0000 1.138 |
103bcb1d | 121 | +++ util.c 24 Apr 2004 07:49:12 -0000 |
b0aa8860 | 122 | @@ -1049,6 +1049,21 @@ int msleep(int t) |
c70898d5 WD |
123 | return True; |
124 | } | |
125 | ||
126 | +/** | |
127 | + * Return the time that rsync is started, used by --time-limit | |
128 | + */ | |
129 | +time_t get_rsync_start_time(void) | |
130 | +{ | |
131 | + static struct timeval tval; | |
132 | + static int has_set_rsync_start_time = 0; | |
133 | + | |
134 | + if (!has_set_rsync_start_time) { | |
135 | + gettimeofday(&tval, NULL); | |
136 | + has_set_rsync_start_time = 1; | |
137 | + } | |
138 | + | |
139 | + return tval.tv_sec; | |
140 | +} | |
141 | ||
142 | /** | |
143 | * Determine if two file modification times are equivalent (either |