1
1
mirror of https://github.com/swaywm/sway synced 2024-11-18 00:24:17 +01:00

properly exit sway

- wlc_terminate() instead of exit(0)
- unlink IPC socket
This commit is contained in:
minus 2015-08-19 01:52:46 +02:00
parent bfbadadf70
commit 91c0877264
4 changed files with 22 additions and 10 deletions

@ -12,6 +12,7 @@ enum ipc_command_type {
IPC_GET_VERSION = 7,
};
void init_ipc(void);
void ipc_init(void);
void ipc_shutdown(void);
#endif

@ -186,7 +186,7 @@ static bool cmd_exit(struct sway_config *config, int argc, char **argv) {
}
// Close all views
container_map(&root_container, kill_views, NULL);
exit(0);
wlc_terminate();
return true;
}

@ -16,6 +16,11 @@
#include "commands.h"
static int ipc_socket = -1;
static struct wlc_event_source *ipc_event_source = NULL;
static struct sockaddr_un ipc_sockaddr = {
.sun_family = AF_UNIX,
.sun_path = "/tmp/sway-ipc.sock"
};
static const char ipc_magic[] = {'i', '3', '-', 'i', 'p', 'c'};
@ -32,17 +37,12 @@ void ipc_client_disconnect(struct ipc_client *client);
void ipc_client_handle_command(struct ipc_client *client);
bool ipc_send_reply(struct ipc_client *client, const char *payload, uint32_t payload_length);
void init_ipc() {
void ipc_init(void) {
ipc_socket = socket(AF_UNIX, SOCK_STREAM | SOCK_NONBLOCK | SOCK_CLOEXEC, 0);
if (ipc_socket == -1) {
sway_abort("Unable to create IPC socket");
}
struct sockaddr_un ipc_sockaddr = {
.sun_family = AF_UNIX,
.sun_path = "/tmp/sway-ipc.sock"
};
if (getenv("SWAYSOCK") != NULL) {
strncpy(ipc_sockaddr.sun_path, getenv("SWAYSOCK"), sizeof(ipc_sockaddr.sun_path));
}
@ -56,10 +56,19 @@ void init_ipc() {
sway_abort("Unable to listen on IPC socket");
}
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) {
if (ipc_event_source) {
wlc_event_source_remove(ipc_event_source);
}
close(ipc_socket);
unlink(ipc_sockaddr.sun_path);
}
int ipc_handle_connection(int fd, uint32_t mask, void *data) {
(void) fd; (void) data;
sway_log(L_DEBUG, "Event on IPC listening socket");
assert(mask == WLC_EVENT_READABLE);

@ -100,13 +100,15 @@ int main(int argc, char **argv) {
free(config_path);
}
init_ipc();
ipc_init();
wlc_run();
if (devnull) {
fclose(devnull);
}
ipc_shutdown();
return 0;
}