-
Notifications
You must be signed in to change notification settings - Fork 693
/
0001-Don-t-set-SIGPIPE-to-ignore-use-MSG_NOSIGNAL-instead.patch
67 lines (60 loc) · 1.77 KB
/
0001-Don-t-set-SIGPIPE-to-ignore-use-MSG_NOSIGNAL-instead.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
From 0c9d9f21633c5dbb482893a9d6bdf40111829925 Mon Sep 17 00:00:00 2001
From: "Roger A. Light" <[email protected]>
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.
---
lib/mosquitto.c | 4 ----
lib/net_mosq.c | 6 +-----
lib/net_mosq.h | 5 +++++
4 files changed, 7 insertions(+), 9 deletions(-)
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 <sys/socket.h>
# include <unistd.h>
#else
# include <winsock2.h>
@@ -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)