From 597d0e9a2093a0139c0abed9a7fedb6cef8bede0 Mon Sep 17 00:00:00 2001 From: Victor Julien Date: Wed, 16 Sep 2009 15:36:26 +0200 Subject: [PATCH] Fix detection of failed thread startup. Cleanup startup output a bit. --- src/app-layer-detect-proto.c | 2 ++ src/eidps.c | 7 +++++-- src/flow.c | 2 ++ src/stream-tcp.c | 4 ++-- src/tm-threads.c | 31 +++++++++++++++++++++++++++---- src/tm-threads.h | 2 +- 6 files changed, 39 insertions(+), 9 deletions(-) diff --git a/src/app-layer-detect-proto.c b/src/app-layer-detect-proto.c index b689b15cf9..11074e3496 100644 --- a/src/app-layer-detect-proto.c +++ b/src/app-layer-detect-proto.c @@ -387,7 +387,9 @@ void AppLayerDetectProtoThreadSpawn() exit(1); } +#ifdef DEBUG printf("AppLayerDetectProtoThread thread created\n"); +#endif return; } diff --git a/src/eidps.c b/src/eidps.c index fb12f890e4..8fcad3fd98 100644 --- a/src/eidps.c +++ b/src/eidps.c @@ -469,8 +469,11 @@ int main(int argc, char **argv) /* Check if the alloted queues have at least 1 reader and writer */ TmValidateQueueState(); - /* Waits till all the threads have been initialized */ - TmThreadWaitOnThreadInit(); + /* Wait till all the threads have been initialized */ + if (TmThreadWaitOnThreadInit() == -1) { + printf("ERROR: Engine initialization failed, aborting...\n"); + exit(EXIT_FAILURE); + } /* Un-pause all the paused threads */ TmThreadContinueThreads(); diff --git a/src/flow.c b/src/flow.c index dbc9339c2d..9e9aa8e063 100644 --- a/src/flow.c +++ b/src/flow.c @@ -493,7 +493,9 @@ void *FlowManagerThread(void *td) uint32_t sleeping = 0; uint8_t emerg = FALSE; +#ifdef DEBUG printf("%s started...\n", th_v->name); +#endif TmThreadsSetFlag(th_v, THV_INIT_DONE); while (1) diff --git a/src/stream-tcp.c b/src/stream-tcp.c index 38727c9060..162553c9fa 100644 --- a/src/stream-tcp.c +++ b/src/stream-tcp.c @@ -178,8 +178,8 @@ void StreamTcpSessionPoolFree(void *s) { void StreamTcpInitConfig(char quiet) { - if (quiet == FALSE) - printf("Initializing Stream:\n"); + //if (quiet == FALSE) + // printf("Initializing Stream:\n"); memset(&stream_config, 0, sizeof(stream_config)); diff --git a/src/tm-threads.c b/src/tm-threads.c index bbd32dc06f..756a405ea2 100644 --- a/src/tm-threads.c +++ b/src/tm-threads.c @@ -597,7 +597,9 @@ ThreadVars *TmThreadCreate(char *name, char *inq_name, char *inqh_name, Tmq *tmq = NULL; Tmqh *tmqh = NULL; +#ifdef DEBUG printf("TmThreadCreate: creating thread \"%s\"...\n", name); +#endif /* XXX create separate function for this: allocate a thread container */ tv = malloc(sizeof(ThreadVars)); @@ -1074,20 +1076,41 @@ void TmThreadCheckThreadState(void) /** \brief Used to check if all threads have finished their initialization. On * finding an un-initialized thread, it waits till that thread completes * its initialization, before proceeding to the next thread. + * \retval 0 all initialized properly + * \retval -1 failure */ -void TmThreadWaitOnThreadInit(void) +int TmThreadWaitOnThreadInit(void) { ThreadVars *tv = NULL; int i = 0; + uint16_t mgt_num = 0; + uint16_t ppt_num = 0; for (i = 0; i < TVT_MAX; i++) { tv = tv_root[i]; while (tv != NULL) { - while (!(TmThreadsCheckFlag(tv, THV_INIT_DONE))) - ; + char started = FALSE; + while (started == FALSE) { + if (TmThreadsCheckFlag(tv, THV_INIT_DONE)) { + started = TRUE; + } + + if (TmThreadsCheckFlag(tv, THV_CLOSED) || + TmThreadsCheckFlag(tv, THV_FAILED)) + { + printf("Thread \"%s\" failed to initialize...\n", tv->name); + return -1; + } + } + + if (i == TVT_MGMT) mgt_num++; + else if (i == TVT_PPT) ppt_num++; + tv = tv->next; } } - return; + printf("All %"PRIu16" packet processing threads, %"PRIu16" management " + "threads initialized, engine started.\n", ppt_num, mgt_num); + return 0; } diff --git a/src/tm-threads.h b/src/tm-threads.h index 6015b8967a..f878414159 100644 --- a/src/tm-threads.h +++ b/src/tm-threads.h @@ -52,7 +52,7 @@ void TmThreadPauseThreads(void); void TmThreadCheckThreadState(void); -void TmThreadWaitOnThreadInit(void); +int TmThreadWaitOnThreadInit(void); inline int TmThreadsCheckFlag(ThreadVars *, uint8_t); inline void TmThreadsSetFlag(ThreadVars *, uint8_t);