diff options
-rw-r--r-- | include/ipc.h | 3 | ||||
-rw-r--r-- | sway/commands.c | 2 | ||||
-rw-r--r-- | sway/ipc.c | 23 | ||||
-rw-r--r-- | sway/main.c | 4 |
4 files changed, 22 insertions, 10 deletions
diff --git a/include/ipc.h b/include/ipc.h index 25d2fc61..606c47ba 100644 --- a/include/ipc.h +++ b/include/ipc.h | |||
@@ -12,6 +12,7 @@ enum ipc_command_type { | |||
12 | IPC_GET_VERSION = 7, | 12 | IPC_GET_VERSION = 7, |
13 | }; | 13 | }; |
14 | 14 | ||
15 | void init_ipc(void); | 15 | void ipc_init(void); |
16 | void ipc_shutdown(void); | ||
16 | 17 | ||
17 | #endif | 18 | #endif |
diff --git a/sway/commands.c b/sway/commands.c index 803d9a21..38557b62 100644 --- a/sway/commands.c +++ b/sway/commands.c | |||
@@ -186,7 +186,7 @@ static bool cmd_exit(struct sway_config *config, int argc, char **argv) { | |||
186 | } | 186 | } |
187 | // Close all views | 187 | // Close all views |
188 | container_map(&root_container, kill_views, NULL); | 188 | container_map(&root_container, kill_views, NULL); |
189 | exit(0); | 189 | wlc_terminate(); |
190 | return true; | 190 | return true; |
191 | } | 191 | } |
192 | 192 | ||
@@ -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 | ||
diff --git a/sway/main.c b/sway/main.c index 1af1278d..a42fbcb7 100644 --- a/sway/main.c +++ b/sway/main.c | |||
@@ -100,13 +100,15 @@ int main(int argc, char **argv) { | |||
100 | free(config_path); | 100 | free(config_path); |
101 | } | 101 | } |
102 | 102 | ||
103 | init_ipc(); | 103 | ipc_init(); |
104 | 104 | ||
105 | wlc_run(); | 105 | wlc_run(); |
106 | if (devnull) { | 106 | if (devnull) { |
107 | fclose(devnull); | 107 | fclose(devnull); |
108 | } | 108 | } |
109 | 109 | ||
110 | ipc_shutdown(); | ||
111 | |||
110 | return 0; | 112 | return 0; |
111 | } | 113 | } |
112 | 114 | ||