diff --git a/src/alert-debuglog.c b/src/alert-debuglog.c index 4090f23808..a0ea4c5687 100644 --- a/src/alert-debuglog.c +++ b/src/alert-debuglog.c @@ -466,25 +466,26 @@ OutputCtx *AlertDebugLogInitCtx(ConfNode *conf) int AlertDebugLogOpenFileCtx(LogFileCtx *file_ctx, const char *filename, const char *mode) { - int ret=0; + char log_path[PATH_MAX]; + char *log_dir; - char log_path[PATH_MAX], *log_dir; if (ConfGet("default-log-dir", &log_dir) != 1) log_dir = DEFAULT_LOG_DIR; + snprintf(log_path, PATH_MAX, "%s/%s", log_dir, filename); - if (strncmp(mode, "yes", sizeof(mode)) == 0) { + + if (strcasecmp(mode, "yes") == 0) { file_ctx->fp = fopen(log_path, "a"); } else { file_ctx->fp = fopen(log_path, "w"); } if (file_ctx->fp == NULL) { - SCLogError(SC_ERR_FOPEN, "ERROR: failed to open %s: %s", log_path, + SCLogError(SC_ERR_FOPEN, "failed to open %s: %s", log_path, strerror(errno)); return -1; } - return ret; + return 0; } - diff --git a/src/alert-fastlog.c b/src/alert-fastlog.c index af7d4f5c15..24cd1096bf 100644 --- a/src/alert-fastlog.c +++ b/src/alert-fastlog.c @@ -354,19 +354,22 @@ static void AlertFastLogDeInitCtx(OutputCtx *output_ctx) static int AlertFastLogOpenFileCtx(LogFileCtx *file_ctx, const char *filename, const char *mode) { - char log_path[PATH_MAX], *log_dir; + char log_path[PATH_MAX]; + char *log_dir; + if (ConfGet("default-log-dir", &log_dir) != 1) log_dir = DEFAULT_LOG_DIR; + snprintf(log_path, PATH_MAX, "%s/%s", log_dir, filename); - if (strncmp(mode, "yes", sizeof(mode)) == 0) { + if (strcasecmp(mode, "yes") == 0) { file_ctx->fp = fopen(log_path, "a"); } else { file_ctx->fp = fopen(log_path, "w"); } if (file_ctx->fp == NULL) { - SCLogError(SC_ERR_FOPEN, "ERROR: failed to open %s: %s", log_path, + SCLogError(SC_ERR_FOPEN, "failed to open %s: %s", log_path, strerror(errno)); return -1; } diff --git a/src/counters.c b/src/counters.c index 27c0fb49cf..aff50ea098 100644 --- a/src/counters.c +++ b/src/counters.c @@ -47,6 +47,8 @@ static time_t sc_start_time; static uint32_t sc_counter_tts = SC_PERF_MGMTT_TTS; /** is the stats counter enabled? */ static char sc_counter_enabled = TRUE; +/** append or overwrite? 1: append, 0: overwrite */ +static char sc_counter_append = TRUE; /** * \brief Adds a value of type uint64_t to the local counter. @@ -330,6 +332,10 @@ static void SCPerfInitOPCtx(void) const char *interval = ConfNodeLookupChildValue(stats, "interval"); if (interval != NULL) sc_counter_tts = (uint32_t) atoi(interval); + + const char *append = ConfNodeLookupChildValue(stats, "append"); + if (append != NULL) + sc_counter_append = (strcasecmp(append,"yes") == 0); } /* Store the engine start time */ @@ -347,7 +353,13 @@ static void SCPerfInitOPCtx(void) SCLogInfo("Error retrieving Perf Counter API output file path"); } - if ( (sc_perf_op_ctx->fp = fopen(sc_perf_op_ctx->file, "w+")) == NULL) { + char *mode; + if (sc_counter_append) + mode = "a+"; + else + mode = "w+"; + + if ( (sc_perf_op_ctx->fp = fopen(sc_perf_op_ctx->file, mode)) == NULL) { SCLogError(SC_ERR_FOPEN, "fopen error opening file \"%s\". Resorting " "to using the standard output for output", sc_perf_op_ctx->file); diff --git a/src/log-httplog.c b/src/log-httplog.c index 676423cf77..647498a037 100644 --- a/src/log-httplog.c +++ b/src/log-httplog.c @@ -457,19 +457,22 @@ static void LogHttpLogDeInitCtx(OutputCtx *output_ctx) int LogHttpLogOpenFileCtx(LogFileCtx *file_ctx, const char *filename, const char *mode) { - char log_path[PATH_MAX], *log_dir; + char log_path[PATH_MAX]; + char *log_dir; + if (ConfGet("default-log-dir", &log_dir) != 1) log_dir = DEFAULT_LOG_DIR; + snprintf(log_path, PATH_MAX, "%s/%s", log_dir, filename); - if (strncmp(mode, "yes", sizeof(mode)) == 0) { + if (strcasecmp(mode, "yes") == 0) { file_ctx->fp = fopen(log_path, "a"); } else { file_ctx->fp = fopen(log_path, "w"); } if (file_ctx->fp == NULL) { - SCLogError(SC_ERR_FOPEN, "ERROR: failed to open %s: %s", log_path, + SCLogError(SC_ERR_FOPEN, "failed to open %s: %s", log_path, strerror(errno)); return -1; } @@ -477,4 +480,3 @@ int LogHttpLogOpenFileCtx(LogFileCtx *file_ctx, const char *filename, const return 0; } -