close signal_fd in cleanup

We should close file descriptors that we open. Also this commit adds
handling SIGINT (same as SIGTERM) and does not die if we got EAGAIN from
poll().
This commit is contained in:
Rentib 2025-02-09 14:33:02 +01:00
parent 6078a20af4
commit e6eb713fb3
No known key found for this signature in database

9
dam.c
View file

@ -727,6 +727,7 @@ setup(void)
sigemptyset(&mask); sigemptyset(&mask);
sigaddset(&mask, SIGUSR1); sigaddset(&mask, SIGUSR1);
sigaddset(&mask, SIGTERM); sigaddset(&mask, SIGTERM);
sigaddset(&mask, SIGINT);
if (sigprocmask(SIG_BLOCK, &mask, NULL) < 0) if (sigprocmask(SIG_BLOCK, &mask, NULL) < 0)
die("sigprocmask:"); die("sigprocmask:");
@ -758,7 +759,9 @@ run(void)
if (wl_display_flush(display) < 0) if (wl_display_flush(display) < 0)
die("wl_display_flush:"); die("wl_display_flush:");
if (poll(pfds, 3, -1) < 0) { while (poll(pfds, 3, -1) < 0) {
if (errno == EAGAIN)
continue;
wl_display_cancel_read(display); wl_display_cancel_read(display);
die("poll:"); die("poll:");
} }
@ -778,7 +781,8 @@ run(void)
die("signalfd/read:"); die("signalfd/read:");
if (si.ssi_signo == SIGUSR1) if (si.ssi_signo == SIGUSR1)
bars_toggle_selected(); bars_toggle_selected();
else if (si.ssi_signo == SIGTERM) else if (si.ssi_signo == SIGTERM ||
si.ssi_signo == SIGINT)
break; break;
} }
@ -814,6 +818,7 @@ cleanup(void)
wl_compositor_destroy(compositor); wl_compositor_destroy(compositor);
wl_registry_destroy(registry); wl_registry_destroy(registry);
wl_display_disconnect(display); wl_display_disconnect(display);
close(signal_fd); /* ignore error */
} }
static void static void