New patch from John Taylor.
[rsync/rsync-patches.git] / time-limit.diff
CommitLineData
c70898d5
WD
1--- io.c 2004-01-16 11:31:47.000000000 -0500
2+++ io.c 2004-04-19 16:07:57.000000000 -0400
3@@ -47,6 +47,7 @@
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;
11@@ -759,6 +760,26 @@
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.
38@@ -837,6 +858,11 @@
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
50--- options.c 2004-04-17 13:07:23.000000000 -0400
51+++ options.c 2004-04-19 16:07:57.000000000 -0400
52@@ -83,6 +83,7 @@
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;
60@@ -288,6 +289,7 @@
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");
68@@ -377,6 +379,7 @@
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 },
76@@ -881,6 +884,12 @@
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 }
89--- proto.h 2004-04-14 19:33:30.000000000 -0400
90+++ proto.h 2004-04-19 16:07:57.000000000 -0400
91@@ -267,6 +267,7 @@
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);
99--- rsync.yo 17 Apr 2004 18:40:16 -0000 1.159
100+++ rsync.yo 19 Apr 2004 20:50:45 -0000
101@@ -346,6 +346,7 @@
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
109@@ -880,6 +881,10 @@
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
120--- util.c 2004-04-17 13:06:03.000000000 -0400
121+++ util.c 2004-04-19 16:07:57.000000000 -0400
122@@ -1050,6 +1050,21 @@
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