From 2827a020a414e20270e06514d7675525c17d100b Mon Sep 17 00:00:00 2001 From: Yuxuan Shui Date: Mon, 26 Nov 2018 23:21:53 +0000 Subject: [PATCH] Handle SIGINT Exit gracefully so sanitizer can do their jobs. Signed-off-by: Yuxuan Shui --- src/compton.c | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/src/compton.c b/src/compton.c index eaac473..9b73ab8 100644 --- a/src/compton.c +++ b/src/compton.c @@ -5809,6 +5809,11 @@ reset_enable(int __attribute__((unused)) signum) { ev_break(ps->loop, EVBREAK_ALL); } +static void +sigint_handler(int __attribute__((unused)) signum) { + exit(0); +} + /** * The function that everybody knows. */ @@ -5819,16 +5824,21 @@ main(int argc, char **argv) { setlocale(LC_ALL, ""); // Set up SIGUSR1 signal handler to reset program - { - sigset_t block_mask; - sigemptyset(&block_mask); - const struct sigaction action= { - .sa_handler = reset_enable, - .sa_mask = block_mask, - .sa_flags = 0 - }; - sigaction(SIGUSR1, &action, NULL); - } + sigset_t sigmask; + sigemptyset(&sigmask); + const struct sigaction usr1_action = { + .sa_handler = reset_enable, + .sa_mask = sigmask, + .sa_flags = 0 + }; + sigaction(SIGUSR1, &usr1_action, NULL); + + const struct sigaction int_action = { + .sa_handler = sigint_handler, + .sa_mask = sigmask, + .sa_flags = 0 + }; + sigaction(SIGINT, &int_action, NULL); // Main loop session_t *ps_old = ps_g;