]> git.sur5r.net Git - i3/i3/commitdiff
ipc: Correctly deal with SIGPIPE/failing write()s
authorMichael Stapelberg <michael@stapelberg.de>
Fri, 12 Mar 2010 14:02:00 +0000 (15:02 +0100)
committerMichael Stapelberg <michael@stapelberg.de>
Fri, 12 Mar 2010 14:02:00 +0000 (15:02 +0100)
If a client disconnects while i3 still wants to write the reply, this
could lead to exits of i3 before.

src/ipc.c
src/mainx.c

index 20e41219be16693c7a0acdab40744cd26c9e727e..629ec89d4624adfb3fc37afa4882e040f9e3438b 100644 (file)
--- a/src/ipc.c
+++ b/src/ipc.c
@@ -85,8 +85,10 @@ static void ipc_send_message(int fd, const unsigned char *payload,
         int bytes_to_go = buffer_size;
         while (sent_bytes < bytes_to_go) {
                 int n = write(fd, msg + sent_bytes, bytes_to_go);
-                if (n == -1)
-                        err(EXIT_FAILURE, "write() failed");
+                if (n == -1) {
+                        DLOG("write() failed: %s\n", strerror(errno));
+                        return;
+                }
 
                 sent_bytes += n;
                 bytes_to_go -= n;
index 8542ab22b59ff928db5e0c38763b995076ae4940..84df8b2e632d82c780cec8d4a007a3f5b83eb3f4 100644 (file)
@@ -527,6 +527,11 @@ int main(int argc, char *argv[], char *env[]) {
         xcb_check_cb(NULL, NULL, 0);
 
         setup_signal_handler();
+
+        /* Ignore SIGPIPE to survive errors when an IPC client disconnects
+         * while we are sending him a message */
+        signal(SIGPIPE, SIG_IGN);
+
         /* Ungrab the server to receive events and enter libev’s eventloop */
         xcb_ungrab_server(conn);