handle SIGINT and SIGTERM: cleanup on these signals - teed - A multiplex relay tee(1) daemon.
 (HTM) git clone git://bitreich.org/teed git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/teed
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) Tags
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit 7ea6a417f78562629bd6f579dd593d44a5372acb
 (DIR) parent c9671740957f58aa168262f3e76ad2f72542f05b
 (HTM) Author: Hiltjo Posthuma <hiltjo@codemadness.org>
       Date:   Mon, 14 Aug 2023 15:09:01 +0200
       
       handle SIGINT and SIGTERM: cleanup on these signals
       
       Signed-off-by: Christoph Lohmann <20h@r-36.net>
       
       Diffstat:
         M teed.c                              |      17 ++++++++++++++++-
       
       1 file changed, 16 insertions(+), 1 deletion(-)
       ---
 (DIR) 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) {