summaryrefslogtreecommitdiffstats
path: root/sway/ipc.c
diff options
context:
space:
mode:
Diffstat (limited to 'sway/ipc.c')
-rw-r--r--sway/ipc.c23
1 files changed, 16 insertions, 7 deletions
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