Skip to content

Commit

Permalink
mosquitto_loop_start() now sets a thread name.
Browse files Browse the repository at this point in the history
This applies on Linux, FreeBSD, NetBSD, and OpenBSD.

Closes #1777. Thanks to ABuch19.
  • Loading branch information
ralight committed Aug 10, 2020
1 parent ebb0f13 commit bd27935
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
2 changes: 2 additions & 0 deletions ChangeLog.txt
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions lib/thread_mosq.c
Expand Up @@ -20,6 +20,12 @@ and the Eclipse Distribution License is available at
#include <time.h>
#endif

#if defined(__linux__) || defined(__NetBSD__)
# include <pthread.h>
#elif defined(__FreeBSD__) || defined(__OpenBSD__)
# include <pthread_np.h>
#endif

#include "mosquitto_internal.h"
#include "net_mosq.h"
#include "util_mosq.h"
Expand All @@ -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;
Expand Down

0 comments on commit bd27935

Please sign in to comment.