detect/loader: minor code cleanups

pull/9380/head
Victor Julien 3 years ago
parent a4f670622e
commit f312370fd2

@ -384,7 +384,7 @@ int SigLoadSignatures(DetectEngineCtx *de_ctx, char *sig_file, int sig_file_excl
#define NLOADERS 4 #define NLOADERS 4
static DetectLoaderControl *loaders = NULL; static DetectLoaderControl *loaders = NULL;
static int cur_loader = 0; static int cur_loader = 0;
void TmThreadWakeupDetectLoaderThreads(void); static void TmThreadWakeupDetectLoaderThreads(void);
static int num_loaders = NLOADERS; static int num_loaders = NLOADERS;
/** \param loader -1 for auto select /** \param loader -1 for auto select
@ -427,14 +427,14 @@ int DetectLoadersSync(void)
{ {
SCLogDebug("waiting"); SCLogDebug("waiting");
int errors = 0; int errors = 0;
int i; for (int i = 0; i < num_loaders; i++) {
for (i = 0; i < num_loaders; i++) { bool done = false;
int done = 0;
DetectLoaderControl *loader = &loaders[i]; DetectLoaderControl *loader = &loaders[i];
while (!done) { while (!done) {
SCMutexLock(&loader->m); SCMutexLock(&loader->m);
if (TAILQ_EMPTY(&loader->task_list)) { if (TAILQ_EMPTY(&loader->task_list)) {
done = 1; done = true;
} }
SCMutexUnlock(&loader->m); SCMutexUnlock(&loader->m);
} }
@ -444,7 +444,6 @@ int DetectLoadersSync(void)
loader->result = 0; loader->result = 0;
} }
SCMutexUnlock(&loader->m); SCMutexUnlock(&loader->m);
} }
if (errors) { if (errors) {
SCLogError("%d loaders reported errors", errors); SCLogError("%d loaders reported errors", errors);
@ -467,19 +466,17 @@ void DetectLoadersInit(void)
(void)ConfGetInt("multi-detect.loaders", &setting); (void)ConfGetInt("multi-detect.loaders", &setting);
if (setting < 1 || setting > 1024) { if (setting < 1 || setting > 1024) {
SCLogError("invalid multi-detect.loaders setting %" PRIdMAX, setting); FatalError("invalid multi-detect.loaders setting %" PRIdMAX, setting);
exit(EXIT_FAILURE);
} }
num_loaders = (int32_t)setting;
num_loaders = (int32_t)setting;
SCLogInfo("using %d detect loader threads", num_loaders); SCLogInfo("using %d detect loader threads", num_loaders);
BUG_ON(loaders != NULL); BUG_ON(loaders != NULL);
loaders = SCCalloc(num_loaders, sizeof(DetectLoaderControl)); loaders = SCCalloc(num_loaders, sizeof(DetectLoaderControl));
BUG_ON(loaders == NULL); BUG_ON(loaders == NULL);
int i; for (int i = 0; i < num_loaders; i++) {
for (i = 0; i < num_loaders; i++) {
DetectLoaderInit(&loaders[i]); DetectLoaderInit(&loaders[i]);
} }
} }
@ -487,14 +484,11 @@ void DetectLoadersInit(void)
/** /**
* \brief Unpauses all threads present in tv_root * \brief Unpauses all threads present in tv_root
*/ */
void TmThreadWakeupDetectLoaderThreads(void) static void TmThreadWakeupDetectLoaderThreads(void)
{ {
ThreadVars *tv = NULL;
int i = 0;
SCMutexLock(&tv_root_lock); SCMutexLock(&tv_root_lock);
for (i = 0; i < TVT_MAX; i++) { for (int i = 0; i < TVT_MAX; i++) {
tv = tv_root[i]; ThreadVars *tv = tv_root[i];
while (tv != NULL) { while (tv != NULL) {
if (strncmp(tv->name,"DL#",3) == 0) { if (strncmp(tv->name,"DL#",3) == 0) {
BUG_ON(tv->ctrl_cond == NULL); BUG_ON(tv->ctrl_cond == NULL);
@ -504,8 +498,6 @@ void TmThreadWakeupDetectLoaderThreads(void)
} }
} }
SCMutexUnlock(&tv_root_lock); SCMutexUnlock(&tv_root_lock);
return;
} }
/** /**
@ -513,12 +505,9 @@ void TmThreadWakeupDetectLoaderThreads(void)
*/ */
void TmThreadContinueDetectLoaderThreads(void) void TmThreadContinueDetectLoaderThreads(void)
{ {
ThreadVars *tv = NULL;
int i = 0;
SCMutexLock(&tv_root_lock); SCMutexLock(&tv_root_lock);
for (i = 0; i < TVT_MAX; i++) { for (int i = 0; i < TVT_MAX; i++) {
tv = tv_root[i]; ThreadVars *tv = tv_root[i];
while (tv != NULL) { while (tv != NULL) {
if (strncmp(tv->name,"DL#",3) == 0) if (strncmp(tv->name,"DL#",3) == 0)
TmThreadContinue(tv); TmThreadContinue(tv);
@ -527,11 +516,8 @@ void TmThreadContinueDetectLoaderThreads(void)
} }
} }
SCMutexUnlock(&tv_root_lock); SCMutexUnlock(&tv_root_lock);
return;
} }
SC_ATOMIC_DECLARE(int, detect_loader_cnt); SC_ATOMIC_DECLARE(int, detect_loader_cnt);
typedef struct DetectLoaderThreadData_ { typedef struct DetectLoaderThreadData_ {
@ -613,27 +599,18 @@ static TmEcode DetectLoader(ThreadVars *th_v, void *thread_data)
/** \brief spawn the detect loader manager thread */ /** \brief spawn the detect loader manager thread */
void DetectLoaderThreadSpawn(void) void DetectLoaderThreadSpawn(void)
{ {
int i; for (int i = 0; i < num_loaders; i++) {
for (i = 0; i < num_loaders; i++) {
ThreadVars *tv_loader = NULL;
char name[TM_THREAD_NAME_MAX]; char name[TM_THREAD_NAME_MAX];
snprintf(name, sizeof(name), "%s#%02d", thread_name_detect_loader, i+1); snprintf(name, sizeof(name), "%s#%02d", thread_name_detect_loader, i+1);
tv_loader = TmThreadCreateCmdThreadByName(name, ThreadVars *tv_loader = TmThreadCreateCmdThreadByName(name, "DetectLoader", 1);
"DetectLoader", 1);
BUG_ON(tv_loader == NULL);
if (tv_loader == NULL) { if (tv_loader == NULL) {
printf("ERROR: TmThreadsCreate failed\n"); FatalError("failed to create thread %s", name);
exit(1);
} }
if (TmThreadSpawn(tv_loader) != TM_ECODE_OK) { if (TmThreadSpawn(tv_loader) != TM_ECODE_OK) {
printf("ERROR: TmThreadSpawn failed\n"); FatalError("failed to create spawn %s", name);
exit(1);
} }
} }
return;
} }
void TmModuleDetectLoaderRegister (void) void TmModuleDetectLoaderRegister (void)

Loading…
Cancel
Save