1 John Taylor's patch for implementing --time-limit and --stop-at, reworked
2 to be simpler and more efficient by Wayne Davison.
4 Do we need configure support for mktime() and strptime()?
6 --- io.c 16 Jan 2004 16:31:47 -0000 1.119
7 +++ io.c 27 Apr 2004 02:56:33 -0000
8 @@ -44,6 +44,7 @@ static int io_multiplexing_in;
9 static int multiplex_in_fd = -1;
10 static int multiplex_out_fd = -1;
11 static time_t last_io;
12 +extern time_t stop_at_utime;
16 @@ -125,15 +126,20 @@ static void check_timeout(void)
21 + if (!io_timeout && !stop_at_utime)
26 + if (stop_at_utime && t >= stop_at_utime) {
27 + rprintf(FERROR, "run-time limit exceeded\n");
28 + exit_cleanup(RERR_TIMEOUT);
32 - last_io = time(NULL);
39 if (last_io && io_timeout && (t-last_io) >= io_timeout) {
40 if (!am_server && !am_daemon) {
41 --- options.c 17 Apr 2004 17:07:23 -0000 1.147
42 +++ options.c 27 Apr 2004 02:56:33 -0000
43 @@ -92,6 +92,7 @@ int modify_window = 0;
45 int checksum_seed = 0;
46 unsigned int block_size = 0;
47 +time_t stop_at_utime = 0;
50 /** Network address family. **/
51 @@ -288,6 +289,8 @@ void usage(enum logcode F)
52 rprintf(F," --log-format=FORMAT log file transfers using specified format\n");
53 rprintf(F," --password-file=FILE get password from FILE\n");
54 rprintf(F," --bwlimit=KBPS limit I/O bandwidth, KBytes per second\n");
55 + rprintf(F," --stop-at=YY-MM-DD@HH:MM Stop rsync at year-month-day@hour:minute\n");
56 + rprintf(F," --time-limit=TIME Stop rsync after TIME minutes have elapsed\n");
57 rprintf(F," --write-batch=PREFIX write batch fileset starting with PREFIX\n");
58 rprintf(F," --read-batch=PREFIX read batch fileset starting with PREFIX\n");
59 rprintf(F," -h, --help show this help screen\n");
60 @@ -305,7 +308,7 @@ void usage(enum logcode F)
61 enum {OPT_VERSION = 1000, OPT_SENDER, OPT_EXCLUDE, OPT_EXCLUDE_FROM,
62 OPT_DELETE_AFTER, OPT_DELETE_EXCLUDED, OPT_LINK_DEST,
63 OPT_INCLUDE, OPT_INCLUDE_FROM, OPT_MODIFY_WINDOW,
64 - OPT_READ_BATCH, OPT_WRITE_BATCH,
65 + OPT_READ_BATCH, OPT_WRITE_BATCH, OPT_STOP_AT, OPT_TIME_LIMIT,
66 OPT_REFUSED_BASE = 9000};
68 static struct poptOption long_options[] = {
69 @@ -377,6 +380,8 @@ static struct poptOption long_options[]
70 {"port", 0, POPT_ARG_INT, &rsync_port, 0, 0, 0 },
71 {"log-format", 0, POPT_ARG_STRING, &log_format, 0, 0, 0 },
72 {"bwlimit", 0, POPT_ARG_INT, &bwlimit, 0, 0, 0 },
73 + {"stop-at", 0, POPT_ARG_STRING, 0, OPT_STOP_AT, 0, 0 },
74 + {"time-limit", 0, POPT_ARG_STRING, 0, OPT_TIME_LIMIT, 0, 0 },
75 {"address", 0, POPT_ARG_STRING, &bind_address, 0, 0, 0 },
76 {"backup-dir", 0, POPT_ARG_STRING, &backup_dir, 0, 0, 0 },
77 {"hard-links", 'H', POPT_ARG_NONE, &preserve_hard_links, 0, 0, 0 },
78 @@ -471,6 +476,7 @@ int parse_arguments(int *argc, const cha
81 char *ref = lp_refuse_options(module_id);
82 + struct tm stop_at_tm;
86 @@ -584,6 +590,37 @@ int parse_arguments(int *argc, const cha
91 + arg = poptGetOptArg(pc);
92 + if (!strptime(arg, "%y-%m-%d@%H:%M", &stop_at_tm)) {
93 + snprintf(err_buf, sizeof err_buf,
94 + "invalid --stop-at format: %s\n",
96 + rprintf(FERROR, "ERROR: %s", err_buf);
99 + stop_at_utime = mktime(&stop_at_tm);
100 + if (stop_at_utime < time(NULL)) {
101 + snprintf(err_buf, sizeof err_buf,
102 + "--stop-at time is in the past: %s\n",
104 + rprintf(FERROR, "ERROR: %s", err_buf);
109 + case OPT_TIME_LIMIT:
110 + arg = poptGetOptArg(pc);
111 + if ((stop_at_utime = atol(arg) * 60) <= 0) {
112 + snprintf(err_buf, sizeof err_buf,
113 + "invalid --time-limit value: %s\n",
115 + rprintf(FERROR, "ERROR: %s", err_buf);
118 + stop_at_utime += time(NULL);
122 /* A large opt value means that set_refuse_options()
123 * turned this option off (opt-BASE is its index). */
124 @@ -881,6 +918,15 @@ void server_options(char **args,int *arg
127 if (asprintf(&arg, "--bwlimit=%d", bwlimit) < 0)
132 + if (stop_at_utime) {
133 + long mins = (stop_at_utime - time(NULL)) / 60;
136 + if (asprintf(&arg, "--time-limit=%ld", mins) < 0)
140 --- rsync.yo 24 Apr 2004 06:16:04 -0000 1.164
141 +++ rsync.yo 27 Apr 2004 02:56:35 -0000
142 @@ -346,6 +346,8 @@ verb(
143 --log-format=FORMAT log file transfers using specified format
144 --password-file=FILE get password from FILE
145 --bwlimit=KBPS limit I/O bandwidth, KBytes per second
146 + --stop-at=YY-MM-DD@HH:MM Stop rsync at year-month-day@hour:minute
147 + --time-limit=TIME Stop rsync after TIME minutes have elapsed
148 --write-batch=PREFIX write batch fileset starting with PREFIX
149 --read-batch=PREFIX read batch fileset starting with PREFIX
150 -h, --help show this help screen
151 @@ -888,6 +890,13 @@ of rsync transfers, blocks of data are s
152 transfer was too fast, it will wait before sending the next data block. The
153 result is an average transfer rate equaling the specified limit. A value
154 of zero specifies no limit.
156 +dit(bf(--stop-at=YY-MM-DD@HH:MM)) This option allows you to specify at what
157 +time to stop rsync, in year-month-day@hour:minute numeric format (e.g.
160 +dit(bf(--time-limit=TIME)) This option allows you to specify the maximum
161 +number of minutes rsync will run for.
163 dit(bf(--write-batch=PREFIX)) Generate a set of files that can be
164 transferred as a batch update. Each filename in the set starts with