diff options
Diffstat (limited to 'sway/ipc.c')
-rw-r--r-- | sway/ipc.c | 15 |
1 files changed, 9 insertions, 6 deletions
@@ -98,7 +98,8 @@ struct sockaddr_un *ipc_user_sockaddr(void) { | |||
98 | int path_size = sizeof(ipc_sockaddr->sun_path); | 98 | int path_size = sizeof(ipc_sockaddr->sun_path); |
99 | 99 | ||
100 | // Without logind: | 100 | // Without logind: |
101 | int allocating_path_size = snprintf(ipc_sockaddr->sun_path, path_size, "/tmp/sway-ipc.%i.sock", getuid()); | 101 | int allocating_path_size = snprintf(ipc_sockaddr->sun_path, path_size, |
102 | "/tmp/sway-ipc.%i.%i.sock", getuid(), getpid()); | ||
102 | 103 | ||
103 | if (allocating_path_size >= path_size) { | 104 | if (allocating_path_size >= path_size) { |
104 | sway_abort("socket path won't fit into ipc_sockaddr->sun_path"); | 105 | sway_abort("socket path won't fit into ipc_sockaddr->sun_path"); |
@@ -176,7 +177,8 @@ int ipc_client_handle_readable(int client_fd, uint32_t mask, void *data) { | |||
176 | return 0; | 177 | return 0; |
177 | } | 178 | } |
178 | 179 | ||
179 | char buf[ipc_header_size]; | 180 | uint8_t buf[ipc_header_size]; |
181 | uint32_t *buf32 = (uint32_t*)(buf + sizeof(ipc_magic)); | ||
180 | ssize_t received = recv(client_fd, buf, ipc_header_size, 0); | 182 | ssize_t received = recv(client_fd, buf, ipc_header_size, 0); |
181 | if (received == -1) { | 183 | if (received == -1) { |
182 | sway_log_errno(L_INFO, "Unable to receive header from IPC client"); | 184 | sway_log_errno(L_INFO, "Unable to receive header from IPC client"); |
@@ -190,8 +192,8 @@ int ipc_client_handle_readable(int client_fd, uint32_t mask, void *data) { | |||
190 | return 0; | 192 | return 0; |
191 | } | 193 | } |
192 | 194 | ||
193 | client->payload_length = *(uint32_t *)&buf[sizeof(ipc_magic)]; | 195 | client->payload_length = buf32[0]; |
194 | client->current_command = (enum ipc_command_type) *(uint32_t *)&buf[sizeof(ipc_magic)+4]; | 196 | client->current_command = (enum ipc_command_type)buf32[1]; |
195 | 197 | ||
196 | if (read_available - received >= client->payload_length) { | 198 | if (read_available - received >= client->payload_length) { |
197 | ipc_client_handle_command(client); | 199 | ipc_client_handle_command(client); |
@@ -336,10 +338,11 @@ bool ipc_send_reply(struct ipc_client *client, const char *payload, uint32_t pay | |||
336 | assert(payload); | 338 | assert(payload); |
337 | 339 | ||
338 | char data[ipc_header_size]; | 340 | char data[ipc_header_size]; |
341 | uint32_t *data32 = (uint32_t*)(data + sizeof(ipc_magic)); | ||
339 | 342 | ||
340 | memcpy(data, ipc_magic, sizeof(ipc_magic)); | 343 | memcpy(data, ipc_magic, sizeof(ipc_magic)); |
341 | *(uint32_t *)&(data[sizeof(ipc_magic)]) = payload_length; | 344 | data32[0] = payload_length; |
342 | *(uint32_t *)&(data[sizeof(ipc_magic)+4]) = client->current_command; | 345 | data32[1] = client->current_command; |
343 | 346 | ||
344 | if (write(client->fd, data, ipc_header_size) == -1) { | 347 | if (write(client->fd, data, ipc_header_size) == -1) { |
345 | sway_log_errno(L_INFO, "Unable to send header to IPC client"); | 348 | sway_log_errno(L_INFO, "Unable to send header to IPC client"); |