From 9d864e5526d39ef974557c9b406bc3ada03ed4c1 Mon Sep 17 00:00:00 2001 From: June McEnroe Date: Tue, 10 Oct 2023 17:16:53 -0400 Subject: Add maximum restart interval --- kitd.8 | 10 +++++++++- 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]) { -- cgit 1.4.1 oot/bin/1sh/redir.h (unfollow)
Commit message (Collapse)Author
2020-06-08Remove reference to FreeBSD-specific libedit hackJune McEnroe
Newer versions of libedit have sane tab-complete now without FreeBSD's hacks, and in fact the hack is gone in FreeBSD-CURRENT. I'm still a little confused why binding this weird function is necessary at all, but at least it exists everywhere, I guess.
2020-06-08Prefix mandoc with exec in about-filterJune McEnroe
2020-06-07Remove mktemp options from mkbuiltins, mktokensJune McEnroe
Why even?
2020-06-07Cast z_stream fields to size_tJune McEnroe
In the version of zlib in OpenBSD, these fields are of type off_t, which is signed (why?), rather than uLong.
2020-06-07Call static_assert by _Static_assertJune McEnroe
OpenBSD doesn't #define static_assert in assert.h and _Static_assert is its real name I guess so why not?
2020-06-07Add OpenBSD to install.shJune McEnroe
Straightforward.
2020-06-03Add The Song of AchillesJune McEnroe
2020-06-01Allow redirecting input in everJune McEnroe
2020-05-31Add %c conversion to c scriptJune McEnroe
2020-05-31Add c script to READMEJune McEnroe
2020-05-31Add c scriptJune McEnroe
2020-05-31Update mdoc source URLsJune McEnroe
2020-05-26Remove unfinished PSF fontsJune McEnroe