From: Michael Stapelberg Date: Fri, 12 Mar 2010 14:02:00 +0000 (+0100) Subject: ipc: Correctly deal with SIGPIPE/failing write()s X-Git-Tag: 3.e~6^2~88 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=5a3d1b38e8e67c11a20ff7ce7d40d0d464b8f702;p=i3%2Fi3 ipc: Correctly deal with SIGPIPE/failing write()s If a client disconnects while i3 still wants to write the reply, this could lead to exits of i3 before. --- diff --git a/src/ipc.c b/src/ipc.c index 20e41219..629ec89d 100644 --- 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; diff --git a/src/mainx.c b/src/mainx.c index 8542ab22..84df8b2e 100644 --- a/src/mainx.c +++ b/src/mainx.c @@ -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);