From b3c2ac20dc5fdaac75baa046134d716e0f5ae846 Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Tue, 11 Aug 2020 11:02:38 +0100 Subject: [PATCH] Fix overly broad HAVE_PTHREAD_CANCEL compile guard. Closes #1547. Thanks to Markus Gothe. --- ChangeLog.txt | 1 + lib/loop.c | 4 ++++ lib/thread_mosq.c | 6 ++++-- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index 06f9b974..9b64ffe9 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -26,6 +26,7 @@ Broker: - Fix potential memory leaks. Closes #1773. Closes #1774. - Fix clients not receiving messages after a previous client with the same client ID and positive will delay interval quit. Closes #1752. +- Fix overly broad HAVE_PTHREAD_CANCEL compile guard. Closes #1547. Client library: - Improved documentation around connect callback return codes. Close #1730. diff --git a/lib/loop.c b/lib/loop.c index f7b26a0f..a3773b0a 100644 --- a/lib/loop.c +++ b/lib/loop.c @@ -256,7 +256,9 @@ int mosquitto_loop_forever(struct mosquitto *mosq, int timeout, int max_packets) while(run){ do{ +#ifdef HAVE_PTHREAD_CANCEL pthread_testcancel(); +#endif rc = mosquitto_loop(mosq, timeout, max_packets); }while(run && rc == MOSQ_ERR_SUCCESS); /* Quit after fatal errors. */ @@ -281,7 +283,9 @@ int mosquitto_loop_forever(struct mosquitto *mosq, int timeout, int max_packets) return rc; } do{ +#ifdef HAVE_PTHREAD_CANCEL pthread_testcancel(); +#endif rc = MOSQ_ERR_SUCCESS; state = mosquitto__get_state(mosq); if(state == mosq_cs_disconnecting || state == mosq_cs_disconnected){ diff --git a/lib/thread_mosq.c b/lib/thread_mosq.c index a8cfa725..b05c1d2a 100644 --- a/lib/thread_mosq.c +++ b/lib/thread_mosq.c @@ -34,7 +34,7 @@ void *mosquitto__thread_main(void *obj); int mosquitto_loop_start(struct mosquitto *mosq) { -#if defined(WITH_THREADING) && defined(HAVE_PTHREAD_CANCEL) +#if defined(WITH_THREADING) if(!mosq || mosq->threaded != mosq_ts_none) return MOSQ_ERR_INVAL; mosq->threaded = mosq_ts_self; @@ -57,7 +57,7 @@ int mosquitto_loop_start(struct mosquitto *mosq) int mosquitto_loop_stop(struct mosquitto *mosq, bool force) { -#if defined(WITH_THREADING) && defined(HAVE_PTHREAD_CANCEL) +#if defined(WITH_THREADING) # ifndef WITH_BROKER char sockpair_data = 0; # endif @@ -76,9 +76,11 @@ int mosquitto_loop_stop(struct mosquitto *mosq, bool force) #endif } +#ifdef HAVE_PTHREAD_CANCEL if(force){ pthread_cancel(mosq->thread_id); } +#endif pthread_join(mosq->thread_id, NULL); mosq->thread_id = pthread_self(); mosq->threaded = mosq_ts_none;