summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/sway/ipc-server.h2
-rw-r--r--sway/ipc-server.c34
-rw-r--r--sway/main.c2
3 files changed, 20 insertions, 18 deletions
diff --git a/include/sway/ipc-server.h b/include/sway/ipc-server.h
index dd16a175..026b5554 100644
--- a/include/sway/ipc-server.h
+++ b/include/sway/ipc-server.h
@@ -9,8 +9,6 @@ struct sway_server;
9 9
10void ipc_init(struct sway_server *server); 10void ipc_init(struct sway_server *server);
11 11
12void ipc_terminate(void);
13
14struct sockaddr_un *ipc_user_sockaddr(void); 12struct sockaddr_un *ipc_user_sockaddr(void);
15 13
16void ipc_event_workspace(struct sway_container *old, 14void ipc_event_workspace(struct sway_container *old,
diff --git a/sway/ipc-server.c b/sway/ipc-server.c
index 3e510c2e..abc2d7cb 100644
--- a/sway/ipc-server.c
+++ b/sway/ipc-server.c
@@ -31,6 +31,7 @@ static int ipc_socket = -1;
31static struct wl_event_source *ipc_event_source = NULL; 31static struct wl_event_source *ipc_event_source = NULL;
32static struct sockaddr_un *ipc_sockaddr = NULL; 32static struct sockaddr_un *ipc_sockaddr = NULL;
33static list_t *ipc_client_list = NULL; 33static list_t *ipc_client_list = NULL;
34static struct wl_listener ipc_display_destroy;
34 35
35static const char ipc_magic[] = {'i', '3', '-', 'i', 'p', 'c'}; 36static const char ipc_magic[] = {'i', '3', '-', 'i', 'p', 'c'};
36 37
@@ -56,6 +57,22 @@ void ipc_client_disconnect(struct ipc_client *client);
56void ipc_client_handle_command(struct ipc_client *client); 57void ipc_client_handle_command(struct ipc_client *client);
57bool ipc_send_reply(struct ipc_client *client, const char *payload, uint32_t payload_length); 58bool ipc_send_reply(struct ipc_client *client, const char *payload, uint32_t payload_length);
58 59
60static void handle_display_destroy(struct wl_listener *listener, void *data) {
61 if (ipc_event_source) {
62 wl_event_source_remove(ipc_event_source);
63 }
64 close(ipc_socket);
65 unlink(ipc_sockaddr->sun_path);
66
67 list_free(ipc_client_list);
68
69 if (ipc_sockaddr) {
70 free(ipc_sockaddr);
71 }
72
73 wl_list_remove(&ipc_display_destroy.link);
74}
75
59void ipc_init(struct sway_server *server) { 76void ipc_init(struct sway_server *server) {
60 ipc_socket = socket(AF_UNIX, SOCK_STREAM | SOCK_NONBLOCK | SOCK_CLOEXEC, 0); 77 ipc_socket = socket(AF_UNIX, SOCK_STREAM | SOCK_NONBLOCK | SOCK_CLOEXEC, 0);
61 if (ipc_socket == -1) { 78 if (ipc_socket == -1) {
@@ -85,24 +102,13 @@ void ipc_init(struct sway_server *server) {
85 102
86 ipc_client_list = create_list(); 103 ipc_client_list = create_list();
87 104
105 ipc_display_destroy.notify = handle_display_destroy;
106 wl_display_add_destroy_listener(server->wl_display, &ipc_display_destroy);
107
88 ipc_event_source = wl_event_loop_add_fd(server->wl_event_loop, ipc_socket, 108 ipc_event_source = wl_event_loop_add_fd(server->wl_event_loop, ipc_socket,
89 WL_EVENT_READABLE, ipc_handle_connection, server); 109 WL_EVENT_READABLE, ipc_handle_connection, server);
90} 110}
91 111
92void ipc_terminate(void) {
93 if (ipc_event_source) {
94 wl_event_source_remove(ipc_event_source);
95 }
96 close(ipc_socket);
97 unlink(ipc_sockaddr->sun_path);
98
99 list_free(ipc_client_list);
100
101 if (ipc_sockaddr) {
102 free(ipc_sockaddr);
103 }
104}
105
106struct sockaddr_un *ipc_user_sockaddr(void) { 112struct sockaddr_un *ipc_user_sockaddr(void) {
107 struct sockaddr_un *ipc_sockaddr = malloc(sizeof(struct sockaddr_un)); 113 struct sockaddr_un *ipc_sockaddr = malloc(sizeof(struct sockaddr_un));
108 if (ipc_sockaddr == NULL) { 114 if (ipc_sockaddr == NULL) {
diff --git a/sway/main.c b/sway/main.c
index 8b0b8612..96e41bbc 100644
--- a/sway/main.c
+++ b/sway/main.c
@@ -437,8 +437,6 @@ int main(int argc, char **argv) {
437 437
438 server_fini(&server); 438 server_fini(&server);
439 439
440 ipc_terminate();
441
442 if (config) { 440 if (config) {
443 free_config(config); 441 free_config(config);
444 } 442 }