From 824875c334d7d172375154c645d072a25b33d798 Mon Sep 17 00:00:00 2001 From: Furkan Sahin Date: Mon, 10 Mar 2025 17:42:48 -0400 Subject: [PATCH] Use sigaction instead of signal man signal(2) says to use sigaction rather than signal. ```man WARNING: the behavior of signal() varies across UNIX versions, and has also varied historically across different versions of Linux. Avoid its use: use sigaction(2) instead. See Portability below. ``` I put a breakpoint on main.c:sigchld_handler and noticed that it would only get hit for the first process to send SIGCHLD. Using signal, subsequent processes do not trigger sigchld_handler, causing them to become zombies. Fixes #8602 --- sway/commands/exec_always.c | 3 --- sway/main.c | 11 ++++++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/sway/commands/exec_always.c b/sway/commands/exec_always.c index 14566fc43..722ea197e 100644 --- a/sway/commands/exec_always.c +++ b/sway/commands/exec_always.c @@ -8,9 +8,6 @@ #include "sway/config.h" #include "sway/server.h" #include "sway/desktop/launcher.h" -#include "sway/tree/container.h" -#include "sway/tree/root.h" -#include "sway/tree/workspace.h" #include "log.h" #include "stringop.h" diff --git a/sway/main.c b/sway/main.c index 0cc7623d8..16efb84bf 100644 --- a/sway/main.c +++ b/sway/main.c @@ -330,9 +330,14 @@ int main(int argc, char **argv) { increase_nofile_limit(); // handle SIGTERM signals - signal(SIGTERM, sig_handler); - signal(SIGINT, sig_handler); - signal(SIGCHLD, sigchld_handler); + struct sigaction sa; + sa.sa_handler = sigchld_handler; + sigemptyset(&sa.sa_mask); + sa.sa_flags = SA_RESTART | SA_NOCLDSTOP; + sigaction(SIGCHLD, &sa, NULL); + sa.sa_handler = sig_handler; + sigaction(SIGTERM, &sa, NULL); + sigaction(SIGINT, &sa, NULL); // prevent ipc from crashing sway signal(SIGPIPE, SIG_IGN);