mirror of
https://github.com/swaywm/sway.git
synced 2025-10-31 22:25:26 -04:00
Use wl_event_loop_add_signal for exit signals
This avoids calling non-async-signal-safe functions from within a signal handler.
This commit is contained in:
parent
cb246cb9c2
commit
8f089f0229
1 changed files with 18 additions and 14 deletions
32
sway/main.c
32
sway/main.c
|
|
@ -44,10 +44,6 @@ void sway_terminate(int exit_code) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void sig_handler(int signal) {
|
|
||||||
sway_terminate(EXIT_SUCCESS);
|
|
||||||
}
|
|
||||||
|
|
||||||
void run_as_ipc_client(char *command, char *socket_path) {
|
void run_as_ipc_client(char *command, char *socket_path) {
|
||||||
int socketfd = ipc_open_socket(socket_path);
|
int socketfd = ipc_open_socket(socket_path);
|
||||||
uint32_t len = strlen(command);
|
uint32_t len = strlen(command);
|
||||||
|
|
@ -152,6 +148,22 @@ void restore_nofile_limit(void) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int term_signal(int signal, void *data) {
|
||||||
|
sway_terminate(EXIT_SUCCESS);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void init_signals(void) {
|
||||||
|
wl_event_loop_add_signal(server.wl_event_loop, SIGTERM, term_signal, NULL);
|
||||||
|
wl_event_loop_add_signal(server.wl_event_loop, SIGINT, term_signal, NULL);
|
||||||
|
|
||||||
|
// avoid need to reap children
|
||||||
|
signal(SIGCHLD, SIG_IGN);
|
||||||
|
|
||||||
|
// prevent ipc write errors from crashing sway
|
||||||
|
signal(SIGPIPE, SIG_IGN);
|
||||||
|
}
|
||||||
|
|
||||||
void restore_signals(void) {
|
void restore_signals(void) {
|
||||||
sigset_t set;
|
sigset_t set;
|
||||||
sigemptyset(&set);
|
sigemptyset(&set);
|
||||||
|
|
@ -330,22 +342,14 @@ int main(int argc, char **argv) {
|
||||||
|
|
||||||
increase_nofile_limit();
|
increase_nofile_limit();
|
||||||
|
|
||||||
// handle SIGTERM signals
|
|
||||||
signal(SIGTERM, sig_handler);
|
|
||||||
signal(SIGINT, sig_handler);
|
|
||||||
|
|
||||||
// avoid need to reap children
|
|
||||||
signal(SIGCHLD, SIG_IGN);
|
|
||||||
|
|
||||||
// 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);
|
||||||
|
|
||||||
if (!server_init(&server)) {
|
if (!server_init(&server)) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
init_signals();
|
||||||
|
|
||||||
if (server.linux_dmabuf_v1) {
|
if (server.linux_dmabuf_v1) {
|
||||||
wlr_scene_set_linux_dmabuf_v1(root->root_scene, server.linux_dmabuf_v1);
|
wlr_scene_set_linux_dmabuf_v1(root->root_scene, server.linux_dmabuf_v1);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue