mirror of
https://github.com/swaywm/sway.git
synced 2024-11-26 18:01:29 +00:00
sway/ipc: Dynamically assign ipc_sockaddr.
This commit is contained in:
parent
219c4848a7
commit
ae93c6e6fe
28
sway/ipc.c
28
sway/ipc.c
|
@ -21,10 +21,7 @@
|
||||||
|
|
||||||
static int ipc_socket = -1;
|
static int ipc_socket = -1;
|
||||||
static struct wlc_event_source *ipc_event_source = NULL;
|
static struct wlc_event_source *ipc_event_source = NULL;
|
||||||
static struct sockaddr_un ipc_sockaddr = {
|
static struct sockaddr_un *ipc_sockaddr = NULL;
|
||||||
.sun_family = AF_UNIX,
|
|
||||||
.sun_path = "/tmp/sway-ipc.sock"
|
|
||||||
};
|
|
||||||
|
|
||||||
static const char ipc_magic[] = {'i', '3', '-', 'i', 'p', 'c'};
|
static const char ipc_magic[] = {'i', '3', '-', 'i', 'p', 'c'};
|
||||||
|
|
||||||
|
@ -35,6 +32,7 @@ struct ipc_client {
|
||||||
enum ipc_command_type current_command;
|
enum ipc_command_type current_command;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct sockaddr_un *ipc_user_sockaddr(void);
|
||||||
int ipc_handle_connection(int fd, uint32_t mask, void *data);
|
int ipc_handle_connection(int fd, uint32_t mask, void *data);
|
||||||
int ipc_client_handle_readable(int client_fd, uint32_t mask, void *data);
|
int ipc_client_handle_readable(int client_fd, uint32_t mask, void *data);
|
||||||
void ipc_client_disconnect(struct ipc_client *client);
|
void ipc_client_disconnect(struct ipc_client *client);
|
||||||
|
@ -49,12 +47,14 @@ void ipc_init(void) {
|
||||||
sway_abort("Unable to create IPC socket");
|
sway_abort("Unable to create IPC socket");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ipc_sockaddr = ipc_user_sockaddr();
|
||||||
|
|
||||||
if (getenv("SWAYSOCK") != NULL) {
|
if (getenv("SWAYSOCK") != NULL) {
|
||||||
strncpy(ipc_sockaddr.sun_path, getenv("SWAYSOCK"), sizeof(ipc_sockaddr.sun_path));
|
strncpy(ipc_sockaddr->sun_path, getenv("SWAYSOCK"), sizeof(ipc_sockaddr->sun_path));
|
||||||
}
|
}
|
||||||
|
|
||||||
unlink(ipc_sockaddr.sun_path);
|
unlink(ipc_sockaddr->sun_path);
|
||||||
if (bind(ipc_socket, (struct sockaddr *)&ipc_sockaddr, sizeof(ipc_sockaddr)) == -1) {
|
if (bind(ipc_socket, (struct sockaddr *)ipc_sockaddr, sizeof(*ipc_sockaddr)) == -1) {
|
||||||
sway_abort("Unable to bind IPC socket");
|
sway_abort("Unable to bind IPC socket");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,7 +63,7 @@ void ipc_init(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set i3 IPC socket path so that i3-msg works out of the box
|
// Set i3 IPC socket path so that i3-msg works out of the box
|
||||||
setenv("I3SOCK", ipc_sockaddr.sun_path, 1);
|
setenv("I3SOCK", ipc_sockaddr->sun_path, 1);
|
||||||
|
|
||||||
ipc_event_source = wlc_event_loop_add_fd(ipc_socket, WLC_EVENT_READABLE, ipc_handle_connection, NULL);
|
ipc_event_source = wlc_event_loop_add_fd(ipc_socket, WLC_EVENT_READABLE, ipc_handle_connection, NULL);
|
||||||
}
|
}
|
||||||
|
@ -73,7 +73,17 @@ void ipc_terminate(void) {
|
||||||
wlc_event_source_remove(ipc_event_source);
|
wlc_event_source_remove(ipc_event_source);
|
||||||
}
|
}
|
||||||
close(ipc_socket);
|
close(ipc_socket);
|
||||||
unlink(ipc_sockaddr.sun_path);
|
unlink(ipc_sockaddr->sun_path);
|
||||||
|
}
|
||||||
|
|
||||||
|
struct sockaddr_un *ipc_user_sockaddr(void) {
|
||||||
|
struct sockaddr_un *ipc_sockaddr = malloc(sizeof(struct sockaddr_un));
|
||||||
|
assert(ipc_sockaddr != NULL);
|
||||||
|
|
||||||
|
ipc_sockaddr->sun_family = AF_UNIX;
|
||||||
|
strcpy(ipc_sockaddr->sun_path, "/tmp/sway-ipc.sock");
|
||||||
|
|
||||||
|
return ipc_sockaddr;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ipc_handle_connection(int fd, uint32_t mask, void *data) {
|
int ipc_handle_connection(int fd, uint32_t mask, void *data) {
|
||||||
|
|
Loading…
Reference in a new issue