Unregister for file rotation notification when a context is

de-initialized.  Required for unix-socket mode where
contexts come and go.
pull/979/merge
Jason Ish 12 years ago committed by Victor Julien
parent e1b97fed70
commit fc2014ab40

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

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

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

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

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

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

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

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

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

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

@ -93,6 +93,7 @@ int OutputSshLoggerEnable(void);
void OutputSshLoggerDisable(void);
void OutputRegisterFileRotationFlag(int *flag);
void OutputUnregisterFileRotationFlag(int *flag);
void OutputNotifyFileRotation(void);
#endif /* ! __OUTPUT_H__ */

Loading…
Cancel
Save