tree 8ced78ef8f6addfc07063569de32a5003d52dfc4
parent 33c718759316f2252eda217db5fdab1df09f58cd
author Hannes Reinecke <hare@suse.de> 1173949216 +0100
committer Hannes Reinecke <hare@suse.de> 1173949216 +0100

[libmultipath] block SIGPIPE before writing to a pipe

We have to block SIGPIPE before we're writing to the communication
pipe otherwise the daemon will be killed if the listening program
terminates prematurely.

Signed-off-by: Hannes Reinecke <hare@suse.de>
96872c26aa434b4611dbc46b14fbb79eeda2b81c
 libmultipath/uxsock.c |   23 ++++++++++++++++++++---
 1 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/libmultipath/uxsock.c b/libmultipath/uxsock.c
index abb9f85..cdc3dbc 100644
--- a/libmultipath/uxsock.c
+++ b/libmultipath/uxsock.c
@@ -14,6 +14,7 @@ #include <sys/types.h>
 #include <sys/socket.h>
 #include <sys/un.h>
 #include <sys/poll.h>
+#include <signal.h>
 #include <errno.h>
 
 #include "memory.h"
@@ -127,9 +128,25 @@ size_t read_all(int fd, void *buf, size_
  */
 int send_packet(int fd, const char *buf, size_t len)
 {
-	if (write_all(fd, &len, sizeof(len)) != sizeof(len)) return -1;
-	if (write_all(fd, buf, len) != len) return -1;	
-	return 0;
+	int ret = 0;
+#ifdef DAEMON
+	sigset_t set, old;
+
+	/* Block SIGPIPE */
+	sigemptyset(&set);
+	sigaddset(&set, SIGPIPE);
+	pthread_sigmask(SIG_BLOCK, &set, &old);
+#endif	
+	if (write_all(fd, &len, sizeof(len)) != sizeof(len)) 
+		ret = -1;
+	if (!ret && write_all(fd, buf, len) != len)
+		ret = -1;	
+
+#ifdef DAEMON
+	/* And unblock it again */
+	pthread_sigmask(SIG_SETMASK, &old, NULL);
+#endif	
+	return ret;
 }
 
 /*
