Skip to content

Instantly share code, notes, and snippets.

@Toasterson
Created May 7, 2024 13:08
Show Gist options
  • Save Toasterson/1453249045bbda6b3879742cc084af68 to your computer and use it in GitHub Desktop.
Save Toasterson/1453249045bbda6b3879742cc084af68 to your computer and use it in GitHub Desktop.
static inline void u_thread_setname( const char *name )
{
#if defined(HAVE_PTHREAD)
#if DETECT_OS_LINUX || DETECT_OS_CYGWIN
int ret = pthread_setname_np(pthread_self(), name);
if (ret == ERANGE) {
char buf[16];
const size_t len = MIN2(strlen(name), ARRAY_SIZE(buf) - 1);
memcpy(buf, name, len);
buf[len] = '\0';
pthread_setname_np(pthread_self(), buf);
}
#elif DETECT_OS_FREEBSD || DETECT_OS_OPENBSD
pthread_set_name_np(pthread_self(), name);
#elif DETECT_OS_NETBSD
pthread_setname_np(pthread_self(), "%s", (void *)name);
#elif DETECT_OS_APPLE
pthread_setname_np(name);
#elif DETECT_OS_HAIKU
rename_thread(find_thread(NULL), name);
#else
#warning Not sure how to call pthread_setname_np
#endif
#endif
(void)name;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment