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
This commit is contained in:
Furkan Sahin 2025-03-10 17:42:48 -04:00
parent 5d7b9a8320
commit 824875c334
2 changed files with 8 additions and 6 deletions

View file

@ -8,9 +8,6 @@
#include "sway/config.h" #include "sway/config.h"
#include "sway/server.h" #include "sway/server.h"
#include "sway/desktop/launcher.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 "log.h"
#include "stringop.h" #include "stringop.h"

View file

@ -330,9 +330,14 @@ int main(int argc, char **argv) {
increase_nofile_limit(); increase_nofile_limit();
// handle SIGTERM signals // handle SIGTERM signals
signal(SIGTERM, sig_handler); struct sigaction sa;
signal(SIGINT, sig_handler); sa.sa_handler = sigchld_handler;
signal(SIGCHLD, 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 // prevent ipc from crashing sway
signal(SIGPIPE, SIG_IGN); signal(SIGPIPE, SIG_IGN);