output: check for multiple instances of drop and tls

Both the drop and tls logs are currently not designed to have multiple
instances running. So until that is changed, error out if more than one
instance is started.
pull/806/head
Victor Julien 11 years ago
parent 870bb23ff6
commit 9950427466

@ -136,6 +136,12 @@ static void LogDropLogDeInitCtx(OutputCtx *output_ctx)
*/ */
static OutputCtx *LogDropLogInitCtx(ConfNode *conf) static OutputCtx *LogDropLogInitCtx(ConfNode *conf)
{ {
if (OutputDropLoggerEnable() != 0) {
SCLogError(SC_ERR_CONF_YAML_ERROR, "only one 'drop' logger "
"can be enabled");
return NULL;
}
LogFileCtx *logfile_ctx = LogFileNewCtx(); LogFileCtx *logfile_ctx = LogFileNewCtx();
if (logfile_ctx == NULL) { if (logfile_ctx == NULL) {
SCLogDebug("LogDropLogInitCtx: Could not create new LogFileCtx"); SCLogDebug("LogDropLogInitCtx: Could not create new LogFileCtx");

@ -401,6 +401,12 @@ static void LogTlsLogExitPrintStats(ThreadVars *tv, void *data)
* */ * */
static OutputCtx *LogTlsLogInitCtx(ConfNode *conf) static OutputCtx *LogTlsLogInitCtx(ConfNode *conf)
{ {
if (OutputTlsLoggerEnable() != 0) {
SCLogError(SC_ERR_CONF_YAML_ERROR, "only one 'tls' logger "
"can be enabled");
return NULL;
}
LogFileCtx* file_ctx = LogFileNewCtx(); LogFileCtx* file_ctx = LogFileNewCtx();
if (file_ctx == NULL) { if (file_ctx == NULL) {

@ -194,6 +194,12 @@ static void JsonDropLogDeInitCtx(OutputCtx *output_ctx)
#define DEFAULT_LOG_FILENAME "drop.json" #define DEFAULT_LOG_FILENAME "drop.json"
static OutputCtx *JsonDropLogInitCtx(ConfNode *conf) static OutputCtx *JsonDropLogInitCtx(ConfNode *conf)
{ {
if (OutputDropLoggerEnable() != 0) {
SCLogError(SC_ERR_CONF_YAML_ERROR, "only one 'drop' logger "
"can be enabled");
return NULL;
}
LogFileCtx *logfile_ctx = LogFileNewCtx(); LogFileCtx *logfile_ctx = LogFileNewCtx();
if (logfile_ctx == NULL) { if (logfile_ctx == NULL) {
return NULL; return NULL;
@ -216,6 +222,12 @@ static OutputCtx *JsonDropLogInitCtx(ConfNode *conf)
static OutputCtx *JsonDropLogInitCtxSub(ConfNode *conf, OutputCtx *parent_ctx) static OutputCtx *JsonDropLogInitCtxSub(ConfNode *conf, OutputCtx *parent_ctx)
{ {
if (OutputDropLoggerEnable() != 0) {
SCLogError(SC_ERR_CONF_YAML_ERROR, "only one 'drop' logger "
"can be enabled");
return NULL;
}
AlertJsonThread *ajt = parent_ctx->data; AlertJsonThread *ajt = parent_ctx->data;
OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx)); OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx));

@ -217,6 +217,12 @@ static TmEcode JsonTlsLogThreadDeinit(ThreadVars *t, void *data)
#define DEFAULT_LOG_FILENAME "tls.json" #define DEFAULT_LOG_FILENAME "tls.json"
OutputCtx *OutputTlsLogInit(ConfNode *conf) OutputCtx *OutputTlsLogInit(ConfNode *conf)
{ {
if (OutputTlsLoggerEnable() != 0) {
SCLogError(SC_ERR_CONF_YAML_ERROR, "only one 'tls' logger "
"can be enabled");
return NULL;
}
LogFileCtx *file_ctx = LogFileNewCtx(); LogFileCtx *file_ctx = LogFileNewCtx();
if(file_ctx == NULL) { if(file_ctx == NULL) {
SCLogError(SC_ERR_HTTP_LOG_GENERIC, "couldn't create new file_ctx"); SCLogError(SC_ERR_HTTP_LOG_GENERIC, "couldn't create new file_ctx");
@ -258,6 +264,12 @@ OutputCtx *OutputTlsLogInitSub(ConfNode *conf, OutputCtx *parent_ctx)
{ {
AlertJsonThread *ajt = parent_ctx->data; AlertJsonThread *ajt = parent_ctx->data;
if (OutputTlsLoggerEnable() != 0) {
SCLogError(SC_ERR_CONF_YAML_ERROR, "only one 'tls' logger "
"can be enabled");
return NULL;
}
OutputTlsCtx *tls_ctx = SCMalloc(sizeof(OutputTlsCtx)); OutputTlsCtx *tls_ctx = SCMalloc(sizeof(OutputTlsCtx));
if (unlikely(tls_ctx == NULL)) if (unlikely(tls_ctx == NULL))
return NULL; return NULL;

@ -374,3 +374,22 @@ OutputDeregisterAll(void)
SCFree(module); SCFree(module);
} }
} }
static int drop_loggers = 0;
int OutputDropLoggerEnable(void) {
if (drop_loggers)
return -1;
drop_loggers++;
return 0;
}
static int tls_loggers = 0;
int OutputTlsLoggerEnable(void) {
if (tls_loggers)
return -1;
tls_loggers++;
return 0;
}

@ -83,4 +83,7 @@ void OutputRegisterFiledataSubModule(const char *parent_name, const char *name,
OutputModule *OutputGetModuleByConfName(const char *name); OutputModule *OutputGetModuleByConfName(const char *name);
void OutputDeregisterAll(void); void OutputDeregisterAll(void);
int OutputDropLoggerEnable(void);
int OutputTlsLoggerEnable(void);
#endif /* ! __OUTPUT_H__ */ #endif /* ! __OUTPUT_H__ */

Loading…
Cancel
Save