Added signal handling
This commit is contained in:
parent
b9e62e21a1
commit
56a0f117ec
1 changed files with 25 additions and 0 deletions
|
@ -4,9 +4,15 @@
|
|||
|
||||
#include <getopt.h>
|
||||
#include <limits.h>
|
||||
#include <signal.h>
|
||||
#include <sys/wait.h>
|
||||
|
||||
#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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue