Extend 'append' option to stats.log as well. Small cleanups.

remotes/origin/master-1.1.x
Victor Julien 14 years ago
parent f4392e1dcc
commit d48ff8f6aa

@ -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;
}

@ -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;
}

@ -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);

@ -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;
}

Loading…
Cancel
Save