added sway_terminate to exit cleanly

This commit is contained in:
minus 2015-08-20 15:12:34 +02:00
parent 70f046c87a
commit f26ed32e46
5 changed files with 19 additions and 6 deletions

View file

@ -13,6 +13,6 @@ enum ipc_command_type {
}; };
void ipc_init(void); void ipc_init(void);
void ipc_shutdown(void); void ipc_terminate(void);
#endif #endif

View file

@ -15,6 +15,7 @@
#include "commands.h" #include "commands.h"
#include "container.h" #include "container.h"
#include "handlers.h" #include "handlers.h"
#include "sway.h"
struct modifier_key { struct modifier_key {
char *name; char *name;
@ -186,7 +187,7 @@ static bool cmd_exit(struct sway_config *config, int argc, char **argv) {
} }
// Close all views // Close all views
container_map(&root_container, kill_views, NULL); container_map(&root_container, kill_views, NULL);
wlc_terminate(); sway_terminate();
return true; return true;
} }

View file

@ -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); 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) { if (ipc_event_source) {
wlc_event_source_remove(ipc_event_source); wlc_event_source_remove(ipc_event_source);
} }

View file

@ -1,4 +1,5 @@
#include "log.h" #include "log.h"
#include "sway.h"
#include <stdarg.h> #include <stdarg.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
@ -42,7 +43,7 @@ void sway_abort(const char *format, ...) {
vfprintf(stderr, format, args); vfprintf(stderr, format, args);
va_end(args); va_end(args);
fprintf(stderr, "\n"); fprintf(stderr, "\n");
exit(1); sway_terminate();
} }
void sway_log(int verbosity, const char* format, ...) { void sway_log(int verbosity, const char* format, ...) {

View file

@ -10,6 +10,14 @@
#include "log.h" #include "log.h"
#include "handlers.h" #include "handlers.h"
#include "ipc.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); static void sigchld_handle(int signal);
@ -102,12 +110,15 @@ int main(int argc, char **argv) {
ipc_init(); ipc_init();
if (!terminate_request) {
wlc_run(); wlc_run();
}
if (devnull) { if (devnull) {
fclose(devnull); fclose(devnull);
} }
ipc_shutdown(); ipc_terminate();
return 0; return 0;
} }