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.
This commit is contained in:
parent
0f5256dc72
commit
5a3d1b38e8
@ -85,8 +85,10 @@ static void ipc_send_message(int fd, const unsigned char *payload,
|
|||||||
int bytes_to_go = buffer_size;
|
int bytes_to_go = buffer_size;
|
||||||
while (sent_bytes < bytes_to_go) {
|
while (sent_bytes < bytes_to_go) {
|
||||||
int n = write(fd, msg + sent_bytes, bytes_to_go);
|
int n = write(fd, msg + sent_bytes, bytes_to_go);
|
||||||
if (n == -1)
|
if (n == -1) {
|
||||||
err(EXIT_FAILURE, "write() failed");
|
DLOG("write() failed: %s\n", strerror(errno));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
sent_bytes += n;
|
sent_bytes += n;
|
||||||
bytes_to_go -= n;
|
bytes_to_go -= n;
|
||||||
|
@ -527,6 +527,11 @@ int main(int argc, char *argv[], char *env[]) {
|
|||||||
xcb_check_cb(NULL, NULL, 0);
|
xcb_check_cb(NULL, NULL, 0);
|
||||||
|
|
||||||
setup_signal_handler();
|
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 */
|
/* Ungrab the server to receive events and enter libev’s eventloop */
|
||||||
xcb_ungrab_server(conn);
|
xcb_ungrab_server(conn);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user