From: Eric Leblond Date: Wed, 9 Apr 2014 13:04:45 +0000 (+0200) Subject: output: clean file desc at exit. X-Git-Tag: suricata-2.0.1rc1~69 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F925%2Fhead;p=thirdparty%2Fsuricata.git output: clean file desc at exit. This is a beginning of implementation for bug #1660: https://redmine.openinfosecfoundation.org/issues/1160 This patch adds a cleaning function for each logger of new type (packet, tx and file). These functions are called in RunModeShutDown(). The state of this patch is that it is crashing suricata when sending pcap to analyse: - At first pcap if tx and file cleaning function are called - At second pcap if only packet cleaning function is called The cause in first case is unknown. In second case this is due to the necessity of cleaning the list of logger registered to a logging type. --- diff --git a/src/output-file.c b/src/output-file.c index f6283d70a1..c9a71444d3 100644 --- a/src/output-file.c +++ b/src/output-file.c @@ -277,3 +277,13 @@ void TmModuleFileLoggerRegister (void) { tmm_modules[TMM_FILELOGGER].ThreadDeinit = OutputFileLogThreadDeinit; tmm_modules[TMM_FILELOGGER].cap_flags = 0; } + +void OutputFileShutdown(void) +{ + OutputFileLogger *logger = list; + while (logger) { + if (logger->output_ctx != NULL && logger->output_ctx->DeInit != NULL) + logger->output_ctx->DeInit(logger->output_ctx); + logger = logger->next; + } +} diff --git a/src/output-file.h b/src/output-file.h index 2e2009681b..8b203e267c 100644 --- a/src/output-file.h +++ b/src/output-file.h @@ -41,4 +41,6 @@ int OutputRegisterFileLogger(const char *name, FileLogger LogFunc, OutputCtx *); void TmModuleFileLoggerRegister (void); +void OutputFileShutdown(void); + #endif /* __OUTPUT_FILE_H__ */ diff --git a/src/output-packet.c b/src/output-packet.c index 6f9ddde55a..d575232d8a 100644 --- a/src/output-packet.c +++ b/src/output-packet.c @@ -217,3 +217,16 @@ void TmModulePacketLoggerRegister (void) { tmm_modules[TMM_PACKETLOGGER].ThreadDeinit = OutputPacketLogThreadDeinit; tmm_modules[TMM_PACKETLOGGER].cap_flags = 0; } + +void OutputPacketShutdown(void) +{ + OutputPacketLogger *logger = list; + while (logger) { + if (logger->output_ctx != NULL && logger->output_ctx->DeInit != NULL) + logger->output_ctx->DeInit(logger->output_ctx); + logger = logger->next; + } + + /* FIXME */ + list = NULL; +} diff --git a/src/output-packet.h b/src/output-packet.h index 1173282f68..5ae1adf8e4 100644 --- a/src/output-packet.h +++ b/src/output-packet.h @@ -41,4 +41,6 @@ int OutputRegisterPacketLogger(const char *name, PacketLogger LogFunc, void TmModulePacketLoggerRegister (void); +void OutputPacketShutdown(void); + #endif /* __OUTPUT_PACKET_H__ */ diff --git a/src/output-tx.c b/src/output-tx.c index f6e5235439..3322277d25 100644 --- a/src/output-tx.c +++ b/src/output-tx.c @@ -284,3 +284,13 @@ void TmModuleTxLoggerRegister (void) { tmm_modules[TMM_TXLOGGER].ThreadDeinit = OutputTxLogThreadDeinit; tmm_modules[TMM_TXLOGGER].cap_flags = 0; } + +void OutputTxShutdown(void) +{ + OutputTxLogger *logger = list; + while (logger) { + if (logger->output_ctx != NULL && logger->output_ctx->DeInit != NULL) + logger->output_ctx->DeInit(logger->output_ctx); + logger = logger->next; + } +} diff --git a/src/output-tx.h b/src/output-tx.h index 9281549900..7ffb8a6d25 100644 --- a/src/output-tx.h +++ b/src/output-tx.h @@ -40,4 +40,6 @@ int OutputRegisterTxLogger(const char *name, AppProto alproto, TxLogger LogFunc, void TmModuleTxLoggerRegister (void); +void OutputTxShutdown(void); + #endif /* __OUTPUT_PACKET_H__ */ diff --git a/src/runmodes.c b/src/runmodes.c index d975414e19..6256819fd6 100644 --- a/src/runmodes.c +++ b/src/runmodes.c @@ -408,6 +408,10 @@ void RunModeShutDown(void) output->output_ctx->DeInit(output->output_ctx); SCFree(output); } + + OutputPacketShutdown(); + OutputTxShutdown(); + OutputFileShutdown(); } static TmModule *pkt_logger_module = NULL;