diff options
Diffstat (limited to 'src/signals.c')
-rw-r--r-- | src/signals.c | 84 |
1 files changed, 40 insertions, 44 deletions
diff --git a/src/signals.c b/src/signals.c index 492c90d..8b1152e 100644 --- a/src/signals.c +++ b/src/signals.c @@ -14,46 +14,57 @@ You should have received a copy of the GNU General Public License along with Redshift. If not, see <http://www.gnu.org/licenses/>. - Copyright (c) 2009-2015 Jon Lund Steffensen <jonlst@gmail.com> - Copyright (c) 2015 Mattias Andrée <m@maandree.se> + Copyright (c) 2009-2015 Jon Lund Steffensen <jonlst@gmail.com> + Copyright (c) 2015, 2025 Mattias Andrée <m@maandree.se> */ #include "common.h" -#ifndef WINDOWS - volatile sig_atomic_t exiting = 0; volatile sig_atomic_t disable = 0; -/* Signal handler for exit signals */ +/** + * Signal handlar for exit signals (SIGINT, SIGTERM, SIGQUIT) + * + * @param signo The received signal + */ static void sigexit(int signo) { exiting = 1; +#ifdef WINDOWS + signal(signo, &sigexit); +#endif (void) signo; } -/* Signal handler for disable signal */ + +/** + * Signal handlar for disable signal (SIGUSR1) + * + * @param signo The received signal + */ +#ifndef WINDOWS static void sigdisable(int signo) { disable = 1; (void) signo; } - -#else - -int disable = 0; -int exiting = 0; - #endif -int +void signals_install_handlers(void) { -#ifndef WINDOWS +#ifdef WINDOWS + if (signal(SIGINT, &sigexit) == SIG_ERR) + eprintf("signal SIGINT <function pointer>:"); + if (signal(SIGTERM, &sigexit) == SIG_ERR) + eprintf("signal SIGTERM <function pointer>:"); + +#else struct sigaction sigact; sigset_t sigset; @@ -62,35 +73,20 @@ signals_install_handlers(void) sigact.sa_mask = sigset; sigact.sa_flags = 0; - /* Install signal handler for INT, TERM, QUIT signals */ - sigact.sa_handler = sigexit; - if (sigaction(SIGINT, &sigact, NULL)) { - weprintf("sigaction SIGINT &{.sa_handler=<function pointer>, .sa_mask={}, .sa_flags=0} NULL:"); - return -1; - } - if (sigaction(SIGTERM, &sigact, NULL)) { - weprintf("sigaction SIGTERM &{.sa_handler=<function pointer>, .sa_mask={}, .sa_flags=0} NULL:"); - return -1; - } - if (sigaction(SIGQUIT, &sigact, NULL)) { - weprintf("sigaction SIGQUIT &{.sa_handler=<function pointer>, .sa_mask={}, .sa_flags=0} NULL:"); - return -1; - } - - /* Install signal handler for USR1 signal */ - sigact.sa_handler = sigdisable; - if (sigaction(SIGUSR1, &sigact, NULL)) { - weprintf("sigaction SIGUSR1 &{.sa_handler=<function pointer>, .sa_mask={}, .sa_flags=0} NULL:"); - return -1; - } - - /* Ignore CHLD signal. This causes child processes (hooks) to be reaped automatically. */ - sigact.sa_handler = SIG_IGN; - if (sigaction(SIGCHLD, &sigact, NULL)) { - weprintf("sigaction SIGCHLD &{.sa_handler=SIG_IGN, .sa_mask={}, .sa_flags=0} NULL:"); - return -1; - } + sigact.sa_handler = &sigexit; + if (sigaction(SIGINT, &sigact, NULL)) + eprintf("sigaction SIGINT &{.sa_handler=<function pointer>, .sa_mask={}, .sa_flags=0} NULL:"); + if (sigaction(SIGTERM, &sigact, NULL)) + eprintf("sigaction SIGTERM &{.sa_handler=<function pointer>, .sa_mask={}, .sa_flags=0} NULL:"); + if (sigaction(SIGQUIT, &sigact, NULL)) + eprintf("sigaction SIGQUIT &{.sa_handler=<function pointer>, .sa_mask={}, .sa_flags=0} NULL:"); + + sigact.sa_handler = &sigdisable; + if (sigaction(SIGUSR1, &sigact, NULL)) + eprintf("sigaction SIGUSR1 &{.sa_handler=<function pointer>, .sa_mask={}, .sa_flags=0} NULL:"); + + sigact.sa_handler = SIG_IGN; /* cause child processes (hooks) to be reaped automatically */ + if (sigaction(SIGCHLD, &sigact, NULL)) + eprintf("sigaction SIGCHLD &{.sa_handler=SIG_IGN, .sa_mask={}, .sa_flags=0} NULL:"); #endif - - return 0; } |