diff options
author | minus <minus@mnus.de> | 2015-08-19 01:52:46 +0200 |
---|---|---|
committer | minus <minus@mnus.de> | 2015-08-20 15:24:33 +0200 |
commit | 91c08772645e2162015c3acf8a8ae7187502adb4 (patch) | |
tree | 542f9f0371f408fc72fbb4715ea0766770ab3fad /sway/ipc.c | |
parent | use env var SWAYSOCK if available (diff) | |
download | sway-91c08772645e2162015c3acf8a8ae7187502adb4.tar.gz sway-91c08772645e2162015c3acf8a8ae7187502adb4.tar.zst sway-91c08772645e2162015c3acf8a8ae7187502adb4.zip |
properly exit sway
- wlc_terminate() instead of exit(0)
- unlink IPC socket
Diffstat (limited to 'sway/ipc.c')
-rw-r--r-- | sway/ipc.c | 23 |
1 files changed, 16 insertions, 7 deletions
@@ -16,6 +16,11 @@ | |||
16 | #include "commands.h" | 16 | #include "commands.h" |
17 | 17 | ||
18 | static int ipc_socket = -1; | 18 | static int ipc_socket = -1; |
19 | static struct wlc_event_source *ipc_event_source = NULL; | ||
20 | static struct sockaddr_un ipc_sockaddr = { | ||
21 | .sun_family = AF_UNIX, | ||
22 | .sun_path = "/tmp/sway-ipc.sock" | ||
23 | }; | ||
19 | 24 | ||
20 | static const char ipc_magic[] = {'i', '3', '-', 'i', 'p', 'c'}; | 25 | static const char ipc_magic[] = {'i', '3', '-', 'i', 'p', 'c'}; |
21 | 26 | ||
@@ -32,17 +37,12 @@ void ipc_client_disconnect(struct ipc_client *client); | |||
32 | void ipc_client_handle_command(struct ipc_client *client); | 37 | void ipc_client_handle_command(struct ipc_client *client); |
33 | bool ipc_send_reply(struct ipc_client *client, const char *payload, uint32_t payload_length); | 38 | bool ipc_send_reply(struct ipc_client *client, const char *payload, uint32_t payload_length); |
34 | 39 | ||
35 | void init_ipc() { | 40 | void ipc_init(void) { |
36 | ipc_socket = socket(AF_UNIX, SOCK_STREAM | SOCK_NONBLOCK | SOCK_CLOEXEC, 0); | 41 | ipc_socket = socket(AF_UNIX, SOCK_STREAM | SOCK_NONBLOCK | SOCK_CLOEXEC, 0); |
37 | if (ipc_socket == -1) { | 42 | if (ipc_socket == -1) { |
38 | sway_abort("Unable to create IPC socket"); | 43 | sway_abort("Unable to create IPC socket"); |
39 | } | 44 | } |
40 | 45 | ||
41 | struct sockaddr_un ipc_sockaddr = { | ||
42 | .sun_family = AF_UNIX, | ||
43 | .sun_path = "/tmp/sway-ipc.sock" | ||
44 | }; | ||
45 | |||
46 | if (getenv("SWAYSOCK") != NULL) { | 46 | if (getenv("SWAYSOCK") != NULL) { |
47 | strncpy(ipc_sockaddr.sun_path, getenv("SWAYSOCK"), sizeof(ipc_sockaddr.sun_path)); | 47 | strncpy(ipc_sockaddr.sun_path, getenv("SWAYSOCK"), sizeof(ipc_sockaddr.sun_path)); |
48 | } | 48 | } |
@@ -56,10 +56,19 @@ void init_ipc() { | |||
56 | sway_abort("Unable to listen on IPC socket"); | 56 | sway_abort("Unable to listen on IPC socket"); |
57 | } | 57 | } |
58 | 58 | ||
59 | wlc_event_loop_add_fd(ipc_socket, WLC_EVENT_READABLE, ipc_handle_connection, NULL); | 59 | ipc_event_source = wlc_event_loop_add_fd(ipc_socket, WLC_EVENT_READABLE, ipc_handle_connection, NULL); |
60 | } | ||
61 | |||
62 | void ipc_shutdown(void) { | ||
63 | if (ipc_event_source) { | ||
64 | wlc_event_source_remove(ipc_event_source); | ||
65 | } | ||
66 | close(ipc_socket); | ||
67 | unlink(ipc_sockaddr.sun_path); | ||
60 | } | 68 | } |
61 | 69 | ||
62 | int ipc_handle_connection(int fd, uint32_t mask, void *data) { | 70 | int ipc_handle_connection(int fd, uint32_t mask, void *data) { |
71 | (void) fd; (void) data; | ||
63 | sway_log(L_DEBUG, "Event on IPC listening socket"); | 72 | sway_log(L_DEBUG, "Event on IPC listening socket"); |
64 | assert(mask == WLC_EVENT_READABLE); | 73 | assert(mask == WLC_EVENT_READABLE); |
65 | 74 | ||