From: Andrew Cooper Date: Mon, 25 Nov 2024 11:11:04 +0000 (+0100) Subject: tools/libxs: Stop playing with SIGPIPE X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=b6aa39f210d42168633a07f1c18f5d65f041ca09;p=people%2Fandrewcoop%2Fxen.git tools/libxs: Stop playing with SIGPIPE It's very rude for a library to play with signals behind the back of the application, no matter ones views on the default behaviour of SIGPIPE under POSIX. Even if the application doesn't care about the xenstored socket, it my care about others. This logic has existed since xenstore/xenstored was originally added in commit 29c9e570b1ed ("Add xenstore daemon and library") in 2005. It's also unnecessary. Pass MSG_NOSIGNAL when talking to xenstored over a pipe (to avoid sucumbing to SIGPIPE if xenstored has crashed), and forgo any playing with the signal disposition. This has a side benefit of saving 2 syscalls per xenstore request. Signed-off-by: Andrew Cooper Reviewed-by: Juergen Gross Reviewed-by: Jason Andryuk master commit: a17b6db9b00784b409c35e3017dc45aed1ec2bfb master date: 2024-07-23 15:11:27 +0100 --- diff --git a/tools/libs/store/xs.c b/tools/libs/store/xs.c index 0b62ec537f..7286a60fd0 100644 --- a/tools/libs/store/xs.c +++ b/tools/libs/store/xs.c @@ -613,7 +613,7 @@ static bool sendmsg_exact(int fd, struct iovec *iov, unsigned int nr) }; while (hdr.msg_iovlen) { - ssize_t res = sendmsg(fd, &hdr, 0); + ssize_t res = sendmsg(fd, &hdr, MSG_NOSIGNAL); if (res < 0 && errno == EINTR) continue; @@ -673,7 +673,6 @@ static void *xs_talkv(struct xs_handle *h, void *ret = NULL; int saved_errno; unsigned int i, msg_len; - struct sigaction ignorepipe, oldact; /* Element 0 must be xsd_sockmsg */ assert(num_vecs >= 1); @@ -690,11 +689,6 @@ static void *xs_talkv(struct xs_handle *h, msg->len = msg_len; - ignorepipe.sa_handler = SIG_IGN; - sigemptyset(&ignorepipe.sa_mask); - ignorepipe.sa_flags = 0; - sigaction(SIGPIPE, &ignorepipe, &oldact); - mutex_lock(&h->request_mutex); if (!write_request(h, iovec, num_vecs)) @@ -706,7 +700,6 @@ static void *xs_talkv(struct xs_handle *h, mutex_unlock(&h->request_mutex); - sigaction(SIGPIPE, &oldact, NULL); if (reply_type == XS_ERROR) { saved_errno = get_error(ret); free(ret); @@ -725,7 +718,6 @@ fail: /* We're in a bad state, so close fd. */ saved_errno = errno; mutex_unlock(&h->request_mutex); - sigaction(SIGPIPE, &oldact, NULL); close_fd: close(h->fd); h->fd = -1;