summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar minus <minus@mnus.de>2015-08-19 01:52:46 +0200
committerLibravatar minus <minus@mnus.de>2015-08-20 15:24:33 +0200
commit91c08772645e2162015c3acf8a8ae7187502adb4 (patch)
tree542f9f0371f408fc72fbb4715ea0766770ab3fad
parentuse env var SWAYSOCK if available (diff)
downloadsway-91c08772645e2162015c3acf8a8ae7187502adb4.tar.gz
sway-91c08772645e2162015c3acf8a8ae7187502adb4.tar.zst
sway-91c08772645e2162015c3acf8a8ae7187502adb4.zip
properly exit sway
- wlc_terminate() instead of exit(0) - unlink IPC socket
-rw-r--r--include/ipc.h3
-rw-r--r--sway/commands.c2
-rw-r--r--sway/ipc.c23
-rw-r--r--sway/main.c4
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
15void init_ipc(void); 15void ipc_init(void);
16void 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
diff --git a/sway/ipc.c b/sway/ipc.c
index ba01a679..a6c4eb1a 100644
--- a/sway/ipc.c
+++ b/sway/ipc.c
@@ -16,6 +16,11 @@
16#include "commands.h" 16#include "commands.h"
17 17
18static int ipc_socket = -1; 18static int ipc_socket = -1;
19static struct wlc_event_source *ipc_event_source = NULL;
20static struct sockaddr_un ipc_sockaddr = {
21 .sun_family = AF_UNIX,
22 .sun_path = "/tmp/sway-ipc.sock"
23};
19 24
20static const char ipc_magic[] = {'i', '3', '-', 'i', 'p', 'c'}; 25static const char ipc_magic[] = {'i', '3', '-', 'i', 'p', 'c'};
21 26
@@ -32,17 +37,12 @@ void ipc_client_disconnect(struct ipc_client *client);
32void ipc_client_handle_command(struct ipc_client *client); 37void ipc_client_handle_command(struct ipc_client *client);
33bool ipc_send_reply(struct ipc_client *client, const char *payload, uint32_t payload_length); 38bool ipc_send_reply(struct ipc_client *client, const char *payload, uint32_t payload_length);
34 39
35void init_ipc() { 40void 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
62void 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
62int ipc_handle_connection(int fd, uint32_t mask, void *data) { 70int 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