]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
threading: simplify thread name logic
authorVictor Julien <vjulien@oisf.net>
Fri, 4 Mar 2022 13:31:24 +0000 (14:31 +0100)
committerVictor Julien <vjulien@oisf.net>
Tue, 12 Apr 2022 05:53:53 +0000 (07:53 +0200)
src/counters.c
src/suricata.c
src/threads.h
src/tm-threads.c

index 810b6c76de250a17c04547bd08d52c42f6f028c3..46fc79caa21fc6e6a9f475da5e67b999013e3c90 100644 (file)
@@ -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);
index 0b04e0db49f8d5eabce590d6d7307b8aa275d4eb..24ffa0fe64454554e84f83c18393a411256ee243 100644 (file)
@@ -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
index 535622f6a7291dd5467c5c423614260c987a68a8..d0cb125377f0bef74cb8e9a4bf5d45e01921413f 100644 (file)
@@ -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
index 48ce77bd6b2a4f8f08d494d6c60fd9b158a3f9bf..72fc2fc61e3c28ad845099b6e451f0867d27e0f1 100644 (file)
@@ -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);