Register signal handler using sigaction() instead of signal()

This commit is contained in:
Camden Dixie O'Brien 2022-10-14 17:19:07 +01:00
parent 7666e3a99a
commit c200de7dc1

9
main.c
View File

@ -107,16 +107,13 @@ int main(int argc, char *argv[])
/*
* Register signal handler for SIGTERM and SIGINT.
*
* The behaviour of signal() is not entirely consistent across
* different implementations, so this should ideally be rewritten
* to use signaction() instead at some point.
*/
if (signal(SIGTERM, handle_exit_signal) == SIG_ERR) {
const struct sigaction act = { .sa_handler = handle_exit_signal };
if (sigaction(SIGTERM, &act, NULL) == -1) {
fprintf(stderr, "Failed to register SIGTERM signal handler\n");
return EXIT_FAILURE;
}
if (signal(SIGINT, handle_exit_signal) == SIG_ERR) {
if (sigaction(SIGINT, &act, NULL) == -1) {
fprintf(stderr, "Failed to register SIGINT signal handler\n");
return EXIT_FAILURE;
}