From 0d13505f0ef0e139008c324e5b46d366ac4ff846 Mon Sep 17 00:00:00 2001 From: William Metcalf Date: Thu, 1 Oct 2009 21:34:10 -0500 Subject: [PATCH] change debug code around to use global log dir --- src/eidps.c | 6 +++--- src/util-debug.c | 38 +++++++++++++++++++++++++++++++++----- src/util-debug.h | 2 +- 3 files changed, 37 insertions(+), 9 deletions(-) diff --git a/src/eidps.c b/src/eidps.c index 92f62fbe6d..e368704aad 100644 --- a/src/eidps.c +++ b/src/eidps.c @@ -255,12 +255,12 @@ int main(int argc, char **argv) char *regex_arg = NULL; int dump_config = 0; - /* initialize the logging subsys */ - SCLogInitLogModule(NULL); - /* Initialize the configuration module. */ ConfInit(); + /* initialize the logging subsys */ + SCLogInitLogModule(NULL); + struct option long_opts[] = { {"dump-config", 0, &dump_config, 1}, {"pfring-int", required_argument, 0, 0}, diff --git a/src/util-debug.c b/src/util-debug.c index fc2aafa3c1..f9b71c05bf 100644 --- a/src/util-debug.c +++ b/src/util-debug.c @@ -31,6 +31,8 @@ #include "util-unittest.h" +#include "conf.h" + /* holds the string-enum mapping for the enums held in the table SCLogLevel */ SCEnumCharMap sc_log_level_map[ ] = { { "None", SC_LOG_NONE }, @@ -84,6 +86,11 @@ SCEnumCharMap sc_syslog_facility_map[] = { */ static SCLogConfig *sc_log_config = NULL; +/** + * \brief Returns the full path given a file and configured log dir + */ +static char * ScGetLogFilename(char *); + /** * \brief Holds the global log level. Is the same as sc_log_config->log_level */ @@ -757,7 +764,7 @@ static inline void SCLogSetOPIface(SCLogInitData *sc_lid, SCLogConfig *sc_lc) case SC_LOG_OP_IFACE_FILE: s = getenv(SC_LOG_ENV_LOG_FILE); if (s == NULL) - s = SC_LOG_DEF_LOG_FILE; + s = ScGetLogFilename(SC_LOG_DEF_LOG_FILE); op_ifaces_ctx = SCLogInitFileOPIface(s, NULL, -1); break; @@ -1047,8 +1054,7 @@ void SCLogInitLogModuleIfEnvSet(void) case SC_LOG_OP_IFACE_FILE: s = getenv(SC_LOG_ENV_LOG_FILE); if (s == NULL) - s = SC_LOG_DEF_LOG_FILE; - + s = ScGetLogFilename(SC_LOG_DEF_LOG_FILE); op_ifaces_ctx = SCLogInitFileOPIface(s, NULL, -1); break; case SC_LOG_OP_IFACE_SYSLOG: @@ -1125,6 +1131,28 @@ void SCLogInitLogModuleIfEnvSet(void) return; } +/** + * \brief returns a full file path given a filename uses log dir specified in conf or DEFAULT_LOG_DIR + * + * \param filearg the relative filename for which we want a full path include log directory + * \retval log_filename the fullpath of the logfile to open. + */ +static char * +ScGetLogFilename(char *filearg) +{ + char *log_dir; + char *log_filename; + + if (ConfGet("default-log-dir", &log_dir) != 1) + log_dir = DEFAULT_LOG_DIR; + log_filename = malloc(PATH_MAX); + if (log_filename == NULL) + return NULL; + snprintf(log_filename, PATH_MAX, "%s/%s", log_dir, filearg); + + return log_filename; +} + /** * \brief De-Initializes the logging module */ @@ -1198,13 +1226,13 @@ int SCLogTestInit02() SCLogInitData *sc_lid = NULL; SCLogOPIfaceCtx *sc_iface_ctx = NULL; int result = 1; - + char *logfile = ScGetLogFilename("boo.txt"); sc_lid = SCLogAllocLogInitData(); sc_lid->startup_message = "Test02"; sc_lid->global_log_level = SC_LOG_DEBUG; sc_lid->op_filter = "boo"; sc_iface_ctx = SCLogInitOPIfaceCtx("file", "%m - %d", SC_LOG_ALERT, - "boo.txt"); + logfile); SCLogAppendOPIfaceCtx(sc_iface_ctx, sc_lid); sc_iface_ctx = SCLogInitOPIfaceCtx("console", NULL, SC_LOG_ERROR, NULL); diff --git a/src/util-debug.h b/src/util-debug.h index d0359c9020..dcd7f28118 100644 --- a/src/util-debug.h +++ b/src/util-debug.h @@ -67,7 +67,7 @@ typedef enum { #define SC_LOG_DEF_LOG_OP_IFACE SC_LOG_OP_IFACE_CONSOLE /* The default log file to be used */ -#define SC_LOG_DEF_LOG_FILE "/var/log/eidps/sc_ids_log.log" +#define SC_LOG_DEF_LOG_FILE "sc_ids_log.log" /* The default syslog facility to be used */ #define SC_LOG_DEF_SYSLOG_FACILITY_STR "local0"