diff --git a/src/alert-debuglog.c b/src/alert-debuglog.c index d095382b72..bfe9b493a2 100644 --- a/src/alert-debuglog.c +++ b/src/alert-debuglog.c @@ -445,6 +445,7 @@ static void AlertDebugLogDeInitCtx(OutputCtx *output_ctx) { if (output_ctx != NULL) { LogFileCtx *logfile_ctx = (LogFileCtx *)output_ctx->data; + OutputUnregisterFileRotationFlag(&logfile_ctx->rotation_flag); if (logfile_ctx != NULL) { LogFileFreeCtx(logfile_ctx); } diff --git a/src/alert-fastlog.c b/src/alert-fastlog.c index 05d97d5e5c..2a5f6d3a57 100644 --- a/src/alert-fastlog.c +++ b/src/alert-fastlog.c @@ -266,6 +266,7 @@ OutputCtx *AlertFastLogInitCtx(ConfNode *conf) static void AlertFastLogDeInitCtx(OutputCtx *output_ctx) { LogFileCtx *logfile_ctx = (LogFileCtx *)output_ctx->data; + OutputUnregisterFileRotationFlag(&logfile_ctx->rotation_flag); LogFileFreeCtx(logfile_ctx); SCFree(output_ctx); } diff --git a/src/counters.c b/src/counters.c index 4bea047635..fce1069080 100644 --- a/src/counters.c +++ b/src/counters.c @@ -285,6 +285,8 @@ static void SCPerfReleaseOPCtx() SCPerfClubTMInst *temp = NULL; pctmi = sc_perf_op_ctx->pctmi; + OutputUnregisterFileRotationFlag(&sc_perf_op_ctx->rotation_flag); + if (sc_perf_op_ctx->fp != NULL) fclose(sc_perf_op_ctx->fp); diff --git a/src/log-dnslog.c b/src/log-dnslog.c index 42f102a63d..913bed93d4 100644 --- a/src/log-dnslog.c +++ b/src/log-dnslog.c @@ -288,6 +288,7 @@ static void LogDnsLogExitPrintStats(ThreadVars *tv, void *data) { static void LogDnsLogDeInitCtx(OutputCtx *output_ctx) { LogDnsFileCtx *dnslog_ctx = (LogDnsFileCtx *)output_ctx->data; + OutputUnregisterFileRotationFlag(&dnslog_ctx->file_ctx->rotation_flag); LogFileFreeCtx(dnslog_ctx->file_ctx); SCFree(dnslog_ctx); SCFree(output_ctx); diff --git a/src/log-droplog.c b/src/log-droplog.c index c8abd3c8ba..5a50d89b55 100644 --- a/src/log-droplog.c +++ b/src/log-droplog.c @@ -125,6 +125,7 @@ static void LogDropLogDeInitCtx(OutputCtx *output_ctx) if (output_ctx != NULL) { LogFileCtx *logfile_ctx = (LogFileCtx *)output_ctx->data; if (logfile_ctx != NULL) { + OutputUnregisterFileRotationFlag(&logfile_ctx->rotation_flag); LogFileFreeCtx(logfile_ctx); } SCFree(output_ctx); diff --git a/src/log-file.c b/src/log-file.c index a2cdb37825..3c5bcd9c7c 100644 --- a/src/log-file.c +++ b/src/log-file.c @@ -346,6 +346,7 @@ void LogFileLogExitPrintStats(ThreadVars *tv, void *data) { static void LogFileLogDeInitCtx(OutputCtx *output_ctx) { LogFileCtx *logfile_ctx = (LogFileCtx *)output_ctx->data; + OutputUnregisterFileRotationFlag(&logfile_ctx->rotation_flag); LogFileFreeCtx(logfile_ctx); free(output_ctx); } diff --git a/src/log-httplog.c b/src/log-httplog.c index b6a0f979d7..bbff5470c3 100644 --- a/src/log-httplog.c +++ b/src/log-httplog.c @@ -730,6 +730,7 @@ static void LogHttpLogDeInitCtx(OutputCtx *output_ctx) for (i = 0; i < httplog_ctx->cf_n; i++) { SCFree(httplog_ctx->cf_nodes[i]); } + OutputUnregisterFileRotationFlag(&httplog_ctx->file_ctx->rotation_flag); LogFileFreeCtx(httplog_ctx->file_ctx); SCFree(httplog_ctx); SCFree(output_ctx); diff --git a/src/log-tlslog.c b/src/log-tlslog.c index 18d2d0e61c..f45ca28934 100644 --- a/src/log-tlslog.c +++ b/src/log-tlslog.c @@ -382,6 +382,7 @@ static void LogTlsLogDeInitCtx(OutputCtx *output_ctx) OutputTlsLoggerDisable(); LogTlsFileCtx *tlslog_ctx = (LogTlsFileCtx *) output_ctx->data; + OutputUnregisterFileRotationFlag(&tlslog_ctx->file_ctx->rotation_flag); LogFileFreeCtx(tlslog_ctx->file_ctx); SCFree(tlslog_ctx); SCFree(output_ctx); diff --git a/src/output-json.c b/src/output-json.c index daf6c2577e..52d8b309fb 100644 --- a/src/output-json.c +++ b/src/output-json.c @@ -477,6 +477,7 @@ static void OutputJsonDeInitCtx(OutputCtx *output_ctx) { OutputJsonCtx *json_ctx = (OutputJsonCtx *)output_ctx->data; LogFileCtx *logfile_ctx = json_ctx->file_ctx; + OutputUnregisterFileRotationFlag(&logfile_ctx->rotation_flag); LogFileFreeCtx(logfile_ctx); SCFree(json_ctx); SCFree(output_ctx); diff --git a/src/output.c b/src/output.c index c29f4d9103..980369ddea 100644 --- a/src/output.c +++ b/src/output.c @@ -429,8 +429,13 @@ void OutputSshLoggerDisable(void) { ssh_loggers--; } -void OutputRegisterFileRotationFlag(int *flag) -{ +/** + * \brief Register a flag for file rotation notification. + * + * \param flag A pointer that will be set to 1 when file rotation is + * requested. + */ +void OutputRegisterFileRotationFlag(int *flag) { OutputFileRolloverFlag *flag_entry = SCCalloc(1, sizeof(*flag_entry)); if (unlikely(flag_entry == NULL)) { SCLogError(SC_ERR_MEM_ALLOC, @@ -441,8 +446,33 @@ void OutputRegisterFileRotationFlag(int *flag) TAILQ_INSERT_TAIL(&output_file_rotation_flags, flag_entry, entries); } -void OutputNotifyFileRotation(void) -{ +/** + * \brief Unregister a file rotation flag. + * + * Note that it is safe to call this function with a flag that may not + * have been registered, in which case this function won't do + * anything. + * + * \param flag A pointer that has been previously registered for file + * rotation notifications. + */ +void OutputUnregisterFileRotationFlag(int *flag) { + OutputFileRolloverFlag *entry, *next; + for (entry = TAILQ_FIRST(&output_file_rotation_flags); entry != NULL; + entry = next) { + next = TAILQ_NEXT(entry, entries); + if (entry->flag == flag) { + TAILQ_REMOVE(&output_file_rotation_flags, entry, entries); + SCFree(entry); + break; + } + } +} + +/** + * \brief Notifies all registered file rotation notification flags. + */ +void OutputNotifyFileRotation(void) { OutputFileRolloverFlag *flag; TAILQ_FOREACH(flag, &output_file_rotation_flags, entries) { *(flag->flag) = 1; diff --git a/src/output.h b/src/output.h index 75c18da7e6..72837ce20c 100644 --- a/src/output.h +++ b/src/output.h @@ -93,6 +93,7 @@ int OutputSshLoggerEnable(void); void OutputSshLoggerDisable(void); void OutputRegisterFileRotationFlag(int *flag); +void OutputUnregisterFileRotationFlag(int *flag); void OutputNotifyFileRotation(void); #endif /* ! __OUTPUT_H__ */