|
|
|
@ -35,6 +35,7 @@
|
|
|
|
|
#include "util-privs.h"
|
|
|
|
|
#include "util-signal.h"
|
|
|
|
|
#include "unix-manager.h"
|
|
|
|
|
#include "output.h"
|
|
|
|
|
|
|
|
|
|
/** \todo Get the default log directory from some global resource. */
|
|
|
|
|
#define SC_PERF_DEFAULT_LOG_FILENAME "stats.log"
|
|
|
|
@ -167,6 +168,23 @@ static char *SCPerfGetLogFilename(ConfNode *stats)
|
|
|
|
|
return log_filename;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* \brief Reopen the log file.
|
|
|
|
|
*
|
|
|
|
|
* \retval 1 if successful, otherwise 0.
|
|
|
|
|
*/
|
|
|
|
|
static int SCPerfFileReopen(SCPerfOPIfaceContext *sc_perf_op_ctx)
|
|
|
|
|
{
|
|
|
|
|
fclose(sc_perf_op_ctx->fp);
|
|
|
|
|
if ((sc_perf_op_ctx->fp = fopen(sc_perf_op_ctx->file, "w+")) == NULL) {
|
|
|
|
|
SCLogError(SC_ERR_FOPEN, "Failed to reopen file \"%s\"."
|
|
|
|
|
"Stats logging will now be disabled.",
|
|
|
|
|
sc_perf_op_ctx->file);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* \brief Initializes the output interface context
|
|
|
|
|
*
|
|
|
|
@ -238,6 +256,10 @@ static void SCPerfInitOPCtx(void)
|
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
/* File opened, register for rotation notification. */
|
|
|
|
|
OutputRegisterFileRotationFlag(&sc_perf_op_ctx->rotation_flag);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* init the lock used by SCPerfClubTMInst */
|
|
|
|
|
if (SCMutexInit(&sc_perf_op_ctx->pctmi_lock, NULL) != 0) {
|
|
|
|
@ -631,6 +653,15 @@ static int SCPerfOutputCounterFileIface()
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (sc_perf_op_ctx->rotation_flag) {
|
|
|
|
|
SCLogDebug("Rotating log file");
|
|
|
|
|
sc_perf_op_ctx->rotation_flag = 0;
|
|
|
|
|
if (!SCPerfFileReopen(sc_perf_op_ctx)) {
|
|
|
|
|
/* Rotation failed, error already logged. */
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
memset(&tval, 0, sizeof(struct timeval));
|
|
|
|
|
|
|
|
|
|
gettimeofday(&tval, NULL);
|
|
|
|
|