]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
Unregister for file rotation notification when a context is
authorJason Ish <jason.ish@emulex.com>
Tue, 27 May 2014 16:07:50 +0000 (10:07 -0600)
committerVictor Julien <victor@inliniac.net>
Wed, 4 Jun 2014 07:50:07 +0000 (09:50 +0200)
de-initialized.  Required for unix-socket mode where
contexts come and go.

src/alert-debuglog.c
src/alert-fastlog.c
src/counters.c
src/log-dnslog.c
src/log-droplog.c
src/log-file.c
src/log-httplog.c
src/log-tlslog.c
src/output-json.c
src/output.c
src/output.h

index d095382b720f523413eb4afe9754cb26b3b48468..bfe9b493a28b7df9aa751211966d82825f265e3d 100644 (file)
@@ -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);
         }
index 05d97d5e5c37a9ccbc6032c06ea6337ec283e0ad..2a5f6d3a575495698ce9f70ebc7f50cf59bbe42d 100644 (file)
@@ -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);
 }
index 4bea047635dac623e66303a3a03fd3f8c68b139f..fce106908087772575283c66abc6018044d5e193 100644 (file)
@@ -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);
 
index 42f102a63d261c783ee1fd57e8806f545c727119..913bed93d46369c413085c935a048b025ea4d98f 100644 (file)
@@ -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);
index c8abd3c8ba644f125326bd22e827d228f3d8ce5f..5a50d89b55c577e3dd8002efef8a66a07314923a 100644 (file)
@@ -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);
index a2cdb37825d0d019eafcd14a82bffcb97b28280c..3c5bcd9c7c2cb0c3840356b52e90f354c064544d 100644 (file)
@@ -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);
 }
index b6a0f979d77ecf53c33cb48178ac15896e9ba22c..bbff5470c32b0e52a30d2c67248496da1b86830f 100644 (file)
@@ -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);
index 18d2d0e61c75ebd1089c46928ae894c811217d6a..f45ca289348878186f932163db5a856b3f459a88 100644 (file)
@@ -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);
index daf6c2577e367f6f1503ceeb484dace2107edd71..52d8b309fb315abff150a44aab3ecc8b130ae9b8 100644 (file)
@@ -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);
index c29f4d9103deaf54db1a9c0f844f640065405fb0..980369ddea97a985a984199f7705be604ee4834f 100644 (file)
@@ -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;
index 75c18da7e6d57da5f2ad973ea1e69fd31d9ed3b3..72837ce20c6f21f2874662bf759666d79ae96a73 100644 (file)
@@ -93,6 +93,7 @@ int OutputSshLoggerEnable(void);
 void OutputSshLoggerDisable(void);
 
 void OutputRegisterFileRotationFlag(int *flag);
+void OutputUnregisterFileRotationFlag(int *flag);
 void OutputNotifyFileRotation(void);
 
 #endif /* ! __OUTPUT_H__ */