static char *active_runmode;
+/* free list for our outputs */
+typedef struct OutputFreeList_ {
+ TmModule *tm_module;
+ OutputCtx *output_ctx;
+
+ TAILQ_ENTRY(OutputFreeList_) entries;
+} OutputFreeList;
+TAILQ_HEAD(, OutputFreeList_) output_free_list =
+ TAILQ_HEAD_INITIALIZER(output_free_list);
+
/**
* \internal
* \brief Translate a runmode mode to a printale string.
return;
}
+/**
+ * Setup the outputs for this run mode.
+ *
+ * \param tv The ThreadVars for the thread the outputs will be
+ * appended to.
+ */
+void RunOutputFreeList(void)
+{
+ OutputFreeList *output;
+ while ((output = TAILQ_FIRST(&output_free_list))) {
+ SCLogDebug("output %s %p %p", output->tm_module->name, output, output->output_ctx);
+
+ if (output->output_ctx != NULL && output->output_ctx->DeInit != NULL)
+ output->output_ctx->DeInit(output->output_ctx);
+
+ TAILQ_REMOVE(&output_free_list, output, entries);
+ SCFree(output);
+ }
+}
+
/**
* Cleanup the run mode.
*/
void RunModeShutDown(void)
{
+ RunOutputFreeList();
+
+ OutputPacketShutdown();
+ OutputTxShutdown();
+ OutputFileShutdown();
+ OutputFiledataShutdown();
+
/* Close any log files. */
RunModeOutput *output;
while ((output = TAILQ_FIRST(&RunModeOutputs))) {
SCLogDebug("Shutting down output %s.", output->tm_module->name);
TAILQ_REMOVE(&RunModeOutputs, output, entries);
- if (output->output_ctx != NULL && output->output_ctx->DeInit != NULL)
- output->output_ctx->DeInit(output->output_ctx);
SCFree(output);
}
- OutputPacketShutdown();
- OutputTxShutdown();
- OutputFileShutdown();
}
static TmModule *pkt_logger_module = NULL;
static TmModule *file_logger_module = NULL;
static TmModule *filedata_logger_module = NULL;
+/** \internal
+ * \brief add Sub RunModeOutput to list for Submodule so we can free
+ * the output ctx at shutdown and unix socket reload */
+static void AddOutputToFreeList(OutputModule *module, OutputCtx *output_ctx)
+{
+ TmModule *tm_module = TmModuleGetByName(module->name);
+ if (tm_module == NULL) {
+ SCLogError(SC_ERR_INVALID_ARGUMENT,
+ "TmModuleGetByName for %s failed", module->name);
+ exit(EXIT_FAILURE);
+ }
+ OutputFreeList *fl_output = SCCalloc(1, sizeof(OutputFreeList));
+ if (unlikely(fl_output == NULL))
+ return;
+ fl_output->tm_module = tm_module;
+ fl_output->output_ctx = output_ctx;
+ TAILQ_INSERT_TAIL(&output_free_list, fl_output, entries);
+}
+
/** \brief Turn output into thread module */
static void SetupOutput(const char *name, OutputModule *module, OutputCtx *output_ctx)
{
continue;
}
+ AddOutputToFreeList(sub_module, sub_output_ctx);
SetupOutput(sub_module->name, sub_module, sub_output_ctx);
}
}
+ /* add 'eve-log' to free list as it's the owner of the
+ * main output ctx from which the sub-modules share the
+ * LogFileCtx */
+ AddOutputToFreeList(module, output_ctx);
} else {
+ AddOutputToFreeList(module, output_ctx);
SetupOutput(module->name, module, output_ctx);
}
}