aboutsummaryrefslogtreecommitdiffstats
path: root/sway/ipc-server.c
diff options
context:
space:
mode:
authorLibravatar Dominique Martinet <asmadeus@codewreck.org>2018-01-05 22:32:51 +0100
committerLibravatar Dominique Martinet <asmadeus@codewreck.org>2018-01-05 23:39:46 +0100
commit67985e903188a464e602d04f9ed218bd397f5ab1 (patch)
tree3589175749c9a2ed746b0cc280ab3ccfb33125e9 /sway/ipc-server.c
parentMerge pull request #1554 from martinetd/cmd_set (diff)
downloadsway-67985e903188a464e602d04f9ed218bd397f5ab1.tar.gz
sway-67985e903188a464e602d04f9ed218bd397f5ab1.tar.zst
sway-67985e903188a464e602d04f9ed218bd397f5ab1.zip
sway: change all sway_log to wlr_log
Diffstat (limited to 'sway/ipc-server.c')
-rw-r--r--sway/ipc-server.c50
1 files changed, 25 insertions, 25 deletions
diff --git a/sway/ipc-server.c b/sway/ipc-server.c
index 046e40a8..d2dd881f 100644
--- a/sway/ipc-server.c
+++ b/sway/ipc-server.c
@@ -125,32 +125,32 @@ struct sockaddr_un *ipc_user_sockaddr(void) {
125int ipc_handle_connection(int fd, uint32_t mask, void *data) { 125int ipc_handle_connection(int fd, uint32_t mask, void *data) {
126 (void) fd; 126 (void) fd;
127 struct sway_server *server = data; 127 struct sway_server *server = data;
128 sway_log(L_DEBUG, "Event on IPC listening socket"); 128 wlr_log(L_DEBUG, "Event on IPC listening socket");
129 assert(mask == WL_EVENT_READABLE); 129 assert(mask == WL_EVENT_READABLE);
130 130
131 int client_fd = accept(ipc_socket, NULL, NULL); 131 int client_fd = accept(ipc_socket, NULL, NULL);
132 if (client_fd == -1) { 132 if (client_fd == -1) {
133 sway_log_errno(L_ERROR, "Unable to accept IPC client connection"); 133 wlr_log_errno(L_ERROR, "Unable to accept IPC client connection");
134 return 0; 134 return 0;
135 } 135 }
136 136
137 int flags; 137 int flags;
138 if ((flags = fcntl(client_fd, F_GETFD)) == -1 138 if ((flags = fcntl(client_fd, F_GETFD)) == -1
139 || fcntl(client_fd, F_SETFD, flags|FD_CLOEXEC) == -1) { 139 || fcntl(client_fd, F_SETFD, flags|FD_CLOEXEC) == -1) {
140 sway_log_errno(L_ERROR, "Unable to set CLOEXEC on IPC client socket"); 140 wlr_log_errno(L_ERROR, "Unable to set CLOEXEC on IPC client socket");
141 close(client_fd); 141 close(client_fd);
142 return 0; 142 return 0;
143 } 143 }
144 if ((flags = fcntl(client_fd, F_GETFL)) == -1 144 if ((flags = fcntl(client_fd, F_GETFL)) == -1
145 || fcntl(client_fd, F_SETFL, flags|O_NONBLOCK) == -1) { 145 || fcntl(client_fd, F_SETFL, flags|O_NONBLOCK) == -1) {
146 sway_log_errno(L_ERROR, "Unable to set NONBLOCK on IPC client socket"); 146 wlr_log_errno(L_ERROR, "Unable to set NONBLOCK on IPC client socket");
147 close(client_fd); 147 close(client_fd);
148 return 0; 148 return 0;
149 } 149 }
150 150
151 struct ipc_client *client = malloc(sizeof(struct ipc_client)); 151 struct ipc_client *client = malloc(sizeof(struct ipc_client));
152 if (!client) { 152 if (!client) {
153 sway_log(L_ERROR, "Unable to allocate ipc client"); 153 wlr_log(L_ERROR, "Unable to allocate ipc client");
154 close(client_fd); 154 close(client_fd);
155 return 0; 155 return 0;
156 } 156 }
@@ -166,12 +166,12 @@ int ipc_handle_connection(int fd, uint32_t mask, void *data) {
166 client->write_buffer_len = 0; 166 client->write_buffer_len = 0;
167 client->write_buffer = malloc(client->write_buffer_size); 167 client->write_buffer = malloc(client->write_buffer_size);
168 if (!client->write_buffer) { 168 if (!client->write_buffer) {
169 sway_log(L_ERROR, "Unable to allocate ipc client write buffer"); 169 wlr_log(L_ERROR, "Unable to allocate ipc client write buffer");
170 close(client_fd); 170 close(client_fd);
171 return 0; 171 return 0;
172 } 172 }
173 173
174 sway_log(L_DEBUG, "New client: fd %d", client_fd); 174 wlr_log(L_DEBUG, "New client: fd %d", client_fd);
175 list_add(ipc_client_list, client); 175 list_add(ipc_client_list, client);
176 return 0; 176 return 0;
177} 177}
@@ -182,22 +182,22 @@ int ipc_client_handle_readable(int client_fd, uint32_t mask, void *data) {
182 struct ipc_client *client = data; 182 struct ipc_client *client = data;
183 183
184 if (mask & WL_EVENT_ERROR) { 184 if (mask & WL_EVENT_ERROR) {
185 sway_log(L_ERROR, "IPC Client socket error, removing client"); 185 wlr_log(L_ERROR, "IPC Client socket error, removing client");
186 ipc_client_disconnect(client); 186 ipc_client_disconnect(client);
187 return 0; 187 return 0;
188 } 188 }
189 189
190 if (mask & WL_EVENT_HANGUP) { 190 if (mask & WL_EVENT_HANGUP) {
191 sway_log(L_DEBUG, "Client %d hung up", client->fd); 191 wlr_log(L_DEBUG, "Client %d hung up", client->fd);
192 ipc_client_disconnect(client); 192 ipc_client_disconnect(client);
193 return 0; 193 return 0;
194 } 194 }
195 195
196 sway_log(L_DEBUG, "Client %d readable", client->fd); 196 wlr_log(L_DEBUG, "Client %d readable", client->fd);
197 197
198 int read_available; 198 int read_available;
199 if (ioctl(client_fd, FIONREAD, &read_available) == -1) { 199 if (ioctl(client_fd, FIONREAD, &read_available) == -1) {
200 sway_log_errno(L_INFO, "Unable to read IPC socket buffer size"); 200 wlr_log_errno(L_INFO, "Unable to read IPC socket buffer size");
201 ipc_client_disconnect(client); 201 ipc_client_disconnect(client);
202 return 0; 202 return 0;
203 } 203 }
@@ -219,13 +219,13 @@ int ipc_client_handle_readable(int client_fd, uint32_t mask, void *data) {
219 // Should be fully available, because read_available >= ipc_header_size 219 // Should be fully available, because read_available >= ipc_header_size
220 ssize_t received = recv(client_fd, buf, ipc_header_size, 0); 220 ssize_t received = recv(client_fd, buf, ipc_header_size, 0);
221 if (received == -1) { 221 if (received == -1) {
222 sway_log_errno(L_INFO, "Unable to receive header from IPC client"); 222 wlr_log_errno(L_INFO, "Unable to receive header from IPC client");
223 ipc_client_disconnect(client); 223 ipc_client_disconnect(client);
224 return 0; 224 return 0;
225 } 225 }
226 226
227 if (memcmp(buf, ipc_magic, sizeof(ipc_magic)) != 0) { 227 if (memcmp(buf, ipc_magic, sizeof(ipc_magic)) != 0) {
228 sway_log(L_DEBUG, "IPC header check failed"); 228 wlr_log(L_DEBUG, "IPC header check failed");
229 ipc_client_disconnect(client); 229 ipc_client_disconnect(client);
230 return 0; 230 return 0;
231 } 231 }
@@ -244,13 +244,13 @@ int ipc_client_handle_writable(int client_fd, uint32_t mask, void *data) {
244 struct ipc_client *client = data; 244 struct ipc_client *client = data;
245 245
246 if (mask & WL_EVENT_ERROR) { 246 if (mask & WL_EVENT_ERROR) {
247 sway_log(L_ERROR, "IPC Client socket error, removing client"); 247 wlr_log(L_ERROR, "IPC Client socket error, removing client");
248 ipc_client_disconnect(client); 248 ipc_client_disconnect(client);
249 return 0; 249 return 0;
250 } 250 }
251 251
252 if (mask & WL_EVENT_HANGUP) { 252 if (mask & WL_EVENT_HANGUP) {
253 sway_log(L_DEBUG, "Client %d hung up", client->fd); 253 wlr_log(L_DEBUG, "Client %d hung up", client->fd);
254 ipc_client_disconnect(client); 254 ipc_client_disconnect(client);
255 return 0; 255 return 0;
256 } 256 }
@@ -259,14 +259,14 @@ int ipc_client_handle_writable(int client_fd, uint32_t mask, void *data) {
259 return 0; 259 return 0;
260 } 260 }
261 261
262 sway_log(L_DEBUG, "Client %d writable", client->fd); 262 wlr_log(L_DEBUG, "Client %d writable", client->fd);
263 263
264 ssize_t written = write(client->fd, client->write_buffer, client->write_buffer_len); 264 ssize_t written = write(client->fd, client->write_buffer, client->write_buffer_len);
265 265
266 if (written == -1 && errno == EAGAIN) { 266 if (written == -1 && errno == EAGAIN) {
267 return 0; 267 return 0;
268 } else if (written == -1) { 268 } else if (written == -1) {
269 sway_log_errno(L_INFO, "Unable to send data from queue to IPC client"); 269 wlr_log_errno(L_INFO, "Unable to send data from queue to IPC client");
270 ipc_client_disconnect(client); 270 ipc_client_disconnect(client);
271 return 0; 271 return 0;
272 } 272 }
@@ -291,7 +291,7 @@ void ipc_client_disconnect(struct ipc_client *client) {
291 shutdown(client->fd, SHUT_RDWR); 291 shutdown(client->fd, SHUT_RDWR);
292 } 292 }
293 293
294 sway_log(L_INFO, "IPC Client %d disconnected", client->fd); 294 wlr_log(L_INFO, "IPC Client %d disconnected", client->fd);
295 wl_event_source_remove(client->event_source); 295 wl_event_source_remove(client->event_source);
296 if (client->writable_event_source) { 296 if (client->writable_event_source) {
297 wl_event_source_remove(client->writable_event_source); 297 wl_event_source_remove(client->writable_event_source);
@@ -313,7 +313,7 @@ void ipc_client_handle_command(struct ipc_client *client) {
313 313
314 char *buf = malloc(client->payload_length + 1); 314 char *buf = malloc(client->payload_length + 1);
315 if (!buf) { 315 if (!buf) {
316 sway_log_errno(L_INFO, "Unable to allocate IPC payload"); 316 wlr_log_errno(L_INFO, "Unable to allocate IPC payload");
317 ipc_client_disconnect(client); 317 ipc_client_disconnect(client);
318 return; 318 return;
319 } 319 }
@@ -322,7 +322,7 @@ void ipc_client_handle_command(struct ipc_client *client) {
322 ssize_t received = recv(client->fd, buf, client->payload_length, 0); 322 ssize_t received = recv(client->fd, buf, client->payload_length, 0);
323 if (received == -1) 323 if (received == -1)
324 { 324 {
325 sway_log_errno(L_INFO, "Unable to receive payload from IPC client"); 325 wlr_log_errno(L_INFO, "Unable to receive payload from IPC client");
326 ipc_client_disconnect(client); 326 ipc_client_disconnect(client);
327 free(buf); 327 free(buf);
328 return; 328 return;
@@ -393,12 +393,12 @@ void ipc_client_handle_command(struct ipc_client *client) {
393 } 393 }
394 394
395 default: 395 default:
396 sway_log(L_INFO, "Unknown IPC command type %i", client->current_command); 396 wlr_log(L_INFO, "Unknown IPC command type %i", client->current_command);
397 goto exit_cleanup; 397 goto exit_cleanup;
398 } 398 }
399 399
400 ipc_send_reply(client, error_denied, (uint32_t)strlen(error_denied)); 400 ipc_send_reply(client, error_denied, (uint32_t)strlen(error_denied));
401 sway_log(L_DEBUG, "Denied IPC client access to %i", client->current_command); 401 wlr_log(L_DEBUG, "Denied IPC client access to %i", client->current_command);
402 402
403exit_cleanup: 403exit_cleanup:
404 client->payload_length = 0; 404 client->payload_length = 0;
@@ -422,14 +422,14 @@ bool ipc_send_reply(struct ipc_client *client, const char *payload, uint32_t pay
422 } 422 }
423 423
424 if (client->write_buffer_size > 4e6) { // 4 MB 424 if (client->write_buffer_size > 4e6) { // 4 MB
425 sway_log(L_ERROR, "Client write buffer too big, disconnecting client"); 425 wlr_log(L_ERROR, "Client write buffer too big, disconnecting client");
426 ipc_client_disconnect(client); 426 ipc_client_disconnect(client);
427 return false; 427 return false;
428 } 428 }
429 429
430 char *new_buffer = realloc(client->write_buffer, client->write_buffer_size); 430 char *new_buffer = realloc(client->write_buffer, client->write_buffer_size);
431 if (!new_buffer) { 431 if (!new_buffer) {
432 sway_log(L_ERROR, "Unable to reallocate ipc client write buffer"); 432 wlr_log(L_ERROR, "Unable to reallocate ipc client write buffer");
433 ipc_client_disconnect(client); 433 ipc_client_disconnect(client);
434 return false; 434 return false;
435 } 435 }
@@ -446,6 +446,6 @@ bool ipc_send_reply(struct ipc_client *client, const char *payload, uint32_t pay
446 ipc_client_handle_writable, client); 446 ipc_client_handle_writable, client);
447 } 447 }
448 448
449 sway_log(L_DEBUG, "Added IPC reply to client %d queue: %s", client->fd, payload); 449 wlr_log(L_DEBUG, "Added IPC reply to client %d queue: %s", client->fd, payload);
450 return true; 450 return true;
451} 451}