about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2023-10-10 17:16:53 -0400
committerJune McEnroe <june@causal.agency>2023-10-10 17:16:53 -0400
commit9d864e5526d39ef974557c9b406bc3ada03ed4c1 (patch)
tree115fef03a2dbd425e7da3b3e2feaa38beca14c04
parentParse interval suffixes (diff)
downloadkitd-9d864e5526d39ef974557c9b406bc3ada03ed4c1.tar.gz
kitd-9d864e5526d39ef974557c9b406bc3ada03ed4c1.zip
Add maximum restart interval HEAD 1.0 main
-rw-r--r--kitd.810
-rw-r--r--kitd.c8
2 files changed, 16 insertions, 2 deletions
diff --git a/kitd.8 b/kitd.8
index 4bce90b..54a9fa3 100644
--- a/kitd.8
+++ b/kitd.8
@@ -10,6 +10,7 @@
 .Nm
 .Op Fl d
 .Op Fl c Ar cooloff
+.Op Fl m Ar maximum
 .Op Fl n Ar name
 .Op Fl t Ar restart
 .Ar command ...
@@ -51,6 +52,13 @@ Do not daemonize.
 Log to standard error
 as well as
 .Xr syslog 3 .
+.It Fl m Ar maximum
+The maximum interval between restarts.
+.Pp
+The interval is interpreted as with
+.Fl c .
+The default maximum interval is
+.Sy 1h .
 .It Fl n Ar name
 Set the name of the process
 and the logging prefix.
@@ -58,7 +66,7 @@ The default is
 the last path component of
 .Ar command .
 .It Fl t Ar restart
-The initial interval between automatic restarts.
+The initial interval between restarts.
 This interval is doubled
 each time the child process
 is restarted.
diff --git a/kitd.c b/kitd.c
index d76cac1..261f9eb 100644
--- a/kitd.c
+++ b/kitd.c
@@ -107,10 +107,12 @@ int main(int argc, char *argv[]) {
 	const char *name = NULL;
 	struct timeval restart = { .tv_sec = 1 };
 	struct timeval cooloff = { .tv_sec = 15*M };
-	for (int opt; 0 < (opt = getopt(argc, argv, "c:dn:t:"));) {
+	struct timeval maximum = { .tv_sec = 1*H };
+	for (int opt; 0 < (opt = getopt(argc, argv, "c:dm:n:t:"));) {
 		switch (opt) {
 			break; case 'c': parse(&cooloff, optarg);
 			break; case 'd': daemonize = false;
+			break; case 'm': parse(&maximum, optarg);
 			break; case 'n': name = optarg;
 			break; case 't': parse(&restart, optarg);
 			break; default: return 1;
@@ -257,7 +259,11 @@ int main(int argc, char *argv[]) {
 			syslog(LOG_INFO, "restarting in %s", humanize(&interval));
 			struct itimerval timer = { .it_value = interval };
 			setitimer(ITIMER_REAL, &timer, NULL);
+
 			timeradd(&interval, &interval, &interval);
+			if (timercmp(&interval, &maximum, >)) {
+				interval = maximum;
+			}
 		}
 
 		if (signals[SIGINFO]) {
f='/cgit-pink/commit/cgit.c?h=1.4.0&id=c96becc1e5ebff9e6609e61e11e80debcb3a778c&follow=1'>cgit.c: Fix comment on bit mask hackLukas Fleischer * Formatting and spelling fixes. * A bit mask with the size of one byte only allows for storing 8 (not 255!) different flags. Signed-off-by: Lukas Fleischer <cgit@cryptocrack.de> 2014-01-10cgit.c: Use "else" for mutually exclusive branchesLukas Fleischer When parsing command line arguments, no pair of command line options can ever match simultaneously. Use "else if" blocks to reflect this. This change improves both readability and speed. Signed-off-by: Lukas Fleischer <cgit@cryptocrack.de> 2014-01-10ui-snapshot.c: Do not reinvent suffixcmp()Lukas Fleischer Use suffixcmp() from Git instead of reimplementing it. This is a preparation for moving to ends_with() in Git 1.8.6. Signed-off-by: Lukas Fleischer <cgit@cryptocrack.de> 2014-01-10Refactor cgit_parse_snapshots_mask()Lukas Fleischer Use Git string lists instead of str{spn,cspn,ncmp}() magic. This significantly improves readability. Signed-off-by: Lukas Fleischer <cgit@cryptocrack.de> 2014-01-10Disallow use of undocumented snapshot delimitersLukas Fleischer Since the introduction of selective snapshot format configuration in dc3c9b5 (allow selective enabling of snapshots, 2007-07-21), we allowed seven different delimiters for snapshot formats, while the documentation has always been clear about spaces being the only valid delimiter: The value is a space-separated list of zero or more of the values "tar", "tar.gz", "tar.bz2", "tar.xz" and "zip". Supporting the undocumented delimiters makes the code unnecessarily complex. Remove them. Signed-off-by: Lukas Fleischer <cgit@cryptocrack.de> 2014-01-10Replace most uses of strncmp() with prefixcmp()Lukas Fleischer This is a preparation for replacing all prefix checks with either strip_prefix() or starts_with() when Git 1.8.6 is released. Signed-off-by: Lukas Fleischer <cgit@cryptocrack.de> 2014-01-09README: Fix dependenciesLukas Fleischer * Remove the dependency on Git (which can be obtained automatically when building, using either the Git submodule or `make get-git`). * Use proper upstream names of dependencies. Signed-off-by: Lukas Fleischer <cgit@cryptocrack.de> 2014-01-08README: Spelling and formatting fixesLukas Fleischer * Several small spelling and capitalization fixes. * Use consistent and better-looking formatting that is compatible with AsciiDoc (and partly compatible with RST). Signed-off-by: Lukas Fleischer <cgit@cryptocrack.de> 2014-01-08Fix UTF-8 with syntax-highlighting.pyPřemysl Janouch Previously the script tried to encode output from Pygments with the ASCII codec, which failed. Signed-off-by: Přemysl Janouch <p.janouch@gmail.com> 2014-01-08Add a suggestion to the manpagePřemysl Janouch So that people wishing to use "enable-http-clone" don't have to find out the correct settings on their own. Signed-off-by: Přemysl Janouch <p.janouch@gmail.com> 2014-01-08Fix the example configurationPřemysl Janouch "enable-git-clone" doesn't exist, replaced with "enable-http-clone". Signed-off-by: Přemysl Janouch <p.janouch@gmail.com> 2014-01-08Fix about-formatting.shPřemysl Janouch dash failed to parse the script. Signed-off-by: Přemysl Janouch <p.janouch@gmail.com> 2014-01-08Fix some spelling errorsPřemysl Janouch Signed-off-by: Přemysl Janouch <p.janouch@gmail.com> 2014-01-08filters: highlight.sh: add css comments for highlight 2.6 and 3.8Ferry Huberts