threading: simplify thread name logic

pull/7242/head
Victor Julien 4 years ago
parent 93d5bce0aa
commit ce4e543719

@ -366,10 +366,7 @@ static void *StatsMgmtThread(void *arg)
{ {
ThreadVars *tv_local = (ThreadVars *)arg; ThreadVars *tv_local = (ThreadVars *)arg;
/* Set the thread name */ SCSetThreadName(tv_local->name);
if (SCSetThreadName(tv_local->name) < 0) {
SCLogWarning(SC_ERR_THREAD_INIT, "Unable to set thread name");
}
if (tv_local->thread_setup_flags != 0) if (tv_local->thread_setup_flags != 0)
TmThreadSetupOptions(tv_local); TmThreadSetupOptions(tv_local);
@ -449,10 +446,7 @@ static void *StatsWakeupThread(void *arg)
{ {
ThreadVars *tv_local = (ThreadVars *)arg; ThreadVars *tv_local = (ThreadVars *)arg;
/* Set the thread name */ SCSetThreadName(tv_local->name);
if (SCSetThreadName(tv_local->name) < 0) {
SCLogWarning(SC_ERR_THREAD_INIT, "Unable to set thread name");
}
if (tv_local->thread_setup_flags != 0) if (tv_local->thread_setup_flags != 0)
TmThreadSetupOptions(tv_local); TmThreadSetupOptions(tv_local);

@ -2815,7 +2815,7 @@ int InitGlobal(void) {
/* initialize the logging subsys */ /* initialize the logging subsys */
SCLogInitLogModule(NULL); SCLogInitLogModule(NULL);
(void)SCSetThreadName("Suricata-Main"); SCSetThreadName("Suricata-Main");
/* Ignore SIGUSR2 as early as possble. We redeclare interest /* Ignore SIGUSR2 as early as possble. We redeclare interest
* once we're done launching threads. The goal is to either die * once we're done launching threads. The goal is to either die

@ -274,7 +274,6 @@ enum {
SCLogDebug("Thread name is too long, truncating it..."); \ SCLogDebug("Thread name is too long, truncating it..."); \
strlcpy(tname, n, 16); \ strlcpy(tname, n, 16); \
pthread_set_name_np(pthread_self(), tname); \ pthread_set_name_np(pthread_self(), tname); \
0; \
}) })
#elif defined __OpenBSD__ /* OpenBSD */ #elif defined __OpenBSD__ /* OpenBSD */
/** \todo Add implementation for OpenBSD */ /** \todo Add implementation for OpenBSD */
@ -289,16 +288,15 @@ enum {
/** /**
* \brief Set the threads name * \brief Set the threads name
*/ */
#define SCSetThreadName(n) ({ \ #define SCSetThreadName(n) \
char tname[THREAD_NAME_LEN + 1] = ""; \ ({ \
if (strlen(n) > THREAD_NAME_LEN) \ char tname[THREAD_NAME_LEN + 1] = ""; \
SCLogDebug("Thread name is too long, truncating it..."); \ if (strlen(n) > THREAD_NAME_LEN) \
strlcpy(tname, n, THREAD_NAME_LEN); \ SCLogDebug("Thread name is too long, truncating it..."); \
int ret = 0; \ strlcpy(tname, n, THREAD_NAME_LEN); \
if ((ret = prctl(PR_SET_NAME, tname, 0, 0, 0)) < 0) \ if (prctl(PR_SET_NAME, tname, 0, 0, 0) < 0) \
SCLogDebug("Error setting thread name \"%s\": %s", tname, strerror(errno)); \ SCLogDebug("Error setting thread name \"%s\": %s", tname, strerror(errno)); \
ret; \ })
})
#else #else
#define SCSetThreadName(n) (0) #define SCSetThreadName(n) (0)
#endif #endif

@ -228,10 +228,7 @@ static void *TmThreadsSlotPktAcqLoop(void *td)
TmEcode r = TM_ECODE_OK; TmEcode r = TM_ECODE_OK;
TmSlot *slot = NULL; TmSlot *slot = NULL;
/* Set the thread name */ SCSetThreadName(tv->name);
if (SCSetThreadName(tv->name) < 0) {
SCLogWarning(SC_ERR_THREAD_INIT, "Unable to set thread name");
}
if (tv->thread_setup_flags != 0) if (tv->thread_setup_flags != 0)
TmThreadSetupOptions(tv); TmThreadSetupOptions(tv);
@ -370,10 +367,7 @@ static void *TmThreadsSlotVar(void *td)
PacketPoolInit();//Empty(); PacketPoolInit();//Empty();
/* Set the thread name */ SCSetThreadName(tv->name);
if (SCSetThreadName(tv->name) < 0) {
SCLogWarning(SC_ERR_THREAD_INIT, "Unable to set thread name");
}
if (tv->thread_setup_flags != 0) if (tv->thread_setup_flags != 0)
TmThreadSetupOptions(tv); TmThreadSetupOptions(tv);
@ -521,10 +515,7 @@ static void *TmThreadsManagement(void *td)
BUG_ON(s == NULL); BUG_ON(s == NULL);
/* Set the thread name */ SCSetThreadName(tv->name);
if (SCSetThreadName(tv->name) < 0) {
SCLogWarning(SC_ERR_THREAD_INIT, "Unable to set thread name");
}
if (tv->thread_setup_flags != 0) if (tv->thread_setup_flags != 0)
TmThreadSetupOptions(tv); TmThreadSetupOptions(tv);

Loading…
Cancel
Save