From 70145171ce5670a78f3b51cb5dc62d1124fe099d Mon Sep 17 00:00:00 2001 From: Anoop Saldanha Date: Fri, 16 Apr 2010 14:38:34 +0530 Subject: [PATCH] fix for bug 108 --- src/suricata.c | 3 ++- src/util-debug.c | 42 ++++++++++++++++++++++++------------------ 2 files changed, 26 insertions(+), 19 deletions(-) diff --git a/src/suricata.c b/src/suricata.c index 78466f7..20aeca8 100644 --- a/src/suricata.c +++ b/src/suricata.c @@ -410,6 +410,8 @@ int main(int argc, char **argv) } #endif + SCLogInfo("This is %s version %s", PROG_NAME, PROG_VER); + /* initialize the logging subsys */ SCLogInitLogModule(NULL); @@ -587,7 +589,6 @@ int main(int argc, char **argv) } SetBpfString(optind, argv); - SCLogInfo("This is %s version %s", PROG_NAME, PROG_VER); UtilCpuPrintSummary(); #ifdef __SC_CUDA_SUPPORT__ diff --git a/src/util-debug.c b/src/util-debug.c index d72cc15..7b19798 100644 --- a/src/util-debug.c +++ b/src/util-debug.c @@ -644,9 +644,9 @@ static inline void SCLogSetLogLevel(SCLogInitData *sc_lid, SCLogConfig *sc_lc) SCLogLevel log_level = SC_LOG_NOTSET; const char *s = NULL; - if (sc_lid != NULL) + if (sc_lid != NULL) { log_level = sc_lid->global_log_level; - else { + } else { s = getenv(SC_LOG_ENV_LOG_LEVEL); if (s != NULL) log_level = SCMapEnumNameToValue(s, sc_log_level_map); @@ -658,9 +658,11 @@ static inline void SCLogSetLogLevel(SCLogInitData *sc_lid, SCLogConfig *sc_lc) else { sc_lc->log_level = SC_LOG_DEF_LOG_LEVEL; #ifndef UNITTESTS - printf("Warning: Invalid global_log_level assigned by user. Falling " - "back on the default_log_level \"%s\"\n", - SCMapEnumValueToName(sc_lc->log_level, sc_log_level_map)); + if (sc_lid != NULL) { + printf("Warning: Invalid/No global_log_level assigned by user. Falling " + "back on the default_log_level \"%s\"\n", + SCMapEnumValueToName(sc_lc->log_level, sc_log_level_map)); + } #endif } @@ -694,15 +696,16 @@ static inline void SCLogSetLogFormat(SCLogInitData *sc_lid, SCLogConfig *sc_lc) if (format == NULL || strlen(format) > SC_LOG_MAX_LOG_FORMAT_LEN) { format = SC_LOG_DEF_LOG_FORMAT; #ifndef UNITTESTS - printf("Warning: Invalid global_log_format supplied by user or format " - "length exceeded limit of \"%d\" characters. Falling back on " - "default log_format \"%s\"\n", SC_LOG_MAX_LOG_FORMAT_LEN, - format); + if (sc_lid != NULL) { + printf("Warning: Invalid/No global_log_format supplied by user or format " + "length exceeded limit of \"%d\" characters. Falling back on " + "default log_format \"%s\"\n", SC_LOG_MAX_LOG_FORMAT_LEN, + format); + } #endif } - if (format != NULL && - (sc_lc->log_format = strdup(format)) == NULL) { + if (format != NULL && (sc_lc->log_format = strdup(format)) == NULL) { printf("Error allocating memory\n"); exit(EXIT_FAILURE); } @@ -731,8 +734,7 @@ static inline void SCLogSetOPIface(SCLogInitData *sc_lid, SCLogConfig *sc_lc) sc_lc->op_ifaces = sc_lid->op_ifaces; sc_lid->op_ifaces = NULL; sc_lc->op_ifaces_cnt = sc_lid->op_ifaces_cnt; - } - else { + } else { s = getenv(SC_LOG_ENV_LOG_OP_IFACE); if (s != NULL) { op_iface = SCMapEnumNameToValue(s, sc_log_op_iface_map); @@ -749,9 +751,11 @@ static inline void SCLogSetOPIface(SCLogInitData *sc_lid, SCLogConfig *sc_lc) else { op_iface = SC_LOG_DEF_LOG_OP_IFACE; #ifndef UNITTESTS - printf("Warning: Output_interface not supplied by user. Falling " - "back on default_output_interface \"%s\"\n", - SCMapEnumValueToName(op_iface, sc_log_op_iface_map)); + if (sc_lid != NULL) { + printf("Warning: Output_interface not supplied by user. Falling " + "back on default_output_interface \"%s\"\n", + SCMapEnumValueToName(op_iface, sc_log_op_iface_map)); + } #endif } @@ -968,9 +972,11 @@ SCLogOPIfaceCtx *SCLogInitOPIfaceCtx(const char *iface_name, } /** - * \brief Initializes the logging module + * \brief Initializes the logging module. * - * \param sc_did The initialization data for the logging module + * \param sc_lid The initialization data for the logging module. If sc_lid is + * NULL, we would stick to the default configuration for the + * logging subsystem. * */ void SCLogInitLogModule(SCLogInitData *sc_lid) -- 1.7.0.2