From f26ed32e460f3007e623c529d28562f4a0b261cd Mon Sep 17 00:00:00 2001 From: minus Date: Thu, 20 Aug 2015 15:12:34 +0200 Subject: [PATCH] added sway_terminate to exit cleanly --- include/ipc.h | 2 +- sway/commands.c | 3 ++- sway/ipc.c | 2 +- sway/log.c | 3 ++- sway/main.c | 15 +++++++++++++-- 5 files changed, 19 insertions(+), 6 deletions(-) diff --git a/include/ipc.h b/include/ipc.h index 606c47bab..0b6441f66 100644 --- a/include/ipc.h +++ b/include/ipc.h @@ -13,6 +13,6 @@ enum ipc_command_type { }; void ipc_init(void); -void ipc_shutdown(void); +void ipc_terminate(void); #endif diff --git a/sway/commands.c b/sway/commands.c index 38557b62d..644b80050 100644 --- a/sway/commands.c +++ b/sway/commands.c @@ -15,6 +15,7 @@ #include "commands.h" #include "container.h" #include "handlers.h" +#include "sway.h" struct modifier_key { char *name; @@ -186,7 +187,7 @@ static bool cmd_exit(struct sway_config *config, int argc, char **argv) { } // Close all views container_map(&root_container, kill_views, NULL); - wlc_terminate(); + sway_terminate(); return true; } diff --git a/sway/ipc.c b/sway/ipc.c index 69f4a4f38..d55469edc 100644 --- a/sway/ipc.c +++ b/sway/ipc.c @@ -60,7 +60,7 @@ void ipc_init(void) { ipc_event_source = wlc_event_loop_add_fd(ipc_socket, WLC_EVENT_READABLE, ipc_handle_connection, NULL); } -void ipc_shutdown(void) { +void ipc_terminate(void) { if (ipc_event_source) { wlc_event_source_remove(ipc_event_source); } diff --git a/sway/log.c b/sway/log.c index e8c1b78fb..6e01421bc 100644 --- a/sway/log.c +++ b/sway/log.c @@ -1,4 +1,5 @@ #include "log.h" +#include "sway.h" #include #include #include @@ -42,7 +43,7 @@ void sway_abort(const char *format, ...) { vfprintf(stderr, format, args); va_end(args); fprintf(stderr, "\n"); - exit(1); + sway_terminate(); } void sway_log(int verbosity, const char* format, ...) { diff --git a/sway/main.c b/sway/main.c index a42fbcb78..f37f086df 100644 --- a/sway/main.c +++ b/sway/main.c @@ -10,6 +10,14 @@ #include "log.h" #include "handlers.h" #include "ipc.h" +#include "sway.h" + +static bool terminate_request = false; + +void sway_terminate(void) { + terminate_request = true; + wlc_terminate(); +} static void sigchld_handle(int signal); @@ -102,12 +110,15 @@ int main(int argc, char **argv) { ipc_init(); - wlc_run(); + if (!terminate_request) { + wlc_run(); + } + if (devnull) { fclose(devnull); } - ipc_shutdown(); + ipc_terminate(); return 0; }