diff options
author | Toni Uhlig <matzeton@googlemail.com> | 2018-06-25 14:06:09 +0200 |
---|---|---|
committer | Toni Uhlig <matzeton@googlemail.com> | 2018-06-25 14:06:09 +0200 |
commit | a2780017dbaefa0761c8b4add09210afb288616d (patch) | |
tree | b405a7f55cab7df73cd8d6b9c66b9c9f33e59fd2 /src | |
parent | 977dac9cf4de095215d35b5716955f2b68fba9fb (diff) |
improved daemon multi process (exit) signal handling e.g. do not send double SIGTERMs/SIGHUPs
Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/main.c | 4 | ||||
-rw-r--r-- | src/utils.c | 7 |
2 files changed, 8 insertions, 3 deletions
@@ -377,11 +377,11 @@ int main(int argc, char *argv[]) E2("%s daemon with pid %d terminated, exiting", (child_pid == jl_pid ? "Jail" : "Redirector"), (child_pid == jl_pid ? jl_pid : rdr_pid)); - kill(getpid(), SIGTERM); - break; } else W2("Process with pid %d terminated", child_pid); + break; } log_close(); + kill(getpid(), SIGTERM); return 0; } diff --git a/src/utils.c b/src/utils.c index 2ff6715..4f0d667 100644 --- a/src/utils.c +++ b/src/utils.c @@ -129,15 +129,20 @@ sig_to_str(int signo, char *buf, size_t siz) static void sighandler_child(int signo) { + static int got_exitsig = 0; char buf[16] = {0}; + if (got_exitsig) + return; W("Got signal[%d]: %s", signo, sig_to_str(signo, &buf[0], sizeof buf)); switch (signo) { case SIGABRT: + got_exitsig = 1; exit(EXIT_FAILURE); case SIGHUP: if (getppid() == 1) { N("Master process %d died, exiting", getpgrp()); + got_exitsig = 1; exit(EXIT_SUCCESS); } break; @@ -150,6 +155,7 @@ static void sighandler_child(int signo) #ifdef HAVE_EXECINFO print_stack_trace(); #endif + got_exitsig = 1; exit(EXIT_FAILURE); } } @@ -180,7 +186,6 @@ static void sighandler_master(int signo) if (exiting) break; exiting = 1; - kill(0, SIGTERM); exit(EXIT_FAILURE); } } |