unix-manager: fix race condition

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.
pull/1799/head
Eric Leblond 10 years ago committed by Victor Julien
parent 083f22f6d6
commit 6b37985c66

@ -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) {

Loading…
Cancel
Save