From 04ca84acdabc55ce20cb03b5c4ca703ab0c14b4d Mon Sep 17 00:00:00 2001 From: "C. McEnroe" Date: Fri, 14 Aug 2020 17:44:27 -0400 Subject: Switch to timespec for timeouts Can be passed to ppoll(2) directly. --- daemon.c | 11 +++++++++-- daemon.h | 9 ++++----- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/daemon.c b/daemon.c index d0a6579..3dc0640 100644 --- a/daemon.c +++ b/daemon.c @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -43,7 +44,7 @@ #define WS " \t" -int restartInterval = 1000; +struct timespec restartInterval = { .tv_sec = 1 }; struct Set256 stopExits; static void configerr(bool exit, const char *format, ...) { @@ -119,6 +120,12 @@ static void parseExits(char *list) { } } +static void parseInterval(const char *millis) { + unsigned long ms = strtoul(millis, NULL, 10); + restartInterval.tv_sec = ms / 1000; + restartInterval.tv_nsec = 1000000 * (ms % 1000); +} + int main(int argc, char *argv[]) { setprogname(argv[0]); @@ -146,7 +153,7 @@ int main(int argc, char *argv[]) { break; case 'g': groupName = optarg; break; case 'p': pidPath = optarg; break; case 's': parseExits(optarg); - break; case 't': restartInterval = strtoul(optarg, NULL, 10); + break; case 't': parseInterval(optarg); break; case 'u': userName = optarg; break; default: return EX_USAGE; } diff --git a/daemon.h b/daemon.h index 09cda47..32827aa 100644 --- a/daemon.h +++ b/daemon.h @@ -19,7 +19,7 @@ #include #include #include -#include +#include #include typedef unsigned char byte; @@ -85,8 +85,8 @@ struct Service { int errPipe[2]; struct Line outLine; struct Line errLine; - int restartInterval; - struct timeval restartTime; + struct timespec restartInterval; + struct timespec restartDeadline; }; extern struct Services { @@ -100,8 +100,6 @@ void serviceStart(struct Service *service); extern char configError[]; int configParse(const char *path); -extern int restartInterval; - struct Set256 { uint32_t bits[8]; }; @@ -117,3 +115,4 @@ static inline uint32_t setTest(const struct Set256 *set, byte x) { enum { StopExit = 127 }; extern struct Set256 stopExits; +extern struct timespec restartInterval; -- cgit 1.4.1 msg=1'>unfollow)
Commit message (Collapse)Author
2020-03-09Fix copyright and rcsidJune McEnroe
2020-03-09Replace strchrnul with strchrJune McEnroe
2020-03-09Replace eaccess with faccessatJune McEnroe
2020-03-09Replace st_mtim with st_mtimespecJune McEnroe
2020-03-09Replace sys_nsig with NSIGJune McEnroe
2020-03-09Replace 1sh MakefileJune McEnroe
2020-03-09Rename manual pages to 1shJune McEnroe
2020-03-09Move bltin out of subdirectoryJune McEnroe
2020-03-09Import /usr/src/usr.bin/printf from FreeBSD 12.1-RELEASEJune McEnroe
2020-03-09Import /usr/src/bin/test from FreeBSD 12.1-RELEASEJune McEnroe
2020-03-09Import /usr/src/bin/kill from FreeBSD 12.1-RELEASEJune McEnroe
2020-03-09Remove extraneous files from sh sourcesJune McEnroe
2020-03-09Import /usr/src/bin/sh from FreeBSD 12.1-RELEASEJune McEnroe
2020-03-09Remove 1sh sourcesJune McEnroe
I'm going to recreate it from fresh sh sources for clean git history.
2020-03-08Add The Stone SkyJune McEnroe
2020-03-08Publish "How I Relay Chat"June McEnroe
2020-03-03Don't use $ inside $(())June McEnroe
2020-03-03Remove setoptJune McEnroe
2020-03-03Use getopts in shell scriptsJune McEnroe
WTF why did no one tell me about this?
2020-02-27Style %T outside of Rs in italicJune McEnroe
2020-02-26Add Fierce Femmes and Notorious LiarsJune McEnroe
2020-02-23Add This Is How You Lose the Time WarJune McEnroe
2020-02-22Add See Ya LaterJune McEnroe
2020-02-20Remove wiki scriptJune McEnroe
Wikipedia seems to have removed the one-sentence extracts from the opensearch results. Too bad. It's not a wiki script, what we need is a command that fetches single-sentence summaries of articles on Wikipedia.
2020-02-19Add The Obelisk GateJune McEnroe
2020-02-17Add Four Tet — HandsJune McEnroe
One from the cafe that caught my attention.
2020-02-12Simplify macOS notify-sendJune McEnroe
2020-02-12Add imbox and notemap to pageJune McEnroe
2020-02-12Collapse simple linksJune McEnroe
2020-02-12Move catgirl up the pageJune McEnroe
2020-02-12Update catgirl pty grabJune McEnroe
2020-02-12Link to cgit /about pages where appropriateJune McEnroe
2020-02-11Separate LINKS from BINS for html to workJune McEnroe
2020-02-11Add margin to Bl-bullet itemsJune McEnroe
2020-02-10Match URLs inside parens or with paired parens insideJune McEnroe
2020-02-10Duplicate effective URL before passing it back to curlJune McEnroe
Apparently sometimes it didn't like receiving its own internal storage to parse again. Understandable.
2020-02-09Add To Be Taught, If FortunateJune McEnroe
2020-02-04Add The Future of Another TimelineJune McEnroe
Wow. One of the best I've read.
2020-01-31Reorganize the Makefile for the umpteenth timeJune McEnroe
Broke out LDLIBS for each bin, and made everything more uniform.
2020-01-28Change scout sensitivity to 1.4June McEnroe
idk it seems to work.
2020-01-28Import shows.txtJune McEnroe