From bd27935ff63613301e485c0ce9e7e9b4e67e6d07 Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Mon, 10 Aug 2020 22:51:17 +0100 Subject: [PATCH] `mosquitto_loop_start()` now sets a thread name. This applies on Linux, FreeBSD, NetBSD, and OpenBSD. Closes #1777. Thanks to ABuch19. --- ChangeLog.txt | 2 ++ lib/thread_mosq.c | 13 +++++++++++++ 2 files changed, 15 insertions(+) diff --git a/ChangeLog.txt b/ChangeLog.txt index 35336acaf0..e2da59c51b 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -25,6 +25,8 @@ Client library: - Improved documentation around connect callback return codes. Close #1730. - Fix `mosquitto_publish*()` no longer returning `MOSQ_ERR_NO_CONN` when not connected. Closes #1725. +- `mosquitto_loop_start()` now sets a thread name on Linux, FreeBSD, NetBSD, + and OpenBSD. Closes #1777. 1.6.10 - 2020-05-25 diff --git a/lib/thread_mosq.c b/lib/thread_mosq.c index d32e26face..a8cfa725ab 100644 --- a/lib/thread_mosq.c +++ b/lib/thread_mosq.c @@ -20,6 +20,12 @@ and the Eclipse Distribution License is available at #include #endif +#if defined(__linux__) || defined(__NetBSD__) +# include +#elif defined(__FreeBSD__) || defined(__OpenBSD__) +# include +#endif + #include "mosquitto_internal.h" #include "net_mosq.h" #include "util_mosq.h" @@ -33,6 +39,13 @@ int mosquitto_loop_start(struct mosquitto *mosq) mosq->threaded = mosq_ts_self; if(!pthread_create(&mosq->thread_id, NULL, mosquitto__thread_main, mosq)){ +#if defined(__linux__) + pthread_setname_np(mosq->thread_id, "mosquitto loop"); +#elif defined(__NetBSD__) + pthread_setname_np(mosq->thread_id, "%s", "mosquitto loop"); +#elif defined(__FreeBSD__) || defined(__OpenBSD__) + pthread_set_name_np(mosq->thread_id, "mosquitto loop"); +#endif return MOSQ_ERR_SUCCESS; }else{ return MOSQ_ERR_ERRNO;