Skip to content

Commit

Permalink
Don't set SIGPIPE to ignore, use MSG_NOSIGNAL instead.
Browse files Browse the repository at this point in the history
Closes #2564. Thanks to nmeum.
  • Loading branch information
ralight committed Aug 7, 2022
1 parent 8c0600c commit 0c9d9f2
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 9 deletions.
1 change: 1 addition & 0 deletions ChangeLog.txt
Expand Up @@ -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.
Expand Down
4 changes: 0 additions & 4 deletions lib/mosquitto.c
Expand Up @@ -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;
Expand Down
6 changes: 1 addition & 5 deletions lib/net_mosq.c
Expand Up @@ -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
}
Expand Down
5 changes: 5 additions & 0 deletions lib/net_mosq.h
Expand Up @@ -19,6 +19,7 @@ SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
#define NET_MOSQ_H

#ifndef WIN32
# include <sys/socket.h>
# include <unistd.h>
#else
# include <winsock2.h>
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 0c9d9f2

Please sign in to comment.