From: Victor Julien Date: Fri, 4 Mar 2022 13:31:24 +0000 (+0100) Subject: threading: simplify thread name logic X-Git-Tag: suricata-7.0.0-beta1~753 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ce4e5437198c59e13b7020e063702d79b3c4c721;p=thirdparty%2Fsuricata.git threading: simplify thread name logic --- diff --git a/src/counters.c b/src/counters.c index 810b6c76de..46fc79caa2 100644 --- a/src/counters.c +++ b/src/counters.c @@ -366,10 +366,7 @@ static void *StatsMgmtThread(void *arg) { ThreadVars *tv_local = (ThreadVars *)arg; - /* Set the thread name */ - if (SCSetThreadName(tv_local->name) < 0) { - SCLogWarning(SC_ERR_THREAD_INIT, "Unable to set thread name"); - } + SCSetThreadName(tv_local->name); if (tv_local->thread_setup_flags != 0) TmThreadSetupOptions(tv_local); @@ -449,10 +446,7 @@ static void *StatsWakeupThread(void *arg) { ThreadVars *tv_local = (ThreadVars *)arg; - /* Set the thread name */ - if (SCSetThreadName(tv_local->name) < 0) { - SCLogWarning(SC_ERR_THREAD_INIT, "Unable to set thread name"); - } + SCSetThreadName(tv_local->name); if (tv_local->thread_setup_flags != 0) TmThreadSetupOptions(tv_local); diff --git a/src/suricata.c b/src/suricata.c index 0b04e0db49..24ffa0fe64 100644 --- a/src/suricata.c +++ b/src/suricata.c @@ -2815,7 +2815,7 @@ int InitGlobal(void) { /* initialize the logging subsys */ SCLogInitLogModule(NULL); - (void)SCSetThreadName("Suricata-Main"); + SCSetThreadName("Suricata-Main"); /* Ignore SIGUSR2 as early as possble. We redeclare interest * once we're done launching threads. The goal is to either die diff --git a/src/threads.h b/src/threads.h index 535622f6a7..d0cb125377 100644 --- a/src/threads.h +++ b/src/threads.h @@ -274,7 +274,6 @@ enum { SCLogDebug("Thread name is too long, truncating it..."); \ strlcpy(tname, n, 16); \ pthread_set_name_np(pthread_self(), tname); \ - 0; \ }) #elif defined __OpenBSD__ /* OpenBSD */ /** \todo Add implementation for OpenBSD */ @@ -289,16 +288,15 @@ enum { /** * \brief Set the threads name */ -#define SCSetThreadName(n) ({ \ - char tname[THREAD_NAME_LEN + 1] = ""; \ - if (strlen(n) > THREAD_NAME_LEN) \ - SCLogDebug("Thread name is too long, truncating it..."); \ - strlcpy(tname, n, THREAD_NAME_LEN); \ - int ret = 0; \ - if ((ret = prctl(PR_SET_NAME, tname, 0, 0, 0)) < 0) \ - SCLogDebug("Error setting thread name \"%s\": %s", tname, strerror(errno)); \ - ret; \ -}) +#define SCSetThreadName(n) \ + ({ \ + char tname[THREAD_NAME_LEN + 1] = ""; \ + if (strlen(n) > THREAD_NAME_LEN) \ + SCLogDebug("Thread name is too long, truncating it..."); \ + strlcpy(tname, n, THREAD_NAME_LEN); \ + if (prctl(PR_SET_NAME, tname, 0, 0, 0) < 0) \ + SCLogDebug("Error setting thread name \"%s\": %s", tname, strerror(errno)); \ + }) #else #define SCSetThreadName(n) (0) #endif diff --git a/src/tm-threads.c b/src/tm-threads.c index 48ce77bd6b..72fc2fc61e 100644 --- a/src/tm-threads.c +++ b/src/tm-threads.c @@ -228,10 +228,7 @@ static void *TmThreadsSlotPktAcqLoop(void *td) TmEcode r = TM_ECODE_OK; TmSlot *slot = NULL; - /* Set the thread name */ - if (SCSetThreadName(tv->name) < 0) { - SCLogWarning(SC_ERR_THREAD_INIT, "Unable to set thread name"); - } + SCSetThreadName(tv->name); if (tv->thread_setup_flags != 0) TmThreadSetupOptions(tv); @@ -370,10 +367,7 @@ static void *TmThreadsSlotVar(void *td) PacketPoolInit();//Empty(); - /* Set the thread name */ - if (SCSetThreadName(tv->name) < 0) { - SCLogWarning(SC_ERR_THREAD_INIT, "Unable to set thread name"); - } + SCSetThreadName(tv->name); if (tv->thread_setup_flags != 0) TmThreadSetupOptions(tv); @@ -521,10 +515,7 @@ static void *TmThreadsManagement(void *td) BUG_ON(s == NULL); - /* Set the thread name */ - if (SCSetThreadName(tv->name) < 0) { - SCLogWarning(SC_ERR_THREAD_INIT, "Unable to set thread name"); - } + SCSetThreadName(tv->name); if (tv->thread_setup_flags != 0) TmThreadSetupOptions(tv);