]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
unix-manager: fix race condition
authorEric Leblond <eric@regit.org>
Mon, 14 Dec 2015 13:02:20 +0000 (14:02 +0100)
committerVictor Julien <victor@inliniac.net>
Thu, 17 Dec 2015 15:28:44 +0000 (16:28 +0100)
Under high load it is possible that the thread is not yet started
and that we register a command at the same time. As a consequence,
the commands list is not yet initialized and we have a segfault.

This patch moves the initialization in the ThreadInit function to
be sure the commands list is available when needed.

src/unix-manager.c

index 9357f4c50453d03ad4392101271a195481281695..ca92677bab50970919b4fe793a4da418b4ee7019 100644 (file)
@@ -851,25 +851,6 @@ static TmEcode UnixManagerThreadInit(ThreadVars *t, void *initdata, void **data)
     if (utd == NULL)
         return TM_ECODE_FAILED;
 
-    *data = utd;
-    return TM_ECODE_OK;
-}
-
-static TmEcode UnixManagerThreadDeinit(ThreadVars *t, void *data)
-{
-    SCFree(data);
-    return TM_ECODE_OK;
-}
-
-static TmEcode UnixManager(ThreadVars *th_v, void *thread_data)
-{
-    int ret;
-
-    /* set the thread name */
-    SCLogDebug("%s started...", th_v->name);
-
-    StatsSetupPrivate(th_v);
-
     if (UnixNew(&command) == 0) {
         int failure_fatal = 0;
         SCLogError(SC_ERR_INITIALIZATION,
@@ -884,10 +865,6 @@ static TmEcode UnixManager(ThreadVars *th_v, void *thread_data)
         }
     }
 
-    /* Set the threads capability */
-    th_v->cap_flags = 0;
-    SCDropCaps(th_v);
-
     /* Init Unix socket */
     UnixManagerRegisterCommand("shutdown", UnixManagerShutdownCommand, NULL, 0);
     UnixManagerRegisterCommand("command-list", UnixManagerListCommand, &command, 0);
@@ -905,6 +882,28 @@ static TmEcode UnixManager(ThreadVars *th_v, void *thread_data)
     UnixManagerRegisterCommand("reload-tenant", UnixSocketReloadTenant, &command, UNIX_CMD_TAKE_ARGS);
     UnixManagerRegisterCommand("unregister-tenant", UnixSocketUnregisterTenant, &command, UNIX_CMD_TAKE_ARGS);
 
+    *data = utd;
+    return TM_ECODE_OK;
+}
+
+static TmEcode UnixManagerThreadDeinit(ThreadVars *t, void *data)
+{
+    SCFree(data);
+    return TM_ECODE_OK;
+}
+
+static TmEcode UnixManager(ThreadVars *th_v, void *thread_data)
+{
+    int ret;
+
+    /* set the thread name */
+    SCLogDebug("%s started...", th_v->name);
+
+    StatsSetupPrivate(th_v);
+
+    /* Set the threads capability */
+    th_v->cap_flags = 0;
+    SCDropCaps(th_v);
 
     TmThreadsSetFlag(th_v, THV_INIT_DONE);
     while (1) {