From f0340b1475d859f03336c503a522e035cefcaee8 Mon Sep 17 00:00:00 2001 From: "Nicholas J. Kain" Date: Mon, 19 Oct 2020 13:03:35 -0400 Subject: [PATCH] Correct ba046c02c729c. Apparently I had forgotten the counter-intuitive semantics of signalfd(): it's necessary to BLOCK the signals that will be handled exclusively by signalfd() so that the default POSIX signal handling mechanism won't intercept the signals first. The lack of response to ctrl+c is a legitimate bug that is now properly fixed; ba046c02c729c fixed that issue, but regressed the handling of other signals. --- src/ndhc.c | 6 +++++- src/sys.c | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/ndhc.c b/src/ndhc.c index 62e55a9..e7ffaa8 100644 --- a/src/ndhc.c +++ b/src/ndhc.c @@ -166,7 +166,8 @@ static void setup_signals_ndhc(void) sigaddset(&mask, SIGUSR2); sigaddset(&mask, SIGCHLD); sigaddset(&mask, SIGTERM); - if (sigprocmask(SIG_UNBLOCK, &mask, (sigset_t *)0) < 0) + sigaddset(&mask, SIGINT); + if (sigprocmask(SIG_BLOCK, &mask, (sigset_t *)0) < 0) suicide("sigprocmask failed"); if (cs.signalFd >= 0) { epoll_del(cs.epollFd, cs.signalFd); @@ -201,6 +202,9 @@ static int signal_dispatch(void) case SIGTERM: log_line("Received SIGTERM. Exiting gracefully."); exit(EXIT_SUCCESS); + case SIGINT: + log_line("Received SIGINT. Exiting gracefully."); + exit(EXIT_SUCCESS); default: return SIGNAL_NONE; } } diff --git a/src/sys.c b/src/sys.c index 17b488a..548e4d8 100644 --- a/src/sys.c +++ b/src/sys.c @@ -77,7 +77,7 @@ int setup_signals_subprocess(void) sigaddset(&mask, SIGHUP); sigaddset(&mask, SIGINT); sigaddset(&mask, SIGTERM); - if (sigprocmask(SIG_UNBLOCK, &mask, (sigset_t *)0) < 0) + if (sigprocmask(SIG_BLOCK, &mask, (sigset_t *)0) < 0) suicide("sigprocmask failed"); int sfd = signalfd(-1, &mask, SFD_NONBLOCK); if (sfd < 0)