diff options
author | emersion <contact@emersion.fr> | 2018-07-09 22:54:30 +0100 |
---|---|---|
committer | emersion <contact@emersion.fr> | 2018-07-09 22:54:30 +0100 |
commit | 63b4bf500020cf35cebfdce2d73f8e359ff495c2 (patch) | |
tree | 76624b3d4820551261e5c15f773c403c1a41264e /sway/ipc-server.c | |
parent | Merge pull request #2223 from RyanDwyer/floating-move (diff) | |
download | sway-63b4bf500020cf35cebfdce2d73f8e359ff495c2.tar.gz sway-63b4bf500020cf35cebfdce2d73f8e359ff495c2.tar.zst sway-63b4bf500020cf35cebfdce2d73f8e359ff495c2.zip |
Update for swaywm/wlroots#1126
Diffstat (limited to 'sway/ipc-server.c')
-rw-r--r-- | sway/ipc-server.c | 62 |
1 files changed, 31 insertions, 31 deletions
diff --git a/sway/ipc-server.c b/sway/ipc-server.c index abdaa237..197851cf 100644 --- a/sway/ipc-server.c +++ b/sway/ipc-server.c | |||
@@ -138,32 +138,32 @@ struct sockaddr_un *ipc_user_sockaddr(void) { | |||
138 | int ipc_handle_connection(int fd, uint32_t mask, void *data) { | 138 | int ipc_handle_connection(int fd, uint32_t mask, void *data) { |
139 | (void) fd; | 139 | (void) fd; |
140 | struct sway_server *server = data; | 140 | struct sway_server *server = data; |
141 | wlr_log(L_DEBUG, "Event on IPC listening socket"); | 141 | wlr_log(WLR_DEBUG, "Event on IPC listening socket"); |
142 | assert(mask == WL_EVENT_READABLE); | 142 | assert(mask == WL_EVENT_READABLE); |
143 | 143 | ||
144 | int client_fd = accept(ipc_socket, NULL, NULL); | 144 | int client_fd = accept(ipc_socket, NULL, NULL); |
145 | if (client_fd == -1) { | 145 | if (client_fd == -1) { |
146 | wlr_log_errno(L_ERROR, "Unable to accept IPC client connection"); | 146 | wlr_log_errno(WLR_ERROR, "Unable to accept IPC client connection"); |
147 | return 0; | 147 | return 0; |
148 | } | 148 | } |
149 | 149 | ||
150 | int flags; | 150 | int flags; |
151 | if ((flags = fcntl(client_fd, F_GETFD)) == -1 | 151 | if ((flags = fcntl(client_fd, F_GETFD)) == -1 |
152 | || fcntl(client_fd, F_SETFD, flags|FD_CLOEXEC) == -1) { | 152 | || fcntl(client_fd, F_SETFD, flags|FD_CLOEXEC) == -1) { |
153 | wlr_log_errno(L_ERROR, "Unable to set CLOEXEC on IPC client socket"); | 153 | wlr_log_errno(WLR_ERROR, "Unable to set CLOEXEC on IPC client socket"); |
154 | close(client_fd); | 154 | close(client_fd); |
155 | return 0; | 155 | return 0; |
156 | } | 156 | } |
157 | if ((flags = fcntl(client_fd, F_GETFL)) == -1 | 157 | if ((flags = fcntl(client_fd, F_GETFL)) == -1 |
158 | || fcntl(client_fd, F_SETFL, flags|O_NONBLOCK) == -1) { | 158 | || fcntl(client_fd, F_SETFL, flags|O_NONBLOCK) == -1) { |
159 | wlr_log_errno(L_ERROR, "Unable to set NONBLOCK on IPC client socket"); | 159 | wlr_log_errno(WLR_ERROR, "Unable to set NONBLOCK on IPC client socket"); |
160 | close(client_fd); | 160 | close(client_fd); |
161 | return 0; | 161 | return 0; |
162 | } | 162 | } |
163 | 163 | ||
164 | struct ipc_client *client = malloc(sizeof(struct ipc_client)); | 164 | struct ipc_client *client = malloc(sizeof(struct ipc_client)); |
165 | if (!client) { | 165 | if (!client) { |
166 | wlr_log(L_ERROR, "Unable to allocate ipc client"); | 166 | wlr_log(WLR_ERROR, "Unable to allocate ipc client"); |
167 | close(client_fd); | 167 | close(client_fd); |
168 | return 0; | 168 | return 0; |
169 | } | 169 | } |
@@ -179,12 +179,12 @@ int ipc_handle_connection(int fd, uint32_t mask, void *data) { | |||
179 | client->write_buffer_len = 0; | 179 | client->write_buffer_len = 0; |
180 | client->write_buffer = malloc(client->write_buffer_size); | 180 | client->write_buffer = malloc(client->write_buffer_size); |
181 | if (!client->write_buffer) { | 181 | if (!client->write_buffer) { |
182 | wlr_log(L_ERROR, "Unable to allocate ipc client write buffer"); | 182 | wlr_log(WLR_ERROR, "Unable to allocate ipc client write buffer"); |
183 | close(client_fd); | 183 | close(client_fd); |
184 | return 0; | 184 | return 0; |
185 | } | 185 | } |
186 | 186 | ||
187 | wlr_log(L_DEBUG, "New client: fd %d", client_fd); | 187 | wlr_log(WLR_DEBUG, "New client: fd %d", client_fd); |
188 | list_add(ipc_client_list, client); | 188 | list_add(ipc_client_list, client); |
189 | return 0; | 189 | return 0; |
190 | } | 190 | } |
@@ -195,22 +195,22 @@ int ipc_client_handle_readable(int client_fd, uint32_t mask, void *data) { | |||
195 | struct ipc_client *client = data; | 195 | struct ipc_client *client = data; |
196 | 196 | ||
197 | if (mask & WL_EVENT_ERROR) { | 197 | if (mask & WL_EVENT_ERROR) { |
198 | wlr_log(L_ERROR, "IPC Client socket error, removing client"); | 198 | wlr_log(WLR_ERROR, "IPC Client socket error, removing client"); |
199 | ipc_client_disconnect(client); | 199 | ipc_client_disconnect(client); |
200 | return 0; | 200 | return 0; |
201 | } | 201 | } |
202 | 202 | ||
203 | if (mask & WL_EVENT_HANGUP) { | 203 | if (mask & WL_EVENT_HANGUP) { |
204 | wlr_log(L_DEBUG, "Client %d hung up", client->fd); | 204 | wlr_log(WLR_DEBUG, "Client %d hung up", client->fd); |
205 | ipc_client_disconnect(client); | 205 | ipc_client_disconnect(client); |
206 | return 0; | 206 | return 0; |
207 | } | 207 | } |
208 | 208 | ||
209 | wlr_log(L_DEBUG, "Client %d readable", client->fd); | 209 | wlr_log(WLR_DEBUG, "Client %d readable", client->fd); |
210 | 210 | ||
211 | int read_available; | 211 | int read_available; |
212 | if (ioctl(client_fd, FIONREAD, &read_available) == -1) { | 212 | if (ioctl(client_fd, FIONREAD, &read_available) == -1) { |
213 | wlr_log_errno(L_INFO, "Unable to read IPC socket buffer size"); | 213 | wlr_log_errno(WLR_INFO, "Unable to read IPC socket buffer size"); |
214 | ipc_client_disconnect(client); | 214 | ipc_client_disconnect(client); |
215 | return 0; | 215 | return 0; |
216 | } | 216 | } |
@@ -232,13 +232,13 @@ int ipc_client_handle_readable(int client_fd, uint32_t mask, void *data) { | |||
232 | // Should be fully available, because read_available >= ipc_header_size | 232 | // Should be fully available, because read_available >= ipc_header_size |
233 | ssize_t received = recv(client_fd, buf, ipc_header_size, 0); | 233 | ssize_t received = recv(client_fd, buf, ipc_header_size, 0); |
234 | if (received == -1) { | 234 | if (received == -1) { |
235 | wlr_log_errno(L_INFO, "Unable to receive header from IPC client"); | 235 | wlr_log_errno(WLR_INFO, "Unable to receive header from IPC client"); |
236 | ipc_client_disconnect(client); | 236 | ipc_client_disconnect(client); |
237 | return 0; | 237 | return 0; |
238 | } | 238 | } |
239 | 239 | ||
240 | if (memcmp(buf, ipc_magic, sizeof(ipc_magic)) != 0) { | 240 | if (memcmp(buf, ipc_magic, sizeof(ipc_magic)) != 0) { |
241 | wlr_log(L_DEBUG, "IPC header check failed"); | 241 | wlr_log(WLR_DEBUG, "IPC header check failed"); |
242 | ipc_client_disconnect(client); | 242 | ipc_client_disconnect(client); |
243 | return 0; | 243 | return 0; |
244 | } | 244 | } |
@@ -272,7 +272,7 @@ static void ipc_send_event(const char *json_string, enum ipc_command_type event) | |||
272 | } | 272 | } |
273 | client->current_command = event; | 273 | client->current_command = event; |
274 | if (!ipc_send_reply(client, json_string, (uint32_t) strlen(json_string))) { | 274 | if (!ipc_send_reply(client, json_string, (uint32_t) strlen(json_string))) { |
275 | wlr_log_errno(L_INFO, "Unable to send reply to IPC client"); | 275 | wlr_log_errno(WLR_INFO, "Unable to send reply to IPC client"); |
276 | /* ipc_send_reply destroys client on error, which also | 276 | /* ipc_send_reply destroys client on error, which also |
277 | * removes it from the list, so we need to process | 277 | * removes it from the list, so we need to process |
278 | * current index again */ | 278 | * current index again */ |
@@ -286,7 +286,7 @@ void ipc_event_workspace(struct sway_container *old, | |||
286 | if (!ipc_has_event_listeners(IPC_EVENT_WORKSPACE)) { | 286 | if (!ipc_has_event_listeners(IPC_EVENT_WORKSPACE)) { |
287 | return; | 287 | return; |
288 | } | 288 | } |
289 | wlr_log(L_DEBUG, "Sending workspace::%s event", change); | 289 | wlr_log(WLR_DEBUG, "Sending workspace::%s event", change); |
290 | json_object *obj = json_object_new_object(); | 290 | json_object *obj = json_object_new_object(); |
291 | json_object_object_add(obj, "change", json_object_new_string(change)); | 291 | json_object_object_add(obj, "change", json_object_new_string(change)); |
292 | if (strcmp("focus", change) == 0) { | 292 | if (strcmp("focus", change) == 0) { |
@@ -314,7 +314,7 @@ void ipc_event_window(struct sway_container *window, const char *change) { | |||
314 | if (!ipc_has_event_listeners(IPC_EVENT_WINDOW)) { | 314 | if (!ipc_has_event_listeners(IPC_EVENT_WINDOW)) { |
315 | return; | 315 | return; |
316 | } | 316 | } |
317 | wlr_log(L_DEBUG, "Sending window::%s event", change); | 317 | wlr_log(WLR_DEBUG, "Sending window::%s event", change); |
318 | json_object *obj = json_object_new_object(); | 318 | json_object *obj = json_object_new_object(); |
319 | json_object_object_add(obj, "change", json_object_new_string(change)); | 319 | json_object_object_add(obj, "change", json_object_new_string(change)); |
320 | json_object_object_add(obj, "container", ipc_json_describe_container_recursive(window)); | 320 | json_object_object_add(obj, "container", ipc_json_describe_container_recursive(window)); |
@@ -328,7 +328,7 @@ void ipc_event_barconfig_update(struct bar_config *bar) { | |||
328 | if (!ipc_has_event_listeners(IPC_EVENT_BARCONFIG_UPDATE)) { | 328 | if (!ipc_has_event_listeners(IPC_EVENT_BARCONFIG_UPDATE)) { |
329 | return; | 329 | return; |
330 | } | 330 | } |
331 | wlr_log(L_DEBUG, "Sending barconfig_update event"); | 331 | wlr_log(WLR_DEBUG, "Sending barconfig_update event"); |
332 | json_object *json = ipc_json_describe_bar_config(bar); | 332 | json_object *json = ipc_json_describe_bar_config(bar); |
333 | 333 | ||
334 | const char *json_string = json_object_to_json_string(json); | 334 | const char *json_string = json_object_to_json_string(json); |
@@ -340,7 +340,7 @@ void ipc_event_mode(const char *mode, bool pango) { | |||
340 | if (!ipc_has_event_listeners(IPC_EVENT_MODE)) { | 340 | if (!ipc_has_event_listeners(IPC_EVENT_MODE)) { |
341 | return; | 341 | return; |
342 | } | 342 | } |
343 | wlr_log(L_DEBUG, "Sending mode::%s event", mode); | 343 | wlr_log(WLR_DEBUG, "Sending mode::%s event", mode); |
344 | json_object *obj = json_object_new_object(); | 344 | json_object *obj = json_object_new_object(); |
345 | json_object_object_add(obj, "change", json_object_new_string(mode)); | 345 | json_object_object_add(obj, "change", json_object_new_string(mode)); |
346 | json_object_object_add(obj, "pango_markup", | 346 | json_object_object_add(obj, "pango_markup", |
@@ -355,13 +355,13 @@ int ipc_client_handle_writable(int client_fd, uint32_t mask, void *data) { | |||
355 | struct ipc_client *client = data; | 355 | struct ipc_client *client = data; |
356 | 356 | ||
357 | if (mask & WL_EVENT_ERROR) { | 357 | if (mask & WL_EVENT_ERROR) { |
358 | wlr_log(L_ERROR, "IPC Client socket error, removing client"); | 358 | wlr_log(WLR_ERROR, "IPC Client socket error, removing client"); |
359 | ipc_client_disconnect(client); | 359 | ipc_client_disconnect(client); |
360 | return 0; | 360 | return 0; |
361 | } | 361 | } |
362 | 362 | ||
363 | if (mask & WL_EVENT_HANGUP) { | 363 | if (mask & WL_EVENT_HANGUP) { |
364 | wlr_log(L_DEBUG, "Client %d hung up", client->fd); | 364 | wlr_log(WLR_DEBUG, "Client %d hung up", client->fd); |
365 | ipc_client_disconnect(client); | 365 | ipc_client_disconnect(client); |
366 | return 0; | 366 | return 0; |
367 | } | 367 | } |
@@ -370,14 +370,14 @@ int ipc_client_handle_writable(int client_fd, uint32_t mask, void *data) { | |||
370 | return 0; | 370 | return 0; |
371 | } | 371 | } |
372 | 372 | ||
373 | wlr_log(L_DEBUG, "Client %d writable", client->fd); | 373 | wlr_log(WLR_DEBUG, "Client %d writable", client->fd); |
374 | 374 | ||
375 | ssize_t written = write(client->fd, client->write_buffer, client->write_buffer_len); | 375 | ssize_t written = write(client->fd, client->write_buffer, client->write_buffer_len); |
376 | 376 | ||
377 | if (written == -1 && errno == EAGAIN) { | 377 | if (written == -1 && errno == EAGAIN) { |
378 | return 0; | 378 | return 0; |
379 | } else if (written == -1) { | 379 | } else if (written == -1) { |
380 | wlr_log_errno(L_INFO, "Unable to send data from queue to IPC client"); | 380 | wlr_log_errno(WLR_INFO, "Unable to send data from queue to IPC client"); |
381 | ipc_client_disconnect(client); | 381 | ipc_client_disconnect(client); |
382 | return 0; | 382 | return 0; |
383 | } | 383 | } |
@@ -400,7 +400,7 @@ void ipc_client_disconnect(struct ipc_client *client) { | |||
400 | 400 | ||
401 | shutdown(client->fd, SHUT_RDWR); | 401 | shutdown(client->fd, SHUT_RDWR); |
402 | 402 | ||
403 | wlr_log(L_INFO, "IPC Client %d disconnected", client->fd); | 403 | wlr_log(WLR_INFO, "IPC Client %d disconnected", client->fd); |
404 | wl_event_source_remove(client->event_source); | 404 | wl_event_source_remove(client->event_source); |
405 | if (client->writable_event_source) { | 405 | if (client->writable_event_source) { |
406 | wl_event_source_remove(client->writable_event_source); | 406 | wl_event_source_remove(client->writable_event_source); |
@@ -461,7 +461,7 @@ void ipc_client_handle_command(struct ipc_client *client) { | |||
461 | 461 | ||
462 | char *buf = malloc(client->payload_length + 1); | 462 | char *buf = malloc(client->payload_length + 1); |
463 | if (!buf) { | 463 | if (!buf) { |
464 | wlr_log_errno(L_INFO, "Unable to allocate IPC payload"); | 464 | wlr_log_errno(WLR_INFO, "Unable to allocate IPC payload"); |
465 | ipc_client_disconnect(client); | 465 | ipc_client_disconnect(client); |
466 | return; | 466 | return; |
467 | } | 467 | } |
@@ -470,7 +470,7 @@ void ipc_client_handle_command(struct ipc_client *client) { | |||
470 | ssize_t received = recv(client->fd, buf, client->payload_length, 0); | 470 | ssize_t received = recv(client->fd, buf, client->payload_length, 0); |
471 | if (received == -1) | 471 | if (received == -1) |
472 | { | 472 | { |
473 | wlr_log_errno(L_INFO, "Unable to receive payload from IPC client"); | 473 | wlr_log_errno(WLR_INFO, "Unable to receive payload from IPC client"); |
474 | ipc_client_disconnect(client); | 474 | ipc_client_disconnect(client); |
475 | free(buf); | 475 | free(buf); |
476 | return; | 476 | return; |
@@ -533,7 +533,7 @@ void ipc_client_handle_command(struct ipc_client *client) { | |||
533 | struct json_object *request = json_tokener_parse(buf); | 533 | struct json_object *request = json_tokener_parse(buf); |
534 | if (request == NULL) { | 534 | if (request == NULL) { |
535 | client_valid = ipc_send_reply(client, "{\"success\": false}", 18); | 535 | client_valid = ipc_send_reply(client, "{\"success\": false}", 18); |
536 | wlr_log_errno(L_INFO, "Failed to read request"); | 536 | wlr_log_errno(WLR_INFO, "Failed to read request"); |
537 | goto exit_cleanup; | 537 | goto exit_cleanup; |
538 | } | 538 | } |
539 | 539 | ||
@@ -556,7 +556,7 @@ void ipc_client_handle_command(struct ipc_client *client) { | |||
556 | client_valid = | 556 | client_valid = |
557 | ipc_send_reply(client, "{\"success\": false}", 18); | 557 | ipc_send_reply(client, "{\"success\": false}", 18); |
558 | json_object_put(request); | 558 | json_object_put(request); |
559 | wlr_log_errno(L_INFO, "Failed to parse request"); | 559 | wlr_log_errno(WLR_INFO, "Failed to parse request"); |
560 | goto exit_cleanup; | 560 | goto exit_cleanup; |
561 | } | 561 | } |
562 | } | 562 | } |
@@ -668,7 +668,7 @@ void ipc_client_handle_command(struct ipc_client *client) { | |||
668 | } | 668 | } |
669 | 669 | ||
670 | default: | 670 | default: |
671 | wlr_log(L_INFO, "Unknown IPC command type %i", client->current_command); | 671 | wlr_log(WLR_INFO, "Unknown IPC command type %i", client->current_command); |
672 | goto exit_cleanup; | 672 | goto exit_cleanup; |
673 | } | 673 | } |
674 | 674 | ||
@@ -696,14 +696,14 @@ bool ipc_send_reply(struct ipc_client *client, const char *payload, uint32_t pay | |||
696 | } | 696 | } |
697 | 697 | ||
698 | if (client->write_buffer_size > 4e6) { // 4 MB | 698 | if (client->write_buffer_size > 4e6) { // 4 MB |
699 | wlr_log(L_ERROR, "Client write buffer too big, disconnecting client"); | 699 | wlr_log(WLR_ERROR, "Client write buffer too big, disconnecting client"); |
700 | ipc_client_disconnect(client); | 700 | ipc_client_disconnect(client); |
701 | return false; | 701 | return false; |
702 | } | 702 | } |
703 | 703 | ||
704 | char *new_buffer = realloc(client->write_buffer, client->write_buffer_size); | 704 | char *new_buffer = realloc(client->write_buffer, client->write_buffer_size); |
705 | if (!new_buffer) { | 705 | if (!new_buffer) { |
706 | wlr_log(L_ERROR, "Unable to reallocate ipc client write buffer"); | 706 | wlr_log(WLR_ERROR, "Unable to reallocate ipc client write buffer"); |
707 | ipc_client_disconnect(client); | 707 | ipc_client_disconnect(client); |
708 | return false; | 708 | return false; |
709 | } | 709 | } |
@@ -720,6 +720,6 @@ bool ipc_send_reply(struct ipc_client *client, const char *payload, uint32_t pay | |||
720 | ipc_client_handle_writable, client); | 720 | ipc_client_handle_writable, client); |
721 | } | 721 | } |
722 | 722 | ||
723 | wlr_log(L_DEBUG, "Added IPC reply to client %d queue: %s", client->fd, payload); | 723 | wlr_log(WLR_DEBUG, "Added IPC reply to client %d queue: %s", client->fd, payload); |
724 | return true; | 724 | return true; |
725 | } | 725 | } |