From 50a31a6c88cf29d0ce43ded49ec5c10e6f59f4bf Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Fri, 7 Apr 2017 07:55:35 -0400 Subject: [PATCH 1/2] Fix dangling file descriptors (fixes #1152) --- sway/ipc-server.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/sway/ipc-server.c b/sway/ipc-server.c index 0cacc5159..3600cab25 100644 --- a/sway/ipc-server.c +++ b/sway/ipc-server.c @@ -161,7 +161,8 @@ int ipc_handle_connection(int fd, uint32_t mask, void *data) { } int flags; - if ((flags=fcntl(client_fd, F_GETFD)) == -1 || fcntl(client_fd, F_SETFD, flags|FD_CLOEXEC) == -1) { + if ((flags = fcntl(client_fd, F_GETFD)) == -1 + || fcntl(client_fd, F_SETFD, flags|FD_CLOEXEC) == -1) { sway_log_errno(L_ERROR, "Unable to set CLOEXEC on IPC client socket"); close(client_fd); return 0; @@ -199,6 +200,8 @@ int ipc_client_handle_readable(int client_fd, uint32_t mask, void *data) { } if (mask & WLC_EVENT_HANGUP) { + sway_log(L_DEBUG, "Client %d hung up", client->fd); + close(client->fd); client->fd = -1; ipc_client_disconnect(client); return 0; From 1b2cd93212508913451fe6b9549f4b172925a4f6 Mon Sep 17 00:00:00 2001 From: Scott Anderson Date: Sat, 8 Apr 2017 00:45:31 +1200 Subject: [PATCH 2/2] Removed explicitly setting file descriptors to -1 --- sway/ipc-server.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/sway/ipc-server.c b/sway/ipc-server.c index 3600cab25..984e67548 100644 --- a/sway/ipc-server.c +++ b/sway/ipc-server.c @@ -194,15 +194,12 @@ int ipc_client_handle_readable(int client_fd, uint32_t mask, void *data) { if (mask & WLC_EVENT_ERROR) { sway_log(L_ERROR, "IPC Client socket error, removing client"); - client->fd = -1; ipc_client_disconnect(client); return 0; } if (mask & WLC_EVENT_HANGUP) { sway_log(L_DEBUG, "Client %d hung up", client->fd); - close(client->fd); - client->fd = -1; ipc_client_disconnect(client); return 0; }