diff --git a/src/kiwmi/main.c b/src/kiwmi/main.c index 76c005b..bcac596 100644 --- a/src/kiwmi/main.c +++ b/src/kiwmi/main.c @@ -4,9 +4,15 @@ #include #include +#include +#include #include "common.h" +static void sig_handler(int sig); + +int g_is_about_to_quit = 0; + int main(int argc, char *argv[]) { @@ -51,4 +57,23 @@ main(int argc, char *argv[]) ); } } + + signal(SIGINT, sig_handler); + signal(SIGHUP, sig_handler); + signal(SIGTERM, sig_handler); + signal(SIGCHLD, sig_handler); + signal(SIGPIPE, SIG_IGN); +} + +static void +sig_handler(int sig) +{ + if (sig == SIGCHLD) { + signal(sig, sig_handler); + while (waitpid(-1, 0, WNOHANG) > 0) { + // EMPTY + } + } else if (sig == SIGINT || sig == SIGHUP || sig == SIGTERM) { + g_is_about_to_quit = 1; + } }