From 79a780ffe44eb6cde2cf0d09d2f53f1480c241ef Mon Sep 17 00:00:00 2001 From: Victor Julien Date: Tue, 20 Apr 2010 17:13:54 +0200 Subject: [PATCH] Improve a number of error and info messages. --- src/alert-unified-alert.c | 4 +++- src/alert-unified-log.c | 4 +++- src/alert-unified2-alert.c | 4 +++- src/tm-threads.c | 36 ++++++++++++++++++++++++++---------- src/util-error.c | 5 ++++- src/util-error.h | 5 +++-- 6 files changed, 42 insertions(+), 16 deletions(-) diff --git a/src/alert-unified-alert.c b/src/alert-unified-alert.c index 4d3a792815..80303870bd 100644 --- a/src/alert-unified-alert.c +++ b/src/alert-unified-alert.c @@ -258,7 +258,9 @@ TmEcode AlertUnifiedAlertThreadDeinit(ThreadVars *t, void *data) } if (!(aun->file_ctx->flags & LOGFILE_ALERTS_PRINTED)) { - SCLogInfo("Alert unified 1 alert module wrote %"PRIu64" alerts", aun->file_ctx->alerts); + SCLogInfo("Alert unified1 alert module wrote %"PRIu64" alerts", + aun->file_ctx->alerts); + /* Do not print it for each thread */ aun->file_ctx->flags |= LOGFILE_ALERTS_PRINTED; } diff --git a/src/alert-unified-log.c b/src/alert-unified-log.c index e0451340b6..3d2d6c8599 100644 --- a/src/alert-unified-log.c +++ b/src/alert-unified-log.c @@ -280,7 +280,9 @@ TmEcode AlertUnifiedLogThreadDeinit(ThreadVars *t, void *data) } if (!(aun->file_ctx->flags & LOGFILE_ALERTS_PRINTED)) { - SCLogInfo("Alert unified 1 log module wrote %"PRIu64" alerts", aun->file_ctx->alerts); + SCLogInfo("Alert unified1 log module wrote %"PRIu64" alerts", + aun->file_ctx->alerts); + /* Do not print it for each thread */ aun->file_ctx->flags |= LOGFILE_ALERTS_PRINTED; } diff --git a/src/alert-unified2-alert.c b/src/alert-unified2-alert.c index 97e5345fc7..a88c732913 100644 --- a/src/alert-unified2-alert.c +++ b/src/alert-unified2-alert.c @@ -556,7 +556,9 @@ TmEcode Unified2AlertThreadDeinit(ThreadVars *t, void *data) } if (!(aun->file_ctx->flags & LOGFILE_ALERTS_PRINTED)) { - SCLogInfo("Alert unified 2 module wrote %"PRIu64" alerts", aun->file_ctx->alerts); + SCLogInfo("Alert unified2 module wrote %"PRIu64" alerts", + aun->file_ctx->alerts); + /* Do not print it for each thread */ aun->file_ctx->flags |= LOGFILE_ALERTS_PRINTED; } diff --git a/src/tm-threads.c b/src/tm-threads.c index 3e335e88fa..348ea76225 100644 --- a/src/tm-threads.c +++ b/src/tm-threads.c @@ -1,4 +1,7 @@ -/** Copyright (c) 2009 Open Information Security Foundation. +/* Copyright (c) 2009 Open Information Security Foundation. */ + +/** + * \file * \author Victor Julien * \author Anoop Saldanha */ @@ -17,7 +20,6 @@ #include #include - #ifdef OS_FREEBSD #include #include @@ -74,7 +76,10 @@ typedef struct TmVarSlot_ { TmSlot *s; } TmVarSlot; -/** \retval 1 flag is set +/** + * \brief Check if a thread flag is set + * + * \retval 1 flag is set * \retval 0 flag is not set */ inline int TmThreadsCheckFlag(ThreadVars *tv, uint8_t flag) { @@ -85,10 +90,13 @@ inline int TmThreadsCheckFlag(ThreadVars *tv, uint8_t flag) { } r = (tv->flags & flag); - SCSpinUnlock(&tv->flags_spinlock); + SCSpinUnlock(&tv->flags_spinlock); return r; } +/** + * \brief Set a thread flag + */ inline void TmThreadsSetFlag(ThreadVars *tv, uint8_t flag) { if (SCSpinLock(&tv->flags_spinlock) != 0) { SCLogError(SC_ERR_SPINLOCK,"spin lock errno=%d",errno); @@ -96,9 +104,12 @@ inline void TmThreadsSetFlag(ThreadVars *tv, uint8_t flag) { } tv->flags |= flag; - SCSpinUnlock(&tv->flags_spinlock); + SCSpinUnlock(&tv->flags_spinlock); } +/** + * \brief Unset a thread flag + */ inline void TmThreadsUnsetFlag(ThreadVars *tv, uint8_t flag) { if (SCSpinLock(&tv->flags_spinlock) != 0) { SCLogError(SC_ERR_SPINLOCK,"spin lock errno=%d",errno); @@ -106,7 +117,7 @@ inline void TmThreadsUnsetFlag(ThreadVars *tv, uint8_t flag) { } tv->flags &= ~flag; - SCSpinUnlock(&tv->flags_spinlock); + SCSpinUnlock(&tv->flags_spinlock); } /* 1 slot functions */ @@ -663,6 +674,7 @@ void TmThreadSetPrio(ThreadVars *tv) SCLogDebug("Nice value set to %"PRId32" for thread %s", tv->thread_priority, tv->name); } #endif /* OS_WIN32 */ + SCReturn; } @@ -1225,7 +1237,7 @@ static void TmThreadRestartThread(ThreadVars *tv) TmThreadsUnsetFlag(tv, THV_FAILED); if (TmThreadSpawn(tv) != TM_ECODE_OK) { - printf("Error: TmThreadSpawn failed\n"); + SCLogError(SC_ERR_THREAD_SPAWN, "thread \"%s\" failed to spawn", tv->name); exit(EXIT_FAILURE); } @@ -1268,9 +1280,11 @@ void TmThreadCheckThreadState(void) return; } -/** \brief Used to check if all threads have finished their initialization. On +/** + * \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 TM_ECODE_OK all initialized properly * \retval TM_ECODE_FAILED failure */ @@ -1291,11 +1305,13 @@ TmEcode TmThreadWaitOnThreadInit(void) } if (TmThreadsCheckFlag(tv, THV_FAILED)) { - printf("Thread \"%s\" failed to initialize...\n", tv->name); + SCLogError(SC_ERR_THREAD_INIT, "thread \"%s\" failed to " + "initialize.", tv->name); return TM_ECODE_FAILED; } if (TmThreadsCheckFlag(tv, THV_CLOSED)) { - printf("Thread \"%s\" closed on initialization...\n", tv->name); + SCLogError(SC_ERR_THREAD_INIT, "thread \"%s\" closed on " + "initialization.", tv->name); return TM_ECODE_FAILED; } } diff --git a/src/util-error.c b/src/util-error.c index 2b46bd10e1..e71ad4664a 100644 --- a/src/util-error.c +++ b/src/util-error.c @@ -23,7 +23,6 @@ const char * SCErrorToString(SCError err) CASE_CODE (SC_ERR_PCRE_COMPILE); CASE_CODE (SC_ERR_PCRE_STUDY); CASE_CODE (SC_ERR_PCRE_PARSE); - CASE_CODE (SC_ERR_THREAD_NICE_PRIO); CASE_CODE (SC_ERR_LOG_MODULE_NOT_INIT); CASE_CODE (SC_ERR_LOG_FG_FILTER_MATCH); CASE_CODE (SC_ERR_PCAP_DISPATCH); @@ -81,6 +80,10 @@ const char * SCErrorToString(SCError err) CASE_CODE (SC_ERR_UNIFIED2_ALERT_GENERIC); CASE_CODE (SC_ERR_FWRITE); CASE_CODE (SC_ERR_FOPEN); + CASE_CODE (SC_ERR_THREAD_NICE_PRIO); + CASE_CODE (SC_ERR_THREAD_SPAWN); + CASE_CODE (SC_ERR_THREAD_CREATE); + CASE_CODE (SC_ERR_THREAD_INIT); CASE_CODE (SC_ERR_THRESHOLD_HASH_ADD); CASE_CODE (SC_ERR_UNDEFINED_VAR); CASE_CODE (SC_ERR_RULE_KEYWORD_UNKNOWN); diff --git a/src/util-error.h b/src/util-error.h index 671a19ff94..2c6e6a016f 100644 --- a/src/util-error.h +++ b/src/util-error.h @@ -18,7 +18,6 @@ typedef enum { SC_ERR_PCRE_COMPILE, SC_ERR_PCRE_STUDY, SC_ERR_PCRE_PARSE, - SC_ERR_THREAD_NICE_PRIO, SC_ERR_LOG_MODULE_NOT_INIT, SC_ERR_LOG_FG_FILTER_MATCH, SC_ERR_COUNTER_EXCEEDED, @@ -56,10 +55,12 @@ typedef enum { SC_ERR_FOPEN, SC_ERR_INITIALIZATION, SC_ERR_THREAD_SPAWN, + SC_ERR_THREAD_NICE_PRIO, + SC_ERR_THREAD_CREATE, + SC_ERR_THREAD_INIT, /**< thread's initialization function failed */ SC_ERR_SYSCALL, SC_ERR_SYSCONF, SC_ERR_INVALID_ARGUMENTS, - SC_ERR_THREAD_CREATE, SC_ERR_PERF_STATS_NOT_INIT, SC_ERR_COMPLETE_PORT_SPACE_NEGATED, SC_ERR_NO_PORTS_LEFT_AFTER_MERGE,