From 0c9d9f21633c5dbb482893a9d6bdf40111829925 Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Sun, 7 Aug 2022 23:04:46 +0100 Subject: [PATCH] Don't set SIGPIPE to ignore, use MSG_NOSIGNAL instead. Closes #2564. Thanks to nmeum. --- ChangeLog.txt | 1 + lib/mosquitto.c | 4 ---- lib/net_mosq.c | 6 +----- lib/net_mosq.h | 5 +++++ 4 files changed, 7 insertions(+), 9 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index c5618b5d..70557603 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -21,6 +21,7 @@ Client library: cmake version to 3.1, which is still ancient. - Fix use of `MOSQ_OPT_TLS_ENGINE` being unable to be used due to the openssl ctx not being initialised until starting to connect. Closes #2537. +- Don't set SIGPIPE to ignore, use MSG_NOSIGNAL instead. Closes #2564. Clients: - Fix mosquitto_pub incorrectly reusing topic aliases when reconnecting. diff --git a/lib/mosquitto.c b/lib/mosquitto.c index 0d68d313..72762ed6 100644 --- a/lib/mosquitto.c +++ b/lib/mosquitto.c @@ -109,10 +109,6 @@ struct mosquitto *mosquitto_new(const char *id, bool clean_start, void *userdata return NULL; } -#ifndef WIN32 - signal(SIGPIPE, SIG_IGN); -#endif - mosq = (struct mosquitto *)mosquitto__calloc(1, sizeof(struct mosquitto)); if(mosq){ mosq->sock = INVALID_SOCKET; diff --git a/lib/net_mosq.c b/lib/net_mosq.c index 22f5a313..d4eb89ef 100644 --- a/lib/net_mosq.c +++ b/lib/net_mosq.c @@ -1041,11 +1041,7 @@ ssize_t net__write(struct mosquitto *mosq, const void *buf, size_t count) /* Call normal write/send */ #endif -#ifndef WIN32 - return write(mosq->sock, buf, count); -#else - return send(mosq->sock, buf, count, 0); -#endif + return send(mosq->sock, buf, count, MSG_NOSIGNAL); #ifdef WITH_TLS } diff --git a/lib/net_mosq.h b/lib/net_mosq.h index 37a21461..ded98760 100644 --- a/lib/net_mosq.h +++ b/lib/net_mosq.h @@ -19,6 +19,7 @@ Contributors: #define NET_MOSQ_H #ifndef WIN32 +# include # include #else # include @@ -51,6 +52,10 @@ typedef SSIZE_T ssize_t; #define INVALID_SOCKET -1 #endif +#ifndef MSG_NOSIGNAL +# define MSG_NOSIGNAL 0 +#endif + /* Macros for accessing the MSB and LSB of a uint16_t */ #define MOSQ_MSB(A) (uint8_t)((A & 0xFF00) >> 8) #define MOSQ_LSB(A) (uint8_t)(A & 0x00FF)