handle SIGINT and SIGTERM: cleanup on these signals - teed - A multiplex relay … | |
git clone git://bitreich.org/teed git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d… | |
Log | |
Files | |
Refs | |
Tags | |
README | |
LICENSE | |
--- | |
commit 7ea6a417f78562629bd6f579dd593d44a5372acb | |
parent c9671740957f58aa168262f3e76ad2f72542f05b | |
Author: Hiltjo Posthuma <[email protected]> | |
Date: Mon, 14 Aug 2023 15:09:01 +0200 | |
handle SIGINT and SIGTERM: cleanup on these signals | |
Signed-off-by: Christoph Lohmann <[email protected]> | |
Diffstat: | |
M teed.c | 17 ++++++++++++++++- | |
1 file changed, 16 insertions(+), 1 deletion(-) | |
--- | |
diff --git a/teed.c b/teed.c | |
@@ -14,6 +14,8 @@ | |
#include <sys/stat.h> | |
#include <sys/select.h> | |
+volatile sig_atomic_t isrunning = 1; | |
+ | |
void * | |
memdup(void *p, int l) | |
{ | |
@@ -144,9 +146,22 @@ llist_del(llist **l, llist *e) | |
} | |
void | |
+sighandler(int signo) | |
+{ | |
+ switch (signo) { | |
+ case SIGINT: | |
+ case SIGTERM: | |
+ isrunning = 0; | |
+ break; | |
+ } | |
+} | |
+ | |
+void | |
initsignals(void) | |
{ | |
signal(SIGPIPE, SIG_IGN); | |
+ signal(SIGINT, sighandler); | |
+ signal(SIGTERM, sighandler); | |
} | |
int | |
@@ -215,7 +230,7 @@ main(int argc, char *argv[]) | |
timeout.tv_sec = 1; | |
timeout.tv_nsec = 0; | |
- for (;;) { | |
+ for (;isrunning;) { | |
maxsfd = 0; | |
FD_ZERO(&fdset); | |
forllist(lfds, e) { |