mirror of
https://github.com/swaywm/sway.git
synced 2026-04-17 06:46:32 -04:00
Use sigaction to establish signal handlers
The `signal` function may or may not re-establish the signal handler after delivering it once. Switch to using `sigaction` to establish signal handlers so we can specify the desired behavior explicitly.
This commit is contained in:
parent
9dcccf784b
commit
d8af40104d
1 changed files with 21 additions and 8 deletions
29
sway/main.c
29
sway/main.c
|
|
@ -159,6 +159,26 @@ void restore_nofile_limit(void) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void setup_signals(void) {
|
||||||
|
// handle SIGTERM signals by exiting
|
||||||
|
struct sigaction term_sig = {
|
||||||
|
.sa_handler = sig_handler,
|
||||||
|
.sa_flags = SA_RESETHAND,
|
||||||
|
};
|
||||||
|
sigaction(SIGTERM, &term_sig, NULL);
|
||||||
|
sigaction(SIGINT, &term_sig, NULL);
|
||||||
|
|
||||||
|
// handle SIGCHLD by reaping children; don't reset it after running it once
|
||||||
|
struct sigaction chld_sig = {
|
||||||
|
.sa_handler = sigchld_handler,
|
||||||
|
.sa_flags = SA_RESTART,
|
||||||
|
};
|
||||||
|
sigaction(SIGCHLD, &chld_sig, NULL);
|
||||||
|
|
||||||
|
// prevent ipc from crashing sway
|
||||||
|
signal(SIGPIPE, SIG_IGN);
|
||||||
|
}
|
||||||
|
|
||||||
void enable_debug_flag(const char *flag) {
|
void enable_debug_flag(const char *flag) {
|
||||||
if (strcmp(flag, "noatomic") == 0) {
|
if (strcmp(flag, "noatomic") == 0) {
|
||||||
debug.noatomic = true;
|
debug.noatomic = true;
|
||||||
|
|
@ -328,14 +348,7 @@ int main(int argc, char **argv) {
|
||||||
}
|
}
|
||||||
|
|
||||||
increase_nofile_limit();
|
increase_nofile_limit();
|
||||||
|
setup_signals();
|
||||||
// handle SIGTERM signals
|
|
||||||
signal(SIGTERM, sig_handler);
|
|
||||||
signal(SIGINT, sig_handler);
|
|
||||||
signal(SIGCHLD, sigchld_handler);
|
|
||||||
|
|
||||||
// prevent ipc from crashing sway
|
|
||||||
signal(SIGPIPE, SIG_IGN);
|
|
||||||
|
|
||||||
sway_log(SWAY_INFO, "Starting sway version " SWAY_VERSION);
|
sway_log(SWAY_INFO, "Starting sway version " SWAY_VERSION);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue