From 64601b5f21d11cdc9391ad6a32fec6976b900613 Mon Sep 17 00:00:00 2001 From: Chewing_Bever Date: Thu, 1 Feb 2024 18:51:05 +0100 Subject: [PATCH] fix: use send instead of write to prevent SIGPIPE --- src/loop/lnm_loop_io.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/loop/lnm_loop_io.c b/src/loop/lnm_loop_io.c index 363d6af..34da2d9 100644 --- a/src/loop/lnm_loop_io.c +++ b/src/loop/lnm_loop_io.c @@ -1,6 +1,7 @@ #include #include #include +#include #include "lnm/loop.h" #include "lnm/loop_internal.h" @@ -43,7 +44,9 @@ void lnm_loop_conn_io_res(lnm_loop *l, lnm_loop_conn *conn) { ssize_t res; do { - res = write(conn->fd, conn->w.buf, conn->w.size); + // Send with MSG_NOSIGNAL prevents closed pipes from exiting the program + // with SIGPIPE + res = send(conn->fd, conn->w.buf, conn->w.size, MSG_NOSIGNAL); } while (res < 0 && errno == EINTR); // Write can't be performed without blocking; we come back later