commit f26ed32e460f3007e623c529d28562f4a0b261cd
parent 70f046c87a1fc03c3b3132bf3b05d2e4c4495805
Author: minus <minus@mnus.de>
Date: Thu, 20 Aug 2015 15:12:34 +0200
added sway_terminate to exit cleanly
Diffstat:
5 files changed, 19 insertions(+), 6 deletions(-)
diff --git 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
@@ -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
@@ -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
@@ -1,4 +1,5 @@
#include "log.h"
+#include "sway.h"
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
@@ -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
@@ -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;
}