diff options
author | June McEnroe <june@causal.agency> | 2023-10-10 17:16:53 -0400 |
---|---|---|
committer | June McEnroe <june@causal.agency> | 2023-10-10 17:16:53 -0400 |
commit | 9d864e5526d39ef974557c9b406bc3ada03ed4c1 (patch) | |
tree | 115fef03a2dbd425e7da3b3e2feaa38beca14c04 | |
parent | Parse interval suffixes (diff) | |
download | kitd-9d864e5526d39ef974557c9b406bc3ada03ed4c1.tar.gz kitd-9d864e5526d39ef974557c9b406bc3ada03ed4c1.zip |
-rw-r--r-- | kitd.8 | 10 | ||||
-rw-r--r-- | kitd.c | 8 |
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]) { |