]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
output: introduce init return type
authorJason Ish <ish@unx.ca>
Thu, 11 Jan 2018 22:34:33 +0000 (16:34 -0600)
committerJason Ish <ish@unx.ca>
Thu, 18 Jan 2018 11:57:26 +0000 (05:57 -0600)
The new OutputInitResult is a struct return type that allows
logger init functions to return a NULL context without
raising error.

Instead of returning NULL to signal error, the "ok" field will
be set to false. If ok, but the ctx is NULL, then silently
move on to the next logger.

Use case: multiple versions of a specific logger, and one
implementation decides the configuration is not for that
implemenation. It can return NULL, ok.

43 files changed:
src/alert-debuglog.c
src/alert-fastlog.c
src/alert-fastlog.h
src/alert-prelude.c
src/alert-syslog.c
src/alert-unified2-alert.c
src/alert-unified2-alert.h
src/log-dnslog.c
src/log-droplog.c
src/log-file.c
src/log-filestore.c
src/log-httplog.c
src/log-httplog.h
src/log-pcap.c
src/log-stats.c
src/log-tcp-data.c
src/log-tcp-data.h
src/log-tlslog.c
src/log-tlsstore.c
src/output-json-alert.c
src/output-json-dnp3.c
src/output-json-dns.c
src/output-json-drop.c
src/output-json-file.c
src/output-json-flow.c
src/output-json-http.c
src/output-json-netflow.c
src/output-json-nfs.c
src/output-json-smtp.c
src/output-json-ssh.c
src/output-json-stats.c
src/output-json-template.c
src/output-json-tls.c
src/output-json-vars.c
src/output-json.c
src/output-json.h
src/output-lua.c
src/output.h
src/runmode-af-packet.c
src/runmode-netmap.c
src/runmode-pcap.c
src/runmodes.c
src/util-runmodes.c

index 68ffd978f057e587082b7612dfac3db89c4d0fdb..e2d1fb85dddc19c69b4fd1c8b0c230e5d90f41d2 100644 (file)
@@ -430,8 +430,9 @@ static void AlertDebugLogDeInitCtx(OutputCtx *output_ctx)
  *
  *  \return output_ctx if succesful, NULL otherwise
  */
-static OutputCtx *AlertDebugLogInitCtx(ConfNode *conf)
+static OutputInitResult AlertDebugLogInitCtx(ConfNode *conf)
 {
+    OutputInitResult result = { NULL, false };
     LogFileCtx *file_ctx = NULL;
 
     file_ctx = LogFileNewCtx();
@@ -453,14 +454,16 @@ static OutputCtx *AlertDebugLogInitCtx(ConfNode *conf)
     output_ctx->DeInit = AlertDebugLogDeInitCtx;
 
     SCLogDebug("Alert debug log output initialized");
-    return output_ctx;
+    result.ctx = output_ctx;
+    result.ok = true;
+    return result;
 
 error:
     if (file_ctx != NULL) {
         LogFileFreeCtx(file_ctx);
     }
 
-    return NULL;
+    return result;
 }
 
 static int AlertDebugLogCondition(ThreadVars *tv, const Packet *p)
index b7fcf5593d01ca9882571ec947127bc5e5e44127..ca62155a025b6a9d4f70f7f1b1993dcb21c7efe0 100644 (file)
@@ -220,26 +220,29 @@ TmEcode AlertFastLogThreadDeinit(ThreadVars *t, void *data)
  * \param conf The configuration node for this output.
  * \return A LogFileCtx pointer on success, NULL on failure.
  */
-OutputCtx *AlertFastLogInitCtx(ConfNode *conf)
+OutputInitResult AlertFastLogInitCtx(ConfNode *conf)
 {
+    OutputInitResult result = { NULL, false };
     LogFileCtx *logfile_ctx = LogFileNewCtx();
     if (logfile_ctx == NULL) {
         SCLogDebug("AlertFastLogInitCtx2: Could not create new LogFileCtx");
-        return NULL;
+        return result;
     }
 
     if (SCConfLogOpenGeneric(conf, logfile_ctx, DEFAULT_LOG_FILENAME, 1) < 0) {
         LogFileFreeCtx(logfile_ctx);
-        return NULL;
+        return result;
     }
 
     OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx));
     if (unlikely(output_ctx == NULL))
-        return NULL;
+        return result;
     output_ctx->data = logfile_ctx;
     output_ctx->DeInit = AlertFastLogDeInitCtx;
 
-    return output_ctx;
+    result.ctx = output_ctx;
+    result.ok = true;
+    return result;
 }
 
 static void AlertFastLogDeInitCtx(OutputCtx *output_ctx)
index 96bd0118abc95111993e7234575b44b9df9dbe15..c2e825096fb044b3c8ed34e66a408b22ab3b85f9 100644 (file)
@@ -27,7 +27,7 @@
 void AlertFastLogRegister(void);
 void TmModuleAlertFastLogIPv4Register(void);
 void TmModuleAlertFastLogIPv6Register(void);
-OutputCtx *AlertFastLogInitCtx(ConfNode *);
+OutputInitResult AlertFastLogInitCtx(ConfNode *);
 
 #endif /* __ALERT_FASTLOG_H__ */
 
index 1f654ee7f3eb13224acb758682dda04f7755521c..9903fef7c74f0a0f098e173ad514b85d21bfa63c 100644 (file)
@@ -778,7 +778,7 @@ static void AlertPreludeDeinitCtx(OutputCtx *output_ctx)
  *
  * \return A newly allocated AlertPreludeCtx structure, or NULL
  */
-static OutputCtx *AlertPreludeInitCtx(ConfNode *conf)
+static OutputInitResult AlertPreludeInitCtx(ConfNode *conf)
 {
     int ret;
     prelude_client_t *client;
@@ -786,6 +786,7 @@ static OutputCtx *AlertPreludeInitCtx(ConfNode *conf)
     const char *prelude_profile_name;
     const char *log_packet_content;
     const char *log_packet_header;
+    OutputInitResult result = { NULL, false };
     OutputCtx *output_ctx;
 
     SCEnter();
@@ -793,7 +794,7 @@ static OutputCtx *AlertPreludeInitCtx(ConfNode *conf)
     ret = prelude_init(0, NULL);
     if (unlikely(ret < 0)) {
         prelude_perror(ret, "unable to initialize the prelude library");
-        SCReturnPtr(NULL, "AlertPreludeCtx");
+        SCReturnCT(result, "OutputInitResult");
     }
 
     prelude_profile_name = ConfNodeLookupChildValue(conf, "profile");
@@ -807,35 +808,35 @@ static OutputCtx *AlertPreludeInitCtx(ConfNode *conf)
     if ( unlikely(ret < 0 || client == NULL )) {
         prelude_perror(ret, "Unable to create a prelude client object");
         prelude_client_destroy(client, PRELUDE_CLIENT_EXIT_STATUS_SUCCESS);
-        SCReturnPtr(NULL, "AlertPreludeCtx");
+        SCReturnCT(result, "OutputInitResult");
     }
 
     ret = prelude_client_set_flags(client, prelude_client_get_flags(client) | PRELUDE_CLIENT_FLAGS_ASYNC_TIMER|PRELUDE_CLIENT_FLAGS_ASYNC_SEND);
     if (unlikely(ret < 0)) {
         SCLogDebug("Unable to set asynchronous send and timer.");
         prelude_client_destroy(client, PRELUDE_CLIENT_EXIT_STATUS_SUCCESS);
-        SCReturnPtr(NULL, "AlertPreludeCtx");
+        SCReturnCT(result, "OutputInitResult");
     }
 
     ret = SetupAnalyzer(prelude_client_get_analyzer(client));
     if (ret < 0) {
         SCLogDebug("Unable to setup prelude client analyzer.");
         prelude_client_destroy(client, PRELUDE_CLIENT_EXIT_STATUS_SUCCESS);
-        SCReturnPtr(NULL, "AlertPreludeCtx");
+        SCReturnCT(result, "OutputInitResult");
     }
 
     ret = prelude_client_start(client);
     if (unlikely(ret < 0)) {
         prelude_perror(ret, "Unable to start prelude client");
         prelude_client_destroy(client, PRELUDE_CLIENT_EXIT_STATUS_SUCCESS);
-        SCReturnPtr(NULL, "AlertPreludeCtx");
+        SCReturnCT(result, "OutputInitResult");
     }
 
     ctx = SCMalloc(sizeof(AlertPreludeCtx));
     if (unlikely(ctx == NULL)) {
         prelude_perror(ret, "Unable to allocate memory");
         prelude_client_destroy(client, PRELUDE_CLIENT_EXIT_STATUS_SUCCESS);
-        SCReturnPtr(NULL, "AlertPreludeCtx");
+        SCReturnCT(result, "OutputInitResult");
     }
 
     ctx->client = client;
@@ -851,13 +852,15 @@ static OutputCtx *AlertPreludeInitCtx(ConfNode *conf)
         SCFree(ctx);
         prelude_perror(ret, "Unable to allocate memory");
         prelude_client_destroy(client, PRELUDE_CLIENT_EXIT_STATUS_SUCCESS);
-        SCReturnPtr(NULL, "AlertPreludeCtx");
+        SCReturnCT(result, "OutputInitResult");
     }
 
     output_ctx->data = ctx;
     output_ctx->DeInit = AlertPreludeDeinitCtx;
 
-    SCReturnPtr((void*)output_ctx, "OutputCtx");
+    result.ctx = output_ctx;
+    result.ok = true;
+    SCReturnCT(result, "OutputInitResult");
 }
 
 static int AlertPreludeCondition(ThreadVars *tv, const Packet *p)
index 51b78bf2412349b74d58f23592bf8f5893255d7a..466ceb77e26ec7991b36f81981587914354a1bef 100644 (file)
@@ -88,8 +88,9 @@ static void AlertSyslogDeInitCtx(OutputCtx *output_ctx)
  * \param conf The configuration node for this output.
  * \return A OutputCtx pointer on success, NULL on failure.
  */
-static OutputCtx *AlertSyslogInitCtx(ConfNode *conf)
+static OutputInitResult AlertSyslogInitCtx(ConfNode *conf)
 {
+    OutputInitResult result = { NULL, false };
     const char *facility_s = ConfNodeLookupChildValue(conf, "facility");
     if (facility_s == NULL) {
         facility_s = DEFAULT_ALERT_SYSLOG_FACILITY_STR;
@@ -98,7 +99,7 @@ static OutputCtx *AlertSyslogInitCtx(ConfNode *conf)
     LogFileCtx *logfile_ctx = LogFileNewCtx();
     if (logfile_ctx == NULL) {
         SCLogDebug("AlertSyslogInitCtx: Could not create new LogFileCtx");
-        return NULL;
+        return result;
     }
 
     int facility = SCMapEnumNameToValue(facility_s, SCSyslogGetFacilityMap());
@@ -126,7 +127,7 @@ static OutputCtx *AlertSyslogInitCtx(ConfNode *conf)
     OutputCtx *output_ctx = SCMalloc(sizeof(OutputCtx));
     if (unlikely(output_ctx == NULL)) {
         SCLogDebug("AlertSyslogInitCtx: Could not create new OutputCtx");
-        return NULL;
+        return result;
     }
     memset(output_ctx, 0x00, sizeof(OutputCtx));
 
@@ -135,7 +136,9 @@ static OutputCtx *AlertSyslogInitCtx(ConfNode *conf)
 
     SCLogInfo("Syslog output initialized");
 
-    return output_ctx;
+    result.ctx = output_ctx;
+    result.ok = true;
+    return result;
 }
 
 /**
index 4d92bcc7039e6333aa408d304e9b251a5aa7e1c8..608a2f5b44c6c326e8eaac372c4d1d4be734b704 100644 (file)
@@ -38,6 +38,8 @@
 #include "threadvars.h"
 #include "tm-threads.h"
 
+#include "output.h"
+
 #include "util-unittest.h"
 #include "alert-unified2-alert.h"
 #include "decode-ipv4.h"
@@ -58,7 +60,6 @@
 #include "app-layer.h"
 #include "app-layer-htp-xff.h"
 
-#include "output.h"
 #include "util-privs.h"
 
 #include "stream.h"
@@ -1218,8 +1219,9 @@ error:
  *  \param conf The configuration node for this output.
  *  \return NULL if failure, LogFileCtx* to the file_ctx if succesful
  * */
-OutputCtx *Unified2AlertInitCtx(ConfNode *conf)
+OutputInitResult Unified2AlertInitCtx(ConfNode *conf)
 {
+    OutputInitResult result = { NULL, false };
     int ret = 0;
     LogFileCtx* file_ctx = NULL;
     OutputCtx* output_ctx = NULL;
@@ -1341,7 +1343,9 @@ OutputCtx *Unified2AlertInitCtx(ConfNode *conf)
 
     SC_ATOMIC_INIT(unified2_event_id);
 
-    return output_ctx;
+    result.ctx = output_ctx;
+    result.ok = true;
+    return result;
 
 error:
     if (xff_cfg != NULL) {
@@ -1351,7 +1355,7 @@ error:
         SCFree(output_ctx);
     }
 
-    return NULL;
+    return result;
 }
 
 static void Unified2AlertDeInitCtx(OutputCtx *output_ctx)
@@ -1444,7 +1448,7 @@ static int Unified2Test01(void)
     DecodeThreadVars dtv;
     PacketQueue pq;
     void *data = NULL;
-    OutputCtx *oc;
+    OutputInitResult oc;
     LogFileCtx *lf;
     Unified2AlertFileCtx *uaf = NULL;
     Signature s;
@@ -1483,17 +1487,17 @@ static int Unified2Test01(void)
 
 
     oc = Unified2AlertInitCtx(NULL);
-    if (oc == NULL) {
+    if (oc.ctx == NULL) {
         goto end;
     }
-    uaf = oc->data;
+    uaf = oc.ctx->data;
     if (uaf == NULL)
         return 0;
     lf = uaf->file_ctx;
     if(lf == NULL) {
         goto end;
     }
-    ret = Unified2AlertThreadInit(&tv, oc, &data);
+    ret = Unified2AlertThreadInit(&tv, oc.ctx, &data);
     if(ret == TM_ECODE_FAILED) {
         goto end;
     }
@@ -1506,7 +1510,7 @@ static int Unified2Test01(void)
         goto end;
     }
 
-    Unified2AlertDeInitCtx(oc);
+    Unified2AlertDeInitCtx(oc.ctx);
 
     PACKET_RECYCLE(p);
     SCFree(p);
@@ -1533,7 +1537,7 @@ static int Unified2Test02(void)
     DecodeThreadVars dtv;
     PacketQueue pq;
     void *data = NULL;
-    OutputCtx *oc;
+    OutputInitResult oc;
     LogFileCtx *lf;
     Unified2AlertFileCtx *uaf = NULL;
     Signature s;
@@ -1573,17 +1577,17 @@ static int Unified2Test02(void)
     DecodeEthernet(&tv, &dtv, p, raw_ipv6_tcp, sizeof(raw_ipv6_tcp), &pq);
 
     oc = Unified2AlertInitCtx(NULL);
-    if (oc == NULL) {
+    if (oc.ctx == NULL) {
         goto end;
     }
-    uaf = oc->data;
+    uaf = oc.ctx->data;
     if (uaf == NULL)
         return 0;
     lf = uaf->file_ctx;
     if(lf == NULL) {
         goto end;
     }
-    ret = Unified2AlertThreadInit(&tv, oc, &data);
+    ret = Unified2AlertThreadInit(&tv, oc.ctx, &data);
     if(ret == -1) {
         goto end;
     }
@@ -1596,7 +1600,7 @@ static int Unified2Test02(void)
         goto end;
     }
 
-    Unified2AlertDeInitCtx(oc);
+    Unified2AlertDeInitCtx(oc.ctx);
 
     PACKET_RECYCLE(p);
     SCFree(p);
@@ -1624,7 +1628,7 @@ static int Unified2Test03(void)
     DecodeThreadVars dtv;
     PacketQueue pq;
     void *data = NULL;
-    OutputCtx *oc;
+    OutputInitResult oc;
     LogFileCtx *lf;
     Unified2AlertFileCtx *uaf = NULL;
     Signature s;
@@ -1670,17 +1674,17 @@ static int Unified2Test03(void)
     DecodeEthernet(&tv, &dtv, p, raw_gre, sizeof(raw_gre), &pq);
 
     oc = Unified2AlertInitCtx(NULL);
-    if (oc == NULL) {
+    if (oc.ctx == NULL) {
         goto end;
     }
-    uaf = oc->data;
+    uaf = oc.ctx->data;
     if (uaf == NULL)
         return 0;
     lf = uaf->file_ctx;
     if(lf == NULL) {
         goto end;
     }
-    ret = Unified2AlertThreadInit(&tv, oc, &data);
+    ret = Unified2AlertThreadInit(&tv, oc.ctx, &data);
     if(ret == -1) {
         goto end;
     }
@@ -1693,7 +1697,7 @@ static int Unified2Test03(void)
         goto end;
     }
 
-    Unified2AlertDeInitCtx(oc);
+    Unified2AlertDeInitCtx(oc.ctx);
 
     pkt = PacketDequeue(&pq);
     while (pkt != NULL) {
@@ -1733,7 +1737,7 @@ static int Unified2Test04(void)
     DecodeThreadVars dtv;
     PacketQueue pq;
     void *data = NULL;
-    OutputCtx *oc;
+    OutputInitResult oc;
     LogFileCtx *lf;
     Unified2AlertFileCtx *uaf = NULL;
     Signature s;
@@ -1767,17 +1771,17 @@ static int Unified2Test04(void)
     DecodePPP(&tv, &dtv, p, raw_ppp, sizeof(raw_ppp), &pq);
 
     oc = Unified2AlertInitCtx(NULL);
-    if (oc == NULL) {
+    if (oc.ctx == NULL) {
         goto end;
     }
-    uaf = oc->data;
+    uaf = oc.ctx->data;
     if (uaf == NULL)
         return 0;
     lf = uaf->file_ctx;
     if(lf == NULL) {
         goto end;
     }
-    ret = Unified2AlertThreadInit(&tv, oc, &data);
+    ret = Unified2AlertThreadInit(&tv, oc.ctx, &data);
     if(ret == -1) {
         goto end;
     }
@@ -1790,7 +1794,7 @@ static int Unified2Test04(void)
         goto end;
     }
 
-    Unified2AlertDeInitCtx(oc);
+    Unified2AlertDeInitCtx(oc.ctx);
 
     PACKET_RECYCLE(p);
     SCFree(p);
@@ -1817,7 +1821,7 @@ static int Unified2Test05(void)
     DecodeThreadVars dtv;
     PacketQueue pq;
     void *data = NULL;
-    OutputCtx *oc;
+    OutputInitResult oc;
     LogFileCtx *lf;
     Unified2AlertFileCtx *uaf = NULL;
     Signature s;
@@ -1857,17 +1861,17 @@ static int Unified2Test05(void)
     p->action = ACTION_DROP;
 
     oc = Unified2AlertInitCtx(NULL);
-    if (oc == NULL) {
+    if (oc.ctx == NULL) {
         goto end;
     }
-    uaf = oc->data;
+    uaf = oc.ctx->data;
     if (uaf == NULL)
         return 0;
     lf = uaf->file_ctx;
     if(lf == NULL) {
         goto end;
     }
-    ret = Unified2AlertThreadInit(&tv, oc, &data);
+    ret = Unified2AlertThreadInit(&tv, oc.ctx, &data);
     if(ret == -1) {
         goto end;
     }
@@ -1880,7 +1884,7 @@ static int Unified2Test05(void)
         goto end;
     }
 
-    Unified2AlertDeInitCtx(oc);
+    Unified2AlertDeInitCtx(oc.ctx);
 
     PACKET_RECYCLE(p);
     SCFree(p);
@@ -1905,16 +1909,16 @@ static int Unified2TestRotate01(void)
     int ret = 0;
     int r = 0;
     ThreadVars tv;
-    OutputCtx *oc;
+    OutputInitResult oc;
     LogFileCtx *lf;
     Unified2AlertFileCtx *uaf = NULL;
     void *data = NULL;
     char *filename = NULL;
 
     oc = Unified2AlertInitCtx(NULL);
-    if (oc == NULL)
+    if (oc.ctx == NULL)
         return 0;
-    uaf = oc->data;
+    uaf = oc.ctx->data;
     if (uaf == NULL)
         return 0;
     lf = uaf->file_ctx;
@@ -1926,7 +1930,7 @@ static int Unified2TestRotate01(void)
 
     memset(&tv, 0, sizeof(ThreadVars));
 
-    ret = Unified2AlertThreadInit(&tv, oc, &data);
+    ret = Unified2AlertThreadInit(&tv, oc.ctx, &data);
     if (ret == TM_ECODE_FAILED) {
         LogFileFreeCtx(lf);
         if (filename != NULL)
@@ -1953,8 +1957,8 @@ error:
     if(ret == TM_ECODE_FAILED) {
         printf("Unified2AlertThreadDeinit error");
     }
-    if (oc != NULL)
-        Unified2AlertDeInitCtx(oc);
+    if (oc.ctx != NULL)
+        Unified2AlertDeInitCtx(oc.ctx);
     if (filename != NULL)
         SCFree(filename);
     return r;
index ae068a1d4e89c55b29e060ba8956ffb40b0949e7..f6cf0e3d870d203a37a533144ebe8ff8e317d3dc 100644 (file)
@@ -44,7 +44,7 @@
 #define UNIFIED2_EXTRADATA_TYPE_EXTRA_DATA 4
 
 void Unified2AlertRegister(void);
-OutputCtx *Unified2AlertInitCtx(ConfNode *);
+OutputInitResult Unified2AlertInitCtx(ConfNode *);
 
 #endif /* __ALERT_UNIFIED2_ALERT_H__ */
 
index 31867ba748af5404b04b69287048aaf132378f57..2e4b628b11540ab87c99790e4a87a00ec041d216 100644 (file)
@@ -315,24 +315,25 @@ static void LogDnsLogDeInitCtx(OutputCtx *output_ctx)
  *  \param conf Pointer to ConfNode containing this loggers configuration.
  *  \return NULL if failure, LogFileCtx* to the file_ctx if succesful
  * */
-static OutputCtx *LogDnsLogInitCtx(ConfNode *conf)
+static OutputInitResult LogDnsLogInitCtx(ConfNode *conf)
 {
+    OutputInitResult result = { NULL, false };
     LogFileCtx* file_ctx = LogFileNewCtx();
 
     if(file_ctx == NULL) {
         SCLogError(SC_ERR_DNS_LOG_GENERIC, "couldn't create new file_ctx");
-        return NULL;
+        return result;
     }
 
     if (SCConfLogOpenGeneric(conf, file_ctx, DEFAULT_LOG_FILENAME, 1) < 0) {
         LogFileFreeCtx(file_ctx);
-        return NULL;
+        return result;
     }
 
     LogDnsFileCtx *dnslog_ctx = SCMalloc(sizeof(LogDnsFileCtx));
     if (unlikely(dnslog_ctx == NULL)) {
         LogFileFreeCtx(file_ctx);
-        return NULL;
+        return result;
     }
     memset(dnslog_ctx, 0x00, sizeof(LogDnsFileCtx));
 
@@ -342,7 +343,7 @@ static OutputCtx *LogDnsLogInitCtx(ConfNode *conf)
     if (unlikely(output_ctx == NULL)) {
         LogFileFreeCtx(file_ctx);
         SCFree(dnslog_ctx);
-        return NULL;
+        return result;
     }
 
     output_ctx->data = dnslog_ctx;
@@ -353,7 +354,9 @@ static OutputCtx *LogDnsLogInitCtx(ConfNode *conf)
     AppLayerParserRegisterLogger(IPPROTO_UDP, ALPROTO_DNS);
     AppLayerParserRegisterLogger(IPPROTO_TCP, ALPROTO_DNS);
 
-    return output_ctx;
+    result.ctx = output_ctx;
+    result.ok = true;
+    return result;
 }
 
 #endif /* !HAVE_RUST */
index d4187111155aca09512f2b436ee9dba3e76e0a6f..1e11ea31e90374b3e31955ac88691b9e1428ef1e 100644 (file)
@@ -135,34 +135,37 @@ static void LogDropLogDeInitCtx(OutputCtx *output_ctx)
  * \param conf The configuration node for this output.
  * \return A LogFileCtx pointer on success, NULL on failure.
  */
-static OutputCtx *LogDropLogInitCtx(ConfNode *conf)
+static OutputInitResult LogDropLogInitCtx(ConfNode *conf)
 {
+    OutputInitResult result = { NULL, false };
     if (OutputDropLoggerEnable() != 0) {
         SCLogError(SC_ERR_CONF_YAML_ERROR, "only one 'drop' logger "
             "can be enabled");
-        return NULL;
+        return result;
     }
 
     LogFileCtx *logfile_ctx = LogFileNewCtx();
     if (logfile_ctx == NULL) {
         SCLogDebug("LogDropLogInitCtx: Could not create new LogFileCtx");
-        return NULL;
+        return result;
     }
 
     if (SCConfLogOpenGeneric(conf, logfile_ctx, DEFAULT_LOG_FILENAME, 1) < 0) {
         LogFileFreeCtx(logfile_ctx);
-        return NULL;
+        return result;
     }
 
     OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx));
     if (unlikely(output_ctx == NULL)) {
         LogFileFreeCtx(logfile_ctx);
-        return NULL;
+        return result;
     }
     output_ctx->data = logfile_ctx;
     output_ctx->DeInit = LogDropLogDeInitCtx;
 
-    return output_ctx;
+    result.ctx = output_ctx;
+    result.ok = true;
+    return result;
 }
 
 /**
index 2cc16e81d1b05ac382fd549de9b119000f62fe6f..63a85e8f862e024fb26af87b5c03de16247f7287 100644 (file)
@@ -412,22 +412,23 @@ static void LogFileLogDeInitCtx(OutputCtx *output_ctx)
  *  \param conf Pointer to ConfNode containing this loggers configuration.
  *  \return NULL if failure, LogFileCtx* to the file_ctx if succesful
  * */
-static OutputCtx *LogFileLogInitCtx(ConfNode *conf)
+static OutputInitResult LogFileLogInitCtx(ConfNode *conf)
 {
+    OutputInitResult result = { NULL, false };
     LogFileCtx *logfile_ctx = LogFileNewCtx();
     if (logfile_ctx == NULL) {
         SCLogDebug("Could not create new LogFileCtx");
-        return NULL;
+        return result;
     }
 
     if (SCConfLogOpenGeneric(conf, logfile_ctx, DEFAULT_LOG_FILENAME, 1) < 0) {
         LogFileFreeCtx(logfile_ctx);
-        return NULL;
+        return result;
     }
 
     OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx));
     if (unlikely(output_ctx == NULL))
-        return NULL;
+        return result;
 
     output_ctx->data = logfile_ctx;
     output_ctx->DeInit = LogFileLogDeInitCtx;
@@ -446,7 +447,10 @@ static OutputCtx *LogFileLogInitCtx(ConfNode *conf)
 
     FileForceHashParseCfg(conf);
     FileForceTrackingEnable();
-    SCReturnPtr(output_ctx, "OutputCtx");
+
+    result.ctx = output_ctx;
+    result.ok = true;
+    SCReturnCT(result, "OutputInitResult");
 }
 
 void LogFileLogRegister (void)
index f8f84616c87df48ef818df6f2ed1ee2f3b559cd4..3160be949b14624c231e42a9cfa2d172c5ff661f 100644 (file)
@@ -572,11 +572,12 @@ static void LogFilestoreLogDeInitCtx(OutputCtx *output_ctx)
  *  \param conf Pointer to ConfNode containing this loggers configuration.
  *  \return NULL if failure, LogFilestoreCtx* to the file_ctx if succesful
  * */
-static OutputCtx *LogFilestoreLogInitCtx(ConfNode *conf)
+static OutputInitResult LogFilestoreLogInitCtx(ConfNode *conf)
 {
+    OutputInitResult result = { NULL, false };
     OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx));
     if (unlikely(output_ctx == NULL))
-        return NULL;
+        return result;
 
     output_ctx->data = NULL;
     output_ctx->DeInit = LogFilestoreLogDeInitCtx;
@@ -660,7 +661,9 @@ static OutputCtx *LogFilestoreLogInitCtx(ConfNode *conf)
         SCLogInfo("enabling pid as a part of all file names");
     }
 
-    SCReturnPtr(output_ctx, "OutputCtx");
+    result.ctx = output_ctx;
+    result.ok = true;
+    SCReturnCT(result, "OutputInitResult");
 }
 
 
index 203e6e7b9917e3b6d010ca86e5338f05f6c1b1f8..ab67859bf1f8826ecf56c809750e4a5c5310cc0d 100644 (file)
@@ -549,23 +549,24 @@ TmEcode LogHttpLogThreadDeinit(ThreadVars *t, void *data)
  *  \param conf Pointer to ConfNode containing this loggers configuration.
  *  \return NULL if failure, LogFileCtx* to the file_ctx if succesful
  * */
-OutputCtx *LogHttpLogInitCtx(ConfNode *conf)
+OutputInitResult LogHttpLogInitCtx(ConfNode *conf)
 {
+    OutputInitResult result = { NULL, false };
     LogFileCtx* file_ctx = LogFileNewCtx();
     if(file_ctx == NULL) {
         SCLogError(SC_ERR_HTTP_LOG_GENERIC, "couldn't create new file_ctx");
-        return NULL;
+        return result;
     }
 
     if (SCConfLogOpenGeneric(conf, file_ctx, DEFAULT_LOG_FILENAME, 1) < 0) {
         LogFileFreeCtx(file_ctx);
-        return NULL;
+        return result;
     }
 
     LogHttpFileCtx *httplog_ctx = SCMalloc(sizeof(LogHttpFileCtx));
     if (unlikely(httplog_ctx == NULL)) {
         LogFileFreeCtx(file_ctx);
-        return NULL;
+        return result;
     }
     memset(httplog_ctx, 0x00, sizeof(LogHttpFileCtx));
 
@@ -612,7 +613,9 @@ OutputCtx *LogHttpLogInitCtx(ConfNode *conf)
     /* enable the logger for the app layer */
     AppLayerParserRegisterLogger(IPPROTO_TCP, ALPROTO_HTTP);
 
-    return output_ctx;
+    result.ctx = output_ctx;
+    result.ok = true;
+    return result;
 
 parsererror:
     SCLogError(SC_ERR_INVALID_ARGUMENT,"Syntax error in custom http log format string.");
@@ -620,7 +623,7 @@ errorfree:
     LogCustomFormatFree(httplog_ctx->cf);
     LogFileFreeCtx(file_ctx);
     SCFree(httplog_ctx);
-    return NULL;
+    return result;
 
 }
 
index e8fccb65dab4797fd0e533a7ee000a666e8819f7..4f7d5776968d541845be6f9f18c5afb04c598694 100644 (file)
@@ -27,7 +27,7 @@
 void LogHttpLogRegister(void);
 void TmModuleLogHttpLogIPv4Register (void);
 void TmModuleLogHttpLogIPv6Register (void);
-OutputCtx *LogHttpLogInitCtx(ConfNode *);
+OutputInitResult LogHttpLogInitCtx(ConfNode *);
 
 #endif /* __LOG_HTTPLOG_H__ */
 
index 0fcf5c7f593951ab4ce6caca0ad285910f782106..c71ad07b7139e15b63535032baf83f72c9ed8a95 100644 (file)
@@ -170,7 +170,7 @@ static int PcapLog(ThreadVars *, void *, const Packet *);
 static TmEcode PcapLogDataInit(ThreadVars *, const void *, void **);
 static TmEcode PcapLogDataDeinit(ThreadVars *, void *);
 static void PcapLogFileDeInitCtx(OutputCtx *);
-static OutputCtx *PcapLogInitCtx(ConfNode *);
+static OutputInitResult PcapLogInitCtx(ConfNode *);
 static void PcapLogProfilingDump(PcapLogData *);
 static int PcapLogCondition(ThreadVars *, const Packet *);
 
@@ -931,8 +931,9 @@ error:
  *  \param conf The configuration node for this output.
  *  \retval output_ctx
  * */
-static OutputCtx *PcapLogInitCtx(ConfNode *conf)
+static OutputInitResult PcapLogInitCtx(ConfNode *conf)
 {
+    OutputInitResult result = { NULL, false };
     const char *pcre_errbuf;
     int pcre_erroffset;
 
@@ -1162,7 +1163,9 @@ static OutputCtx *PcapLogInitCtx(ConfNode *conf)
     output_ctx->DeInit = PcapLogFileDeInitCtx;
     g_pcap_data = pl;
 
-    return output_ctx;
+    result.ctx = output_ctx;
+    result.ok = true;
+    return result;
 }
 
 static void PcapLogFileDeInitCtx(OutputCtx *output_ctx)
index 138eef0027c1e405b8c864cc199c6173c80e7a85..011945924d240d9384c3117b0ad9fb3d8801611b 100644 (file)
@@ -210,23 +210,24 @@ TmEcode LogStatsLogThreadDeinit(ThreadVars *t, void *data)
  *  \param conf Pointer to ConfNode containing this loggers configuration.
  *  \return NULL if failure, LogFileCtx* to the file_ctx if succesful
  * */
-static OutputCtx *LogStatsLogInitCtx(ConfNode *conf)
+static OutputInitResult LogStatsLogInitCtx(ConfNode *conf)
 {
+    OutputInitResult result = { NULL, false };
     LogFileCtx *file_ctx = LogFileNewCtx();
     if (file_ctx == NULL) {
         SCLogError(SC_ERR_STATS_LOG_GENERIC, "couldn't create new file_ctx");
-        return NULL;
+        return result;
     }
 
     if (SCConfLogOpenGeneric(conf, file_ctx, DEFAULT_LOG_FILENAME, 1) < 0) {
         LogFileFreeCtx(file_ctx);
-        return NULL;
+        return result;
     }
 
     LogStatsFileCtx *statslog_ctx = SCMalloc(sizeof(LogStatsFileCtx));
     if (unlikely(statslog_ctx == NULL)) {
         LogFileFreeCtx(file_ctx);
-        return NULL;
+        return result;
     }
     memset(statslog_ctx, 0x00, sizeof(LogStatsFileCtx));
 
@@ -244,7 +245,7 @@ static OutputCtx *LogStatsLogInitCtx(ConfNode *conf)
             SCFree(statslog_ctx);
             SCLogError(SC_ERR_STATS_LOG_NEGATED,
                     "Cannot disable both totals and threads in stats logging");
-            return NULL;
+            return result;
         }
 
         if (totals != NULL && ConfValIsFalse(totals)) {
@@ -265,7 +266,7 @@ static OutputCtx *LogStatsLogInitCtx(ConfNode *conf)
     if (unlikely(output_ctx == NULL)) {
         LogFileFreeCtx(file_ctx);
         SCFree(statslog_ctx);
-        return NULL;
+        return result;
     }
 
     output_ctx->data = statslog_ctx;
@@ -273,7 +274,9 @@ static OutputCtx *LogStatsLogInitCtx(ConfNode *conf)
 
     SCLogDebug("STATS log output initialized");
 
-    return output_ctx;
+    result.ctx = output_ctx;
+    result.ok = true;
+    return result;
 }
 
 static void LogStatsLogDeInitCtx(OutputCtx *output_ctx)
index 9be178a8a7366d7d0b080f07e1b15c622dea1013..f9e5a5d4261eacd6927e13b902b45a386293eee3 100644 (file)
@@ -225,8 +225,9 @@ TmEcode LogTcpDataLogThreadDeinit(ThreadVars *t, void *data)
  *  \param conf Pointer to ConfNode containing this loggers configuration.
  *  \return NULL if failure, LogFileCtx* to the file_ctx if succesful
  * */
-OutputCtx *LogTcpDataLogInitCtx(ConfNode *conf)
+OutputInitResult LogTcpDataLogInitCtx(ConfNode *conf)
 {
+    OutputInitResult result = { NULL, false };
     char filename[PATH_MAX] = "";
     char dirname[32] = "";
     strlcpy(filename, DEFAULT_LOG_FILENAME, sizeof(filename));
@@ -234,13 +235,13 @@ OutputCtx *LogTcpDataLogInitCtx(ConfNode *conf)
     LogFileCtx *file_ctx = LogFileNewCtx();
     if(file_ctx == NULL) {
         SCLogError(SC_ERR_TCPDATA_LOG_GENERIC, "couldn't create new file_ctx");
-        return NULL;
+        return result;
     }
 
     LogTcpDataFileCtx *tcpdatalog_ctx = SCMalloc(sizeof(LogTcpDataFileCtx));
     if (unlikely(tcpdatalog_ctx == NULL)) {
         LogFileFreeCtx(file_ctx);
-        return NULL;
+        return result;
     }
     memset(tcpdatalog_ctx, 0x00, sizeof(LogTcpDataFileCtx));
 
@@ -281,7 +282,7 @@ OutputCtx *LogTcpDataLogInitCtx(ConfNode *conf)
         if (SCConfLogOpenGeneric(conf, file_ctx, filename, 1) < 0) {
             LogFileFreeCtx(file_ctx);
             SCFree(tcpdatalog_ctx);
-            return NULL;
+            return result;
         }
     }
 
@@ -307,13 +308,15 @@ OutputCtx *LogTcpDataLogInitCtx(ConfNode *conf)
     output_ctx->DeInit = LogTcpDataLogDeInitCtx;
 
     SCLogDebug("Streaming log output initialized");
-    return output_ctx;
+    result.ctx = output_ctx;
+    result.ok = true;
+    return result;
 
 parsererror:
     LogFileFreeCtx(file_ctx);
     SCFree(tcpdatalog_ctx);
     SCLogError(SC_ERR_INVALID_ARGUMENT,"Syntax error in custom http log format string.");
-    return NULL;
+    return result;
 
 }
 
index fcfe19442b598cd63072d3b21a5826bc9a7585d7..d23f8e7d7bb2a93c65a7f74032f510b44fcc2ef8 100644 (file)
@@ -25,6 +25,6 @@
 #define __LOG_TCPDATALOG_H__
 
 void LogTcpDataLogRegister(void);
-OutputCtx *LogTcpDataLogInitCtx(ConfNode *);
+OutputInitResult LogTcpDataLogInitCtx(ConfNode *);
 
 #endif /* __LOG_TCPDATALOG_H__ */
index 1081864a2b930e6c1cd01f16fac66b05c0941146..590cbabaeb280413697ddacfb6a28adc7b8460d4 100644 (file)
@@ -264,14 +264,15 @@ static void LogTlsLogExitPrintStats(ThreadVars *tv, void *data)
  *  \param conf Pointer to ConfNode containing this loggers configuration.
  *  \return NULL if failure, LogFileCtx* to the file_ctx if succesful
  * */
-static OutputCtx *LogTlsLogInitCtx(ConfNode *conf)
+static OutputInitResult LogTlsLogInitCtx(ConfNode *conf)
 {
+    OutputInitResult result = { NULL, false };
     LogFileCtx* file_ctx = LogFileNewCtx();
 
     if (file_ctx == NULL) {
         SCLogError(SC_ERR_TLS_LOG_GENERIC, "LogTlsLogInitCtx: Couldn't "
         "create new file_ctx");
-        return NULL;
+        return result;
     }
 
     if (SCConfLogOpenGeneric(conf, file_ctx, DEFAULT_LOG_FILENAME, 1) < 0) {
@@ -325,7 +326,9 @@ static OutputCtx *LogTlsLogInitCtx(ConfNode *conf)
     /* enable the logger for the app layer */
     AppLayerParserRegisterLogger(IPPROTO_TCP, ALPROTO_TLS);
 
-    return output_ctx;
+    result.ctx = output_ctx;
+    result.ok = true;
+    return result;
 parser_error:
     SCLogError(SC_ERR_INVALID_ARGUMENT,"Syntax error in custom tls log format string.");
 tlslog_error:
@@ -333,7 +336,7 @@ tlslog_error:
     SCFree(tlslog_ctx);
 filectx_error:
     LogFileFreeCtx(file_ctx);
-    return NULL;
+    return result;
 }
 
 /* Custom format logging */
index 1e6573c93f0dbfec268f820c04e20491d5dcd269..05567f8778f4b3f10b7cd28260a2a45be129b50c 100644 (file)
@@ -374,12 +374,12 @@ static void LogTlsStoreLogDeInitCtx(OutputCtx *output_ctx)
  *  \param conf Pointer to ConfNode containing this loggers configuration.
  *  \return NULL if failure, LogFilestoreCtx* to the file_ctx if succesful
  * */
-static OutputCtx *LogTlsStoreLogInitCtx(ConfNode *conf)
+static OutputInitResult LogTlsStoreLogInitCtx(ConfNode *conf)
 {
-
+    OutputInitResult result = { NULL, false };
     OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx));
     if (unlikely(output_ctx == NULL))
-        return NULL;
+        return result;
 
     output_ctx->data = NULL;
     output_ctx->DeInit = LogTlsStoreLogDeInitCtx;
@@ -408,7 +408,9 @@ static OutputCtx *LogTlsStoreLogInitCtx(ConfNode *conf)
     /* enable the logger for the app layer */
     AppLayerParserRegisterLogger(IPPROTO_TCP, ALPROTO_TLS);
 
-    SCReturnPtr(output_ctx, "OutputCtx");
+    result.ctx = output_ctx;
+    result.ok = true;
+    SCReturnCT(result, "OutputInitResult");
 }
 
 void LogTlsStoreRegister (void)
index 47c15727587c47bf96f3fab848af60d36362a9e2..f2170929c8980d8e727137f473c4efe8ba4d6b88 100644 (file)
@@ -825,31 +825,32 @@ static void XffSetup(AlertJsonOutputCtx *json_output_ctx, ConfNode *conf)
  * \param conf The configuration node for this output.
  * \return A LogFileCtx pointer on success, NULL on failure.
  */
-static OutputCtx *JsonAlertLogInitCtx(ConfNode *conf)
+static OutputInitResult JsonAlertLogInitCtx(ConfNode *conf)
 {
+    OutputInitResult result = { NULL, false };
     AlertJsonOutputCtx *json_output_ctx = NULL;
     LogFileCtx *logfile_ctx = LogFileNewCtx();
     if (logfile_ctx == NULL) {
         SCLogDebug("AlertFastLogInitCtx2: Could not create new LogFileCtx");
-        return NULL;
+        return result;
     }
 
     if (SCConfLogOpenGeneric(conf, logfile_ctx, DEFAULT_LOG_FILENAME, 1) < 0) {
         LogFileFreeCtx(logfile_ctx);
-        return NULL;
+        return result;
     }
 
     OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx));
     if (unlikely(output_ctx == NULL)) {
         LogFileFreeCtx(logfile_ctx);
-        return NULL;
+        return result;
     }
 
     json_output_ctx = SCMalloc(sizeof(AlertJsonOutputCtx));
     if (unlikely(json_output_ctx == NULL)) {
         LogFileFreeCtx(logfile_ctx);
         SCFree(output_ctx);
-        return NULL;
+        return result;
     }
     memset(json_output_ctx, 0, sizeof(AlertJsonOutputCtx));
 
@@ -860,7 +861,9 @@ static OutputCtx *JsonAlertLogInitCtx(ConfNode *conf)
     output_ctx->data = json_output_ctx;
     output_ctx->DeInit = JsonAlertLogDeInitCtx;
 
-    return output_ctx;
+    result.ctx = output_ctx;
+    result.ok = true;
+    return result;
 }
 
 /**
@@ -868,14 +871,15 @@ static OutputCtx *JsonAlertLogInitCtx(ConfNode *conf)
  * \param conf The configuration node for this output.
  * \return A LogFileCtx pointer on success, NULL on failure.
  */
-static OutputCtx *JsonAlertLogInitCtxSub(ConfNode *conf, OutputCtx *parent_ctx)
+static OutputInitResult JsonAlertLogInitCtxSub(ConfNode *conf, OutputCtx *parent_ctx)
 {
+    OutputInitResult result = { NULL, false };
     OutputJsonCtx *ajt = parent_ctx->data;
     AlertJsonOutputCtx *json_output_ctx = NULL;
 
     OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx));
     if (unlikely(output_ctx == NULL))
-        return NULL;
+        return result;
 
     json_output_ctx = SCMalloc(sizeof(AlertJsonOutputCtx));
     if (unlikely(json_output_ctx == NULL)) {
@@ -890,7 +894,9 @@ static OutputCtx *JsonAlertLogInitCtxSub(ConfNode *conf, OutputCtx *parent_ctx)
     output_ctx->data = json_output_ctx;
     output_ctx->DeInit = JsonAlertLogDeInitCtxSub;
 
-    return output_ctx;
+    result.ctx = output_ctx;
+    result.ok = true;
+    return result;
 
 error:
     if (json_output_ctx != NULL) {
@@ -900,7 +906,7 @@ error:
         SCFree(output_ctx);
     }
 
-    return NULL;
+    return result;
 }
 
 void JsonAlertLogRegister (void)
index 67025cb8e47e337ac337a9b5ac9c98b4acfbc655..91f7689042dee5f3e86b163ae7f68ed8a6c23907 100644 (file)
@@ -362,20 +362,21 @@ static void OutputDNP3LogDeInitCtxSub(OutputCtx *output_ctx)
 
 #define DEFAULT_LOG_FILENAME "dnp3.json"
 
-static OutputCtx *OutputDNP3LogInitSub(ConfNode *conf, OutputCtx *parent_ctx)
+static OutputInitResult OutputDNP3LogInitSub(ConfNode *conf, OutputCtx *parent_ctx)
 {
+    OutputInitResult result = { NULL, false };
     OutputJsonCtx *ajt = parent_ctx->data;
 
     LogDNP3FileCtx *dnp3log_ctx = SCCalloc(1, sizeof(*dnp3log_ctx));
     if (unlikely(dnp3log_ctx == NULL)) {
-        return NULL;
+        return result;
     }
     dnp3log_ctx->file_ctx = ajt->file_ctx;
 
     OutputCtx *output_ctx = SCCalloc(1, sizeof(*output_ctx));
     if (unlikely(output_ctx == NULL)) {
         SCFree(dnp3log_ctx);
-        return NULL;
+        return result;
     }
     output_ctx->data = dnp3log_ctx;
     output_ctx->DeInit = OutputDNP3LogDeInitCtxSub;
@@ -384,7 +385,9 @@ static OutputCtx *OutputDNP3LogInitSub(ConfNode *conf, OutputCtx *parent_ctx)
 
     AppLayerParserRegisterLogger(IPPROTO_TCP, ALPROTO_DNP3);
 
-    return output_ctx;
+    result.ctx = output_ctx;
+    result.ok = true;
+    return result;
 }
 
 #define OUTPUT_BUFFER_SIZE 65535
index af962914723dacb29fe5b50156c7611796c6da72..b6fea54a94b0191ac3c8008a5677b896c7673180 100644 (file)
@@ -851,13 +851,14 @@ static void JsonDnsLogInitFilters(LogDnsFileCtx *dnslog_ctx, ConfNode *conf)
     }
 }
 
-static OutputCtx *JsonDnsLogInitCtxSub(ConfNode *conf, OutputCtx *parent_ctx)
+static OutputInitResult JsonDnsLogInitCtxSub(ConfNode *conf, OutputCtx *parent_ctx)
 {
+    OutputInitResult result = { NULL, false };
     OutputJsonCtx *ojc = parent_ctx->data;
 
     LogDnsFileCtx *dnslog_ctx = SCMalloc(sizeof(LogDnsFileCtx));
     if (unlikely(dnslog_ctx == NULL)) {
-        return NULL;
+        return result;
     }
     memset(dnslog_ctx, 0x00, sizeof(LogDnsFileCtx));
 
@@ -866,7 +867,7 @@ static OutputCtx *JsonDnsLogInitCtxSub(ConfNode *conf, OutputCtx *parent_ctx)
     OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx));
     if (unlikely(output_ctx == NULL)) {
         SCFree(dnslog_ctx);
-        return NULL;
+        return result;
     }
 
     output_ctx->data = dnslog_ctx;
@@ -879,7 +880,9 @@ static OutputCtx *JsonDnsLogInitCtxSub(ConfNode *conf, OutputCtx *parent_ctx)
     AppLayerParserRegisterLogger(IPPROTO_UDP, ALPROTO_DNS);
     AppLayerParserRegisterLogger(IPPROTO_TCP, ALPROTO_DNS);
 
-    return output_ctx;
+    result.ctx = output_ctx;
+    result.ok = true;
+    return result;
 }
 
 #define DEFAULT_LOG_FILENAME "dns.json"
@@ -887,24 +890,25 @@ static OutputCtx *JsonDnsLogInitCtxSub(ConfNode *conf, OutputCtx *parent_ctx)
  *  \param conf Pointer to ConfNode containing this loggers configuration.
  *  \return NULL if failure, LogFileCtx* to the file_ctx if succesful
  * */
-static OutputCtx *JsonDnsLogInitCtx(ConfNode *conf)
+static OutputInitResult JsonDnsLogInitCtx(ConfNode *conf)
 {
+    OutputInitResult result = { NULL, false };
     LogFileCtx *file_ctx = LogFileNewCtx();
 
     if(file_ctx == NULL) {
         SCLogError(SC_ERR_DNS_LOG_GENERIC, "couldn't create new file_ctx");
-        return NULL;
+        return result;
     }
 
     if (SCConfLogOpenGeneric(conf, file_ctx, DEFAULT_LOG_FILENAME, 1) < 0) {
         LogFileFreeCtx(file_ctx);
-        return NULL;
+        return result;
     }
 
     LogDnsFileCtx *dnslog_ctx = SCMalloc(sizeof(LogDnsFileCtx));
     if (unlikely(dnslog_ctx == NULL)) {
         LogFileFreeCtx(file_ctx);
-        return NULL;
+        return result;
     }
     memset(dnslog_ctx, 0x00, sizeof(LogDnsFileCtx));
 
@@ -914,7 +918,7 @@ static OutputCtx *JsonDnsLogInitCtx(ConfNode *conf)
     if (unlikely(output_ctx == NULL)) {
         LogFileFreeCtx(file_ctx);
         SCFree(dnslog_ctx);
-        return NULL;
+        return result;
     }
 
     output_ctx->data = dnslog_ctx;
@@ -927,7 +931,9 @@ static OutputCtx *JsonDnsLogInitCtx(ConfNode *conf)
     AppLayerParserRegisterLogger(IPPROTO_UDP, ALPROTO_DNS);
     AppLayerParserRegisterLogger(IPPROTO_TCP, ALPROTO_DNS);
 
-    return output_ctx;
+    result.ctx = output_ctx;
+    result.ok = true;
+    return result;
 }
 
 
index 38065f700e4c02f0653d52b5701b8396ad46333a..2947a30684ff4c5995c79dd5b682fe3e3e087c0c 100644 (file)
@@ -250,33 +250,34 @@ static void JsonDropLogDeInitCtxSub(OutputCtx *output_ctx)
 }
 
 #define DEFAULT_LOG_FILENAME "drop.json"
-static OutputCtx *JsonDropLogInitCtx(ConfNode *conf)
+static OutputInitResult JsonDropLogInitCtx(ConfNode *conf)
 {
+    OutputInitResult result = { NULL, false };
     if (OutputDropLoggerEnable() != 0) {
         SCLogError(SC_ERR_CONF_YAML_ERROR, "only one 'drop' logger "
             "can be enabled");
-        return NULL;
+        return result;
     }
 
     JsonDropOutputCtx *drop_ctx = SCCalloc(1, sizeof(*drop_ctx));
     if (drop_ctx == NULL)
-        return NULL;
+        return result;
 
     drop_ctx->file_ctx = LogFileNewCtx();
     if (drop_ctx->file_ctx == NULL) {
         JsonDropOutputCtxFree(drop_ctx);
-        return NULL;
+        return result;
     }
 
     if (SCConfLogOpenGeneric(conf, drop_ctx->file_ctx, DEFAULT_LOG_FILENAME, 1) < 0) {
         JsonDropOutputCtxFree(drop_ctx);
-        return NULL;
+        return result;
     }
 
     OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx));
     if (unlikely(output_ctx == NULL)) {
         JsonDropOutputCtxFree(drop_ctx);
-        return NULL;
+        return result;
     }
 
     if (conf) {
@@ -301,27 +302,31 @@ static OutputCtx *JsonDropLogInitCtx(ConfNode *conf)
 
     output_ctx->data = drop_ctx;
     output_ctx->DeInit = JsonDropLogDeInitCtx;
-    return output_ctx;
+
+    result.ctx = output_ctx;
+    result.ok = true;
+    return result;
 }
 
-static OutputCtx *JsonDropLogInitCtxSub(ConfNode *conf, OutputCtx *parent_ctx)
+static OutputInitResult JsonDropLogInitCtxSub(ConfNode *conf, OutputCtx *parent_ctx)
 {
+    OutputInitResult result = { NULL, false };
     if (OutputDropLoggerEnable() != 0) {
         SCLogError(SC_ERR_CONF_YAML_ERROR, "only one 'drop' logger "
             "can be enabled");
-        return NULL;
+        return result;
     }
 
     OutputJsonCtx *ajt = parent_ctx->data;
 
     JsonDropOutputCtx *drop_ctx = SCCalloc(1, sizeof(*drop_ctx));
     if (drop_ctx == NULL)
-        return NULL;
+        return result;
 
     OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx));
     if (unlikely(output_ctx == NULL)) {
         JsonDropOutputCtxFree(drop_ctx);
-        return NULL;
+        return result;
     }
 
     if (conf) {
@@ -348,7 +353,10 @@ static OutputCtx *JsonDropLogInitCtxSub(ConfNode *conf, OutputCtx *parent_ctx)
 
     output_ctx->data = drop_ctx;
     output_ctx->DeInit = JsonDropLogDeInitCtxSub;
-    return output_ctx;
+
+    result.ctx = output_ctx;
+    result.ok = true;
+    return result;
 }
 
 /**
index 0b7fbaa98392defa5a11a5e44ed156c2d7a19d98..fcfec5047e1803cdefd5a724a857c4bdc1546fd7 100644 (file)
@@ -274,18 +274,19 @@ static void OutputFileLogDeinitSub(OutputCtx *output_ctx)
  *  \param conf Pointer to ConfNode containing this loggers configuration.
  *  \return NULL if failure, LogFileCtx* to the file_ctx if succesful
  * */
-static OutputCtx *OutputFileLogInitSub(ConfNode *conf, OutputCtx *parent_ctx)
+static OutputInitResult OutputFileLogInitSub(ConfNode *conf, OutputCtx *parent_ctx)
 {
+    OutputInitResult result = { NULL, false };
     OutputJsonCtx *ojc = parent_ctx->data;
 
     OutputFileCtx *output_file_ctx = SCMalloc(sizeof(OutputFileCtx));
     if (unlikely(output_file_ctx == NULL))
-        return NULL;
+        return result;
 
     OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx));
     if (unlikely(output_ctx == NULL)) {
         SCFree(output_file_ctx);
-        return NULL;
+        return result;
     }
 
     output_file_ctx->file_ctx = ojc->file_ctx;
@@ -310,7 +311,9 @@ static OutputCtx *OutputFileLogInitSub(ConfNode *conf, OutputCtx *parent_ctx)
     output_ctx->DeInit = OutputFileLogDeinitSub;
 
     FileForceTrackingEnable();
-    return output_ctx;
+    result.ctx = output_ctx;
+    result.ok = true;
+    return result;
 }
 
 void JsonFileLogRegister (void)
index 73448149fa15dabd9228d841365a2bf3ecca84a3..dee2f6ff5af3273380b0b2e0791413dfec8db9ce 100644 (file)
@@ -377,37 +377,40 @@ static void OutputFlowLogDeinit(OutputCtx *output_ctx)
 }
 
 #define DEFAULT_LOG_FILENAME "flow.json"
-static OutputCtx *OutputFlowLogInit(ConfNode *conf)
+static OutputInitResult OutputFlowLogInit(ConfNode *conf)
 {
+    OutputInitResult result = { NULL, false };
     LogFileCtx *file_ctx = LogFileNewCtx();
     if(file_ctx == NULL) {
         SCLogError(SC_ERR_FLOW_LOG_GENERIC, "couldn't create new file_ctx");
-        return NULL;
+        return result;
     }
 
     if (SCConfLogOpenGeneric(conf, file_ctx, DEFAULT_LOG_FILENAME, 1) < 0) {
         LogFileFreeCtx(file_ctx);
-        return NULL;
+        return result;
     }
 
     LogJsonFileCtx *flow_ctx = SCMalloc(sizeof(LogJsonFileCtx));
     if (unlikely(flow_ctx == NULL)) {
         LogFileFreeCtx(file_ctx);
-        return NULL;
+        return result;
     }
 
     OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx));
     if (unlikely(output_ctx == NULL)) {
         LogFileFreeCtx(file_ctx);
         SCFree(flow_ctx);
-        return NULL;
+        return result;
     }
 
     flow_ctx->file_ctx = file_ctx;
     output_ctx->data = flow_ctx;
     output_ctx->DeInit = OutputFlowLogDeinit;
 
-    return output_ctx;
+    result.ctx = output_ctx;
+    result.ok = true;
+    return result;
 }
 
 static void OutputFlowLogDeinitSub(OutputCtx *output_ctx)
@@ -417,18 +420,19 @@ static void OutputFlowLogDeinitSub(OutputCtx *output_ctx)
     SCFree(output_ctx);
 }
 
-static OutputCtx *OutputFlowLogInitSub(ConfNode *conf, OutputCtx *parent_ctx)
+static OutputInitResult OutputFlowLogInitSub(ConfNode *conf, OutputCtx *parent_ctx)
 {
+    OutputInitResult result = { NULL, false };
     OutputJsonCtx *ojc = parent_ctx->data;
 
     LogJsonFileCtx *flow_ctx = SCMalloc(sizeof(LogJsonFileCtx));
     if (unlikely(flow_ctx == NULL))
-        return NULL;
+        return result;
 
     OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx));
     if (unlikely(output_ctx == NULL)) {
         SCFree(flow_ctx);
-        return NULL;
+        return result;
     }
 
     flow_ctx->file_ctx = ojc->file_ctx;
@@ -436,7 +440,9 @@ static OutputCtx *OutputFlowLogInitSub(ConfNode *conf, OutputCtx *parent_ctx)
     output_ctx->data = flow_ctx;
     output_ctx->DeInit = OutputFlowLogDeinitSub;
 
-    return output_ctx;
+    result.ctx = output_ctx;
+    result.ok = true;
+    return result;
 }
 
 #define OUTPUT_BUFFER_SIZE 65535
index 02127928afa7f9ee999e6895bf0df76f35241356..bb60ce3e563746d736f5134f73bdee1cdcb94308 100644 (file)
@@ -501,30 +501,31 @@ static void OutputHttpLogDeinit(OutputCtx *output_ctx)
 }
 
 #define DEFAULT_LOG_FILENAME "http.json"
-static OutputCtx *OutputHttpLogInit(ConfNode *conf)
+static OutputInitResult OutputHttpLogInit(ConfNode *conf)
 {
+    OutputInitResult result = { NULL, false };
     LogFileCtx *file_ctx = LogFileNewCtx();
     if(file_ctx == NULL) {
         SCLogError(SC_ERR_HTTP_LOG_GENERIC, "couldn't create new file_ctx");
-        return NULL;
+        return result;
     }
 
     if (SCConfLogOpenGeneric(conf, file_ctx, DEFAULT_LOG_FILENAME, 1) < 0) {
         LogFileFreeCtx(file_ctx);
-        return NULL;
+        return result;
     }
 
     LogHttpFileCtx *http_ctx = SCMalloc(sizeof(LogHttpFileCtx));
     if (unlikely(http_ctx == NULL)) {
         LogFileFreeCtx(file_ctx);
-        return NULL;
+        return result;
     }
 
     OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx));
     if (unlikely(output_ctx == NULL)) {
         LogFileFreeCtx(file_ctx);
         SCFree(http_ctx);
-        return NULL;
+        return result;
     }
 
     http_ctx->file_ctx = file_ctx;
@@ -545,7 +546,9 @@ static OutputCtx *OutputHttpLogInit(ConfNode *conf)
     /* enable the logger for the app layer */
     AppLayerParserRegisterLogger(IPPROTO_TCP, ALPROTO_HTTP);
 
-    return output_ctx;
+    result.ctx = output_ctx;
+    result.ok = true;
+    return result;
 }
 
 static void OutputHttpLogDeinitSub(OutputCtx *output_ctx)
@@ -555,19 +558,20 @@ static void OutputHttpLogDeinitSub(OutputCtx *output_ctx)
     SCFree(output_ctx);
 }
 
-static OutputCtx *OutputHttpLogInitSub(ConfNode *conf, OutputCtx *parent_ctx)
+static OutputInitResult OutputHttpLogInitSub(ConfNode *conf, OutputCtx *parent_ctx)
 {
+    OutputInitResult result = { NULL, false };
     OutputJsonCtx *ojc = parent_ctx->data;
 
     LogHttpFileCtx *http_ctx = SCMalloc(sizeof(LogHttpFileCtx));
     if (unlikely(http_ctx == NULL))
-        return NULL;
+        return result;
     memset(http_ctx, 0x00, sizeof(*http_ctx));
 
     OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx));
     if (unlikely(output_ctx == NULL)) {
         SCFree(http_ctx);
-        return NULL;
+        return result;
     }
 
     http_ctx->file_ctx = ojc->file_ctx;
@@ -611,7 +615,9 @@ static OutputCtx *OutputHttpLogInitSub(ConfNode *conf, OutputCtx *parent_ctx)
     /* enable the logger for the app layer */
     AppLayerParserRegisterLogger(IPPROTO_TCP, ALPROTO_HTTP);
 
-    return output_ctx;
+    result.ctx = output_ctx;
+    result.ok = true;
+    return result;
 }
 
 #define OUTPUT_BUFFER_SIZE 65535
index 092776ac2ceb5ae805e5ffc97f570024b41faa2c..7a912dbafae5c479bcb7cd8e5405b17e509fd37b 100644 (file)
@@ -334,37 +334,40 @@ static void OutputNetFlowLogDeinit(OutputCtx *output_ctx)
 }
 
 #define DEFAULT_LOG_FILENAME "netflow.json"
-static OutputCtx *OutputNetFlowLogInit(ConfNode *conf)
+static OutputInitResult OutputNetFlowLogInit(ConfNode *conf)
 {
+    OutputInitResult result = { NULL, false };
     LogFileCtx *file_ctx = LogFileNewCtx();
     if(file_ctx == NULL) {
         SCLogError(SC_ERR_NETFLOW_LOG_GENERIC, "couldn't create new file_ctx");
-        return NULL;
+        return result;
     }
 
     if (SCConfLogOpenGeneric(conf, file_ctx, DEFAULT_LOG_FILENAME, 1) < 0) {
         LogFileFreeCtx(file_ctx);
-        return NULL;
+        return result;
     }
 
     LogJsonFileCtx *flow_ctx = SCMalloc(sizeof(LogJsonFileCtx));
     if (unlikely(flow_ctx == NULL)) {
         LogFileFreeCtx(file_ctx);
-        return NULL;
+        return result;
     }
 
     OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx));
     if (unlikely(output_ctx == NULL)) {
         LogFileFreeCtx(file_ctx);
         SCFree(flow_ctx);
-        return NULL;
+        return result;
     }
 
     flow_ctx->file_ctx = file_ctx;
     output_ctx->data = flow_ctx;
     output_ctx->DeInit = OutputNetFlowLogDeinit;
 
-    return output_ctx;
+    result.ctx = output_ctx;
+    result.ok = true;
+    return result;
 }
 
 static void OutputNetFlowLogDeinitSub(OutputCtx *output_ctx)
@@ -374,18 +377,19 @@ static void OutputNetFlowLogDeinitSub(OutputCtx *output_ctx)
     SCFree(output_ctx);
 }
 
-static OutputCtx *OutputNetFlowLogInitSub(ConfNode *conf, OutputCtx *parent_ctx)
+static OutputInitResult OutputNetFlowLogInitSub(ConfNode *conf, OutputCtx *parent_ctx)
 {
+    OutputInitResult result = { NULL, false };
     OutputJsonCtx *ojc = parent_ctx->data;
 
     LogJsonFileCtx *flow_ctx = SCMalloc(sizeof(LogJsonFileCtx));
     if (unlikely(flow_ctx == NULL))
-        return NULL;
+        return result;
 
     OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx));
     if (unlikely(output_ctx == NULL)) {
         SCFree(flow_ctx);
-        return NULL;
+        return result;
     }
 
     flow_ctx->file_ctx = ojc->file_ctx;
@@ -393,7 +397,9 @@ static OutputCtx *OutputNetFlowLogInitSub(ConfNode *conf, OutputCtx *parent_ctx)
     output_ctx->data = flow_ctx;
     output_ctx->DeInit = OutputNetFlowLogDeinitSub;
 
-    return output_ctx;
+    result.ctx = output_ctx;
+    result.ok = true;
+    return result;
 }
 
 #define OUTPUT_BUFFER_SIZE 65535
index 1087fe76c92af2bfd049e77ee2437d5ce1cc3429..fe0b8d491c77dfacfe6071af51057eb7eaa2b5dd 100644 (file)
@@ -133,21 +133,22 @@ static void OutputNFSLogDeInitCtxSub(OutputCtx *output_ctx)
     SCFree(output_ctx);
 }
 
-static OutputCtx *OutputNFSLogInitSub(ConfNode *conf,
+static OutputInitResult OutputNFSLogInitSub(ConfNode *conf,
     OutputCtx *parent_ctx)
 {
+    OutputInitResult result = { NULL, false };
     OutputJsonCtx *ajt = parent_ctx->data;
 
     LogNFSFileCtx *nfslog_ctx = SCCalloc(1, sizeof(*nfslog_ctx));
     if (unlikely(nfslog_ctx == NULL)) {
-        return NULL;
+        return result;
     }
     nfslog_ctx->file_ctx = ajt->file_ctx;
 
     OutputCtx *output_ctx = SCCalloc(1, sizeof(*output_ctx));
     if (unlikely(output_ctx == NULL)) {
         SCFree(nfslog_ctx);
-        return NULL;
+        return result;
     }
     output_ctx->data = nfslog_ctx;
     output_ctx->DeInit = OutputNFSLogDeInitCtxSub;
@@ -157,7 +158,9 @@ static OutputCtx *OutputNFSLogInitSub(ConfNode *conf,
     AppLayerParserRegisterLogger(IPPROTO_TCP, ALPROTO_NFS);
     AppLayerParserRegisterLogger(IPPROTO_UDP, ALPROTO_NFS);
 
-    return output_ctx;
+    result.ctx = output_ctx;
+    result.ok = true;
+    return result;
 }
 
 #define OUTPUT_BUFFER_SIZE 65535
index e736014b205dc6d03543fce3a93ea65ff3d2355e..b14f203c4f4d46c2188f9dbf668afff413a3d902 100644 (file)
@@ -151,30 +151,31 @@ static void OutputSmtpLogDeInitCtxSub(OutputCtx *output_ctx)
 }
 
 #define DEFAULT_LOG_FILENAME "smtp.json"
-static OutputCtx *OutputSmtpLogInit(ConfNode *conf)
+static OutputInitResult OutputSmtpLogInit(ConfNode *conf)
 {
+    OutputInitResult result = { NULL, false };
     LogFileCtx *file_ctx = LogFileNewCtx();
     if(file_ctx == NULL) {
         SCLogError(SC_ERR_SMTP_LOG_GENERIC, "couldn't create new file_ctx");
-        return NULL;
+        return result;
     }
 
     if (SCConfLogOpenGeneric(conf, file_ctx, DEFAULT_LOG_FILENAME, 1) < 0) {
         LogFileFreeCtx(file_ctx);
-        return NULL;
+        return result;
     }
 
     OutputJsonEmailCtx *email_ctx = SCMalloc(sizeof(OutputJsonEmailCtx));
     if (unlikely(email_ctx == NULL)) {
         LogFileFreeCtx(file_ctx);
-        return NULL;
+        return result;
     }
 
     OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx));
     if (unlikely(output_ctx == NULL)) {
         LogFileFreeCtx(file_ctx);
         SCFree(email_ctx);
-        return NULL;
+        return result;
     }
 
     email_ctx->file_ctx = file_ctx;
@@ -185,21 +186,24 @@ static OutputCtx *OutputSmtpLogInit(ConfNode *conf)
     /* enable the logger for the app layer */
     AppLayerParserRegisterLogger(IPPROTO_TCP, ALPROTO_SMTP);
 
-    return output_ctx;
+    result.ctx = output_ctx;
+    result.ok = true;
+    return result;
 }
 
-static OutputCtx *OutputSmtpLogInitSub(ConfNode *conf, OutputCtx *parent_ctx)
+static OutputInitResult OutputSmtpLogInitSub(ConfNode *conf, OutputCtx *parent_ctx)
 {
+    OutputInitResult result = { NULL, false };
     OutputJsonCtx *ojc = parent_ctx->data;
 
     OutputJsonEmailCtx *email_ctx = SCMalloc(sizeof(OutputJsonEmailCtx));
     if (unlikely(email_ctx == NULL))
-        return NULL;
+        return result;
 
     OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx));
     if (unlikely(output_ctx == NULL)) {
         SCFree(email_ctx);
-        return NULL;
+        return result;
     }
 
     email_ctx->file_ctx = ojc->file_ctx;
@@ -212,7 +216,9 @@ static OutputCtx *OutputSmtpLogInitSub(ConfNode *conf, OutputCtx *parent_ctx)
     /* enable the logger for the app layer */
     AppLayerParserRegisterLogger(IPPROTO_TCP, ALPROTO_SMTP);
 
-    return output_ctx;
+    result.ctx = output_ctx;
+    result.ok = true;
+    return result;
 }
 
 #define OUTPUT_BUFFER_SIZE 65535
index 17c0e72b3a9593f6dfe7d564adda29ed0bade27e..ffb781e06ac963a457318c47143c58a7e82db444 100644 (file)
@@ -182,30 +182,31 @@ static void OutputSshLogDeinit(OutputCtx *output_ctx)
 }
 
 #define DEFAULT_LOG_FILENAME "ssh.json"
-static OutputCtx *OutputSshLogInit(ConfNode *conf)
+static OutputInitResult OutputSshLogInit(ConfNode *conf)
 {
+    OutputInitResult result = { NULL, false };
     LogFileCtx *file_ctx = LogFileNewCtx();
     if(file_ctx == NULL) {
         SCLogError(SC_ERR_SSH_LOG_GENERIC, "couldn't create new file_ctx");
-        return NULL;
+        return result;
     }
 
     if (SCConfLogOpenGeneric(conf, file_ctx, DEFAULT_LOG_FILENAME, 1) < 0) {
         LogFileFreeCtx(file_ctx);
-        return NULL;
+        return result;
     }
 
     OutputSshCtx *ssh_ctx = SCMalloc(sizeof(OutputSshCtx));
     if (unlikely(ssh_ctx == NULL)) {
         LogFileFreeCtx(file_ctx);
-        return NULL;
+        return result;
     }
 
     OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx));
     if (unlikely(output_ctx == NULL)) {
         LogFileFreeCtx(file_ctx);
         SCFree(ssh_ctx);
-        return NULL;
+        return result;
     }
 
     ssh_ctx->file_ctx = file_ctx;
@@ -214,7 +215,10 @@ static OutputCtx *OutputSshLogInit(ConfNode *conf)
     output_ctx->DeInit = OutputSshLogDeinit;
 
     AppLayerParserRegisterLogger(IPPROTO_TCP, ALPROTO_SSH);
-    return output_ctx;
+
+    result.ctx = output_ctx;
+    result.ok = true;
+    return result;
 }
 
 static void OutputSshLogDeinitSub(OutputCtx *output_ctx)
@@ -224,18 +228,19 @@ static void OutputSshLogDeinitSub(OutputCtx *output_ctx)
     SCFree(output_ctx);
 }
 
-static OutputCtx *OutputSshLogInitSub(ConfNode *conf, OutputCtx *parent_ctx)
+static OutputInitResult OutputSshLogInitSub(ConfNode *conf, OutputCtx *parent_ctx)
 {
+    OutputInitResult result = { NULL, false };
     OutputJsonCtx *ojc = parent_ctx->data;
 
     OutputSshCtx *ssh_ctx = SCMalloc(sizeof(OutputSshCtx));
     if (unlikely(ssh_ctx == NULL))
-        return NULL;
+        return result;
 
     OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx));
     if (unlikely(output_ctx == NULL)) {
         SCFree(ssh_ctx);
-        return NULL;
+        return result;
     }
 
     ssh_ctx->file_ctx = ojc->file_ctx;
@@ -244,7 +249,10 @@ static OutputCtx *OutputSshLogInitSub(ConfNode *conf, OutputCtx *parent_ctx)
     output_ctx->DeInit = OutputSshLogDeinitSub;
 
     AppLayerParserRegisterLogger(IPPROTO_TCP, ALPROTO_SSH);
-    return output_ctx;
+
+    result.ctx = output_ctx;
+    result.ok = true;
+    return result;
 }
 
 void JsonSshLogRegister (void)
index b42030cf0a69da8bc2534541ee93d8ceb1809bbc..004d6531a222765ff84263091aab27c681b41ab0 100644 (file)
@@ -378,23 +378,24 @@ static void OutputStatsLogDeinit(OutputCtx *output_ctx)
 }
 
 #define DEFAULT_LOG_FILENAME "stats.json"
-static OutputCtx *OutputStatsLogInit(ConfNode *conf)
+static OutputInitResult OutputStatsLogInit(ConfNode *conf)
 {
+    OutputInitResult result = { NULL, false };
     LogFileCtx *file_ctx = LogFileNewCtx();
     if(file_ctx == NULL) {
         SCLogError(SC_ERR_STATS_LOG_GENERIC, "couldn't create new file_ctx");
-        return NULL;
+        return result;
     }
 
     if (SCConfLogOpenGeneric(conf, file_ctx, DEFAULT_LOG_FILENAME, 1) < 0) {
         LogFileFreeCtx(file_ctx);
-        return NULL;
+        return result;
     }
 
     OutputStatsCtx *stats_ctx = SCMalloc(sizeof(OutputStatsCtx));
     if (unlikely(stats_ctx == NULL)) {
         LogFileFreeCtx(file_ctx);
-        return NULL;
+        return result;
     }
     stats_ctx->flags = JSON_STATS_TOTALS;
 
@@ -420,7 +421,7 @@ static OutputCtx *OutputStatsLogInit(ConfNode *conf)
     if (unlikely(output_ctx == NULL)) {
         LogFileFreeCtx(file_ctx);
         SCFree(stats_ctx);
-        return NULL;
+        return result;
     }
 
     stats_ctx->file_ctx = file_ctx;
@@ -428,7 +429,9 @@ static OutputCtx *OutputStatsLogInit(ConfNode *conf)
     output_ctx->data = stats_ctx;
     output_ctx->DeInit = OutputStatsLogDeinit;
 
-    return output_ctx;
+    result.ctx = output_ctx;
+    result.ok = true;
+    return result;
 }
 
 static void OutputStatsLogDeinitSub(OutputCtx *output_ctx)
@@ -438,13 +441,13 @@ static void OutputStatsLogDeinitSub(OutputCtx *output_ctx)
     SCFree(output_ctx);
 }
 
-static OutputCtx *OutputStatsLogInitSub(ConfNode *conf, OutputCtx *parent_ctx)
+static OutputInitResult OutputStatsLogInitSub(ConfNode *conf, OutputCtx *parent_ctx)
 {
+    OutputInitResult result = { NULL, false };
     OutputJsonCtx *ajt = parent_ctx->data;
-
     OutputStatsCtx *stats_ctx = SCMalloc(sizeof(OutputStatsCtx));
     if (unlikely(stats_ctx == NULL))
-        return NULL;
+        return result;
 
     stats_ctx->flags = JSON_STATS_TOTALS;
 
@@ -459,7 +462,7 @@ static OutputCtx *OutputStatsLogInitSub(ConfNode *conf, OutputCtx *parent_ctx)
             SCFree(stats_ctx);
             SCLogError(SC_ERR_JSON_STATS_LOG_NEGATED,
                     "Cannot disable both totals and threads in stats logging");
-            return NULL;
+            return result;
         }
 
         if (totals != NULL && ConfValIsFalse(totals)) {
@@ -477,7 +480,7 @@ static OutputCtx *OutputStatsLogInitSub(ConfNode *conf, OutputCtx *parent_ctx)
     OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx));
     if (unlikely(output_ctx == NULL)) {
         SCFree(stats_ctx);
-        return NULL;
+        return result;
     }
 
     stats_ctx->file_ctx = ajt->file_ctx;
@@ -485,7 +488,9 @@ static OutputCtx *OutputStatsLogInitSub(ConfNode *conf, OutputCtx *parent_ctx)
     output_ctx->data = stats_ctx;
     output_ctx->DeInit = OutputStatsLogDeinitSub;
 
-    return output_ctx;
+    result.ctx = output_ctx;
+    result.ok = true;
+    return result;
 }
 
 void JsonStatsLogRegister(void) {
index 17fd6dfd3d357c18608e5a7b5af90f5c23f9ef10..7a390527583362d45ad517cfe5350a977a004f9c 100644 (file)
@@ -122,21 +122,22 @@ static void OutputTemplateLogDeInitCtxSub(OutputCtx *output_ctx)
     SCFree(output_ctx);
 }
 
-static OutputCtx *OutputTemplateLogInitSub(ConfNode *conf,
+static OutputInitResult OutputTemplateLogInitSub(ConfNode *conf,
     OutputCtx *parent_ctx)
 {
+    OutputInitResult result = { NULL, false };
     OutputJsonCtx *ajt = parent_ctx->data;
 
     LogTemplateFileCtx *templatelog_ctx = SCCalloc(1, sizeof(*templatelog_ctx));
     if (unlikely(templatelog_ctx == NULL)) {
-        return NULL;
+        return result;
     }
     templatelog_ctx->file_ctx = ajt->file_ctx;
 
     OutputCtx *output_ctx = SCCalloc(1, sizeof(*output_ctx));
     if (unlikely(output_ctx == NULL)) {
         SCFree(templatelog_ctx);
-        return NULL;
+        return result;
     }
     output_ctx->data = templatelog_ctx;
     output_ctx->DeInit = OutputTemplateLogDeInitCtxSub;
@@ -145,7 +146,9 @@ static OutputCtx *OutputTemplateLogInitSub(ConfNode *conf,
 
     AppLayerParserRegisterLogger(IPPROTO_TCP, ALPROTO_TEMPLATE);
 
-    return output_ctx;
+    result.ctx = output_ctx;
+    result.ok = true;
+    return result;
 }
 
 #define OUTPUT_BUFFER_SIZE 65535
index 3bdd481621de3ba05c1ed5804fd505d8d81247b8..18d45dce2463cab5a949c46445660daf20dd4332 100644 (file)
@@ -503,30 +503,31 @@ static OutputTlsCtx *OutputTlsInitCtx(ConfNode *conf)
     return tls_ctx;
 }
 
-static OutputCtx *OutputTlsLogInit(ConfNode *conf)
+static OutputInitResult OutputTlsLogInit(ConfNode *conf)
 {
+    OutputInitResult result = { NULL, false };
     LogFileCtx *file_ctx = LogFileNewCtx();
     if (file_ctx == NULL) {
         SCLogError(SC_ERR_TLS_LOG_GENERIC, "couldn't create new file_ctx");
-        return NULL;
+        return result;
     }
 
     if (SCConfLogOpenGeneric(conf, file_ctx, DEFAULT_LOG_FILENAME, 1) < 0) {
         LogFileFreeCtx(file_ctx);
-        return NULL;
+        return result;
     }
 
     OutputTlsCtx *tls_ctx = OutputTlsInitCtx(conf);
     if (unlikely(tls_ctx == NULL)) {
         LogFileFreeCtx(file_ctx);
-        return NULL;
+        return result;
     }
 
     OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx));
     if (unlikely(output_ctx == NULL)) {
         LogFileFreeCtx(file_ctx);
         SCFree(tls_ctx);
-        return NULL;
+        return result;
     }
 
     tls_ctx->file_ctx = file_ctx;
@@ -536,7 +537,9 @@ static OutputCtx *OutputTlsLogInit(ConfNode *conf)
 
     AppLayerParserRegisterLogger(IPPROTO_TCP, ALPROTO_TLS);
 
-    return output_ctx;
+    result.ctx = output_ctx;
+    result.ok = true;
+    return result;
 }
 
 static void OutputTlsLogDeinitSub(OutputCtx *output_ctx)
@@ -546,18 +549,19 @@ static void OutputTlsLogDeinitSub(OutputCtx *output_ctx)
     SCFree(output_ctx);
 }
 
-static OutputCtx *OutputTlsLogInitSub(ConfNode *conf, OutputCtx *parent_ctx)
+static OutputInitResult OutputTlsLogInitSub(ConfNode *conf, OutputCtx *parent_ctx)
 {
+    OutputInitResult result = { NULL, false };
     OutputJsonCtx *ojc = parent_ctx->data;
 
     OutputTlsCtx *tls_ctx = OutputTlsInitCtx(conf);
     if (unlikely(tls_ctx == NULL))
-        return NULL;
+        return result;
 
     OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx));
     if (unlikely(output_ctx == NULL)) {
         SCFree(tls_ctx);
-        return NULL;
+        return result;
     }
 
     tls_ctx->file_ctx = ojc->file_ctx;
@@ -575,7 +579,9 @@ static OutputCtx *OutputTlsLogInitSub(ConfNode *conf, OutputCtx *parent_ctx)
 
     AppLayerParserRegisterLogger(IPPROTO_TCP, ALPROTO_TLS);
 
-    return output_ctx;
+    result.ctx = output_ctx;
+    result.ok = true;
+    return result;
 }
 
 void JsonTlsLogRegister (void)
index 14961d23e4acb92bb5d9190370a764ccfbe679e5..502d12f2254ffdcdb99a170487ee58da6c33fd6e 100644 (file)
@@ -184,31 +184,32 @@ static void JsonVarsLogDeInitCtxSub(OutputCtx *output_ctx)
  * \param conf The configuration node for this output.
  * \return A LogFileCtx pointer on success, NULL on failure.
  */
-static OutputCtx *JsonVarsLogInitCtx(ConfNode *conf)
+static OutputInitResult JsonVarsLogInitCtx(ConfNode *conf)
 {
+    OutputInitResult result = { NULL, false };
     VarsJsonOutputCtx *json_output_ctx = NULL;
     LogFileCtx *logfile_ctx = LogFileNewCtx();
     if (logfile_ctx == NULL) {
         SCLogDebug("VarsFastLogInitCtx2: Could not create new LogFileCtx");
-        return NULL;
+        return result;
     }
 
     if (SCConfLogOpenGeneric(conf, logfile_ctx, DEFAULT_LOG_FILENAME, 1) < 0) {
         LogFileFreeCtx(logfile_ctx);
-        return NULL;
+        return result;
     }
 
     OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx));
     if (unlikely(output_ctx == NULL)) {
         LogFileFreeCtx(logfile_ctx);
-        return NULL;
+        return result;
     }
 
     json_output_ctx = SCMalloc(sizeof(VarsJsonOutputCtx));
     if (unlikely(json_output_ctx == NULL)) {
         LogFileFreeCtx(logfile_ctx);
         SCFree(output_ctx);
-        return NULL;
+        return result;
     }
     memset(json_output_ctx, 0, sizeof(VarsJsonOutputCtx));
 
@@ -217,7 +218,9 @@ static OutputCtx *JsonVarsLogInitCtx(ConfNode *conf)
     output_ctx->data = json_output_ctx;
     output_ctx->DeInit = JsonVarsLogDeInitCtx;
 
-    return output_ctx;
+    result.ctx = output_ctx;
+    result.ok = true;
+    return result;
 }
 
 /**
@@ -225,14 +228,15 @@ static OutputCtx *JsonVarsLogInitCtx(ConfNode *conf)
  * \param conf The configuration node for this output.
  * \return A LogFileCtx pointer on success, NULL on failure.
  */
-static OutputCtx *JsonVarsLogInitCtxSub(ConfNode *conf, OutputCtx *parent_ctx)
+static OutputInitResult JsonVarsLogInitCtxSub(ConfNode *conf, OutputCtx *parent_ctx)
 {
+    OutputInitResult result = { NULL, false };
     OutputJsonCtx *ajt = parent_ctx->data;
     VarsJsonOutputCtx *json_output_ctx = NULL;
 
     OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx));
     if (unlikely(output_ctx == NULL))
-        return NULL;
+        return result;
 
     json_output_ctx = SCMalloc(sizeof(VarsJsonOutputCtx));
     if (unlikely(json_output_ctx == NULL)) {
@@ -245,7 +249,9 @@ static OutputCtx *JsonVarsLogInitCtxSub(ConfNode *conf, OutputCtx *parent_ctx)
     output_ctx->data = json_output_ctx;
     output_ctx->DeInit = JsonVarsLogDeInitCtxSub;
 
-    return output_ctx;
+    result.ctx = output_ctx;
+    result.ok = true;
+    return result;
 
 error:
     if (json_output_ctx != NULL) {
@@ -255,7 +261,7 @@ error:
         SCFree(output_ctx);
     }
 
-    return NULL;
+    return result;
 }
 
 void JsonVarsLogRegister (void)
index 05942a581e18535713c4f630919755fa4f255e14..4d2fe5e572316f46f20c00f7947497c27dc8ee85 100644 (file)
@@ -532,8 +532,9 @@ int OutputJSONBuffer(json_t *js, LogFileCtx *file_ctx, MemBuffer **buffer)
  * \param conf The configuration node for this output.
  * \return A LogFileCtx pointer on success, NULL on failure.
  */
-OutputCtx *OutputJsonInitCtx(ConfNode *conf)
+OutputInitResult OutputJsonInitCtx(ConfNode *conf)
 {
+    OutputInitResult result = { NULL, false };
     OutputJsonCtx *json_ctx = SCCalloc(1, sizeof(OutputJsonCtx));;
 
     /* First lookup a sensor-name value in this outputs configuration
@@ -550,14 +551,14 @@ OutputCtx *OutputJsonInitCtx(ConfNode *conf)
 
     if (unlikely(json_ctx == NULL)) {
         SCLogDebug("AlertJsonInitCtx: Could not create new LogFileCtx");
-        return NULL;
+        return result;
     }
 
     json_ctx->file_ctx = LogFileNewCtx();
     if (unlikely(json_ctx->file_ctx == NULL)) {
         SCLogDebug("AlertJsonInitCtx: Could not create new LogFileCtx");
         SCFree(json_ctx);
-        return NULL;
+        return result;
     }
 
     if (sensor_name) {
@@ -565,7 +566,7 @@ OutputCtx *OutputJsonInitCtx(ConfNode *conf)
         if (json_ctx->file_ctx->sensor_name  == NULL) {
             LogFileFreeCtx(json_ctx->file_ctx);
             SCFree(json_ctx);
-            return NULL;
+            return result;
         }
     } else {
         json_ctx->file_ctx->sensor_name = NULL;
@@ -575,7 +576,7 @@ OutputCtx *OutputJsonInitCtx(ConfNode *conf)
     if (unlikely(output_ctx == NULL)) {
         LogFileFreeCtx(json_ctx->file_ctx);
         SCFree(json_ctx);
-        return NULL;
+        return result;
     }
 
     output_ctx->data = json_ctx;
@@ -637,7 +638,7 @@ OutputCtx *OutputJsonInitCtx(ConfNode *conf)
                 LogFileFreeCtx(json_ctx->file_ctx);
                 SCFree(json_ctx);
                 SCFree(output_ctx);
-                return NULL;
+                return result;
             }
             OutputRegisterFileRotationFlag(&json_ctx->file_ctx->rotation_flag);
         } else if (json_ctx->json_out == LOGFILE_TYPE_SYSLOG) {
@@ -681,14 +682,14 @@ OutputCtx *OutputJsonInitCtx(ConfNode *conf)
                 LogFileFreeCtx(json_ctx->file_ctx);
                 SCFree(json_ctx);
                 SCFree(output_ctx);
-                return NULL;
+                return result;
             }
 
             if (SCConfLogOpenRedis(redis_node, json_ctx->file_ctx) < 0) {
                 LogFileFreeCtx(json_ctx->file_ctx);
                 SCFree(json_ctx);
                 SCFree(output_ctx);
-                return NULL;
+                return result;
             }
         }
 #endif
@@ -707,7 +708,10 @@ OutputCtx *OutputJsonInitCtx(ConfNode *conf)
     }
 
     SCLogDebug("returning output_ctx %p", output_ctx);
-    return output_ctx;
+
+    result.ctx = output_ctx;
+    result.ok = true;
+    return result;
 }
 
 static void OutputJsonDeInitCtx(OutputCtx *output_ctx)
index 76d4f02848dfe6ac26c13d9419382c40fe9d8054..637d4b5ebdfce768ca0e17e2f43d578d36ff8500 100644 (file)
@@ -27,6 +27,7 @@
 #include "suricata-common.h"
 #include "util-buffer.h"
 #include "util-logopenfile.h"
+#include "output.h"
 
 void OutputJsonRegister(void);
 
@@ -46,7 +47,7 @@ void JsonFiveTuple(const Packet *, int, json_t *);
 json_t *CreateJSONHeader(const Packet *p, int direction_sensative, const char *event_type);
 json_t *CreateJSONHeaderWithTxId(const Packet *p, int direction_sensitive, const char *event_type, uint64_t tx_id);
 int OutputJSONBuffer(json_t *js, LogFileCtx *file_ctx, MemBuffer **buffer);
-OutputCtx *OutputJsonInitCtx(ConfNode *);
+OutputInitResult OutputJsonInitCtx(ConfNode *);
 
 /*
  * Global configuration context data
index 6d7d7a07b76d765f4e71098bba9bf22ded0610ff..77d6ec96c07cb9f1fbff9794d219fed57c3b2cd3 100644 (file)
@@ -664,20 +664,21 @@ static void LogLuaSubFree(OutputCtx *oc) {
  *
  *  Runs script 'setup' function.
  */
-static OutputCtx *OutputLuaLogInitSub(ConfNode *conf, OutputCtx *parent_ctx)
+static OutputInitResult OutputLuaLogInitSub(ConfNode *conf, OutputCtx *parent_ctx)
 {
+    OutputInitResult result = { NULL, false };
     if (conf == NULL)
-        return NULL;
+        return result;
 
     LogLuaCtx *lua_ctx = SCMalloc(sizeof(LogLuaCtx));
     if (unlikely(lua_ctx == NULL))
-        return NULL;
+        return result;
     memset(lua_ctx, 0x00, sizeof(*lua_ctx));
 
     OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx));
     if (unlikely(output_ctx == NULL)) {
         SCFree(lua_ctx);
-        return NULL;
+        return result;
     }
 
     SCMutexInit(&lua_ctx->m, NULL);
@@ -707,12 +708,14 @@ static OutputCtx *OutputLuaLogInitSub(ConfNode *conf, OutputCtx *parent_ctx)
     output_ctx->data = lua_ctx;
     output_ctx->DeInit = LogLuaSubFree;
 
-    return output_ctx;
+    result.ctx = output_ctx;
+    result.ok = true;
+    return result;
 error:
     SCMutexDestroy(&lua_ctx->m);
     SCFree(lua_ctx);
     SCFree(output_ctx);
-    return NULL;
+    return result;
 }
 
 static void LogLuaMasterFree(OutputCtx *oc)
@@ -734,8 +737,9 @@ static void LogLuaMasterFree(OutputCtx *oc)
  *  inspect, then fills the OutputCtx::submodules list with the
  *  proper Logger function for the data type the script needs.
  */
-static OutputCtx *OutputLuaLogInit(ConfNode *conf)
+static OutputInitResult OutputLuaLogInit(ConfNode *conf)
 {
+    OutputInitResult result = { NULL, false };
     const char *dir = ConfNodeLookupChildValue(conf, "scripts-dir");
     if (dir == NULL)
         dir = "";
@@ -744,19 +748,19 @@ static OutputCtx *OutputLuaLogInit(ConfNode *conf)
     if (scripts == NULL) {
         /* No "outputs" section in the configuration. */
         SCLogInfo("scripts not defined");
-        return NULL;
+        return result;
     }
 
     /* global output ctx setup */
     OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx));
     if (unlikely(output_ctx == NULL)) {
-        return NULL;
+        return result;
     }
     output_ctx->DeInit = LogLuaMasterFree;
     output_ctx->data = SCCalloc(1, sizeof(LogLuaMasterCtx));
     if (unlikely(output_ctx->data == NULL)) {
         SCFree(output_ctx);
-        return NULL;
+        return result;
     }
     LogLuaMasterCtx *master_config = output_ctx->data;
     strlcpy(master_config->path, dir, sizeof(master_config->path));
@@ -853,12 +857,14 @@ static OutputCtx *OutputLuaLogInit(ConfNode *conf)
         TAILQ_INSERT_TAIL(&output_ctx->submodules, om, entries);
     }
 
-    return output_ctx;
+    result.ctx = output_ctx;
+    result.ok = true;
+    return result;
 
 error:
     if (output_ctx->DeInit)
         output_ctx->DeInit(output_ctx);
-    return NULL;
+    return result;
 }
 
 /** \internal
index 4c5a770fe7cf7d3550f7c7fa0c3967eac68ba49e..d6873d076f4772840a61480b5c093187bd676b01 100644 (file)
 #include "output-streaming.h"
 #include "output-stats.h"
 
-typedef OutputCtx *(*OutputInitFunc)(ConfNode *);
-typedef OutputCtx *(*OutputInitSubFunc)(ConfNode *, OutputCtx *);
+typedef struct OutputInitResult_ {
+    OutputCtx *ctx;
+    bool ok;
+} OutputInitResult;
+
+typedef OutputInitResult (*OutputInitFunc)(ConfNode *);
+typedef OutputInitResult (*OutputInitSubFunc)(ConfNode *, OutputCtx *);
 typedef TmEcode (*OutputLogFunc)(ThreadVars *, Packet *, void *);
 
 typedef struct OutputModule_ {
index eeeaf49d0f6387f1a36945f0eccaea2496e490c7..1498501e70f993d65ed19a3606ce2dd2e92529fd 100644 (file)
@@ -37,8 +37,8 @@
 #include "conf.h"
 #include "runmodes.h"
 #include "runmode-af-packet.h"
-#include "log-httplog.h"
 #include "output.h"
+#include "log-httplog.h"
 #include "detect-engine-mpm.h"
 
 #include "alert-fastlog.h"
index e10f846ce212eb45685b764cc7cf3b7d6efe6888..3a525e76f4e42a2f9ee9ac470855b2184bc6d944 100644 (file)
@@ -36,8 +36,8 @@
 #include "conf.h"
 #include "runmodes.h"
 #include "runmode-netmap.h"
-#include "log-httplog.h"
 #include "output.h"
+#include "log-httplog.h"
 #include "detect-engine-mpm.h"
 
 #include "alert-fastlog.h"
index 684218acba7c14bd9a06d7700215f1580f75cecd..850bcb7e3975bad84cd6cdd6a024d2e6e2b15dd7 100644 (file)
@@ -20,8 +20,8 @@
 #include "conf.h"
 #include "runmodes.h"
 #include "runmode-pcap.h"
-#include "log-httplog.h"
 #include "output.h"
+#include "log-httplog.h"
 
 #include "util-debug.h"
 #include "util-time.h"
index 2abf9dd97bc3d2e9cbeea83ec58e1b1329a444cf..4f4e7f70c2536c0df6835855183625d8791559cd 100644 (file)
@@ -39,6 +39,8 @@
 #include "util-unittest.h"
 #include "util-misc.h"
 
+#include "output.h"
+
 #include "alert-fastlog.h"
 #include "alert-prelude.h"
 #include "alert-unified2-alert.h"
@@ -46,8 +48,6 @@
 
 #include "log-httplog.h"
 
-#include "output.h"
-
 #include "source-pfring.h"
 
 #include "tmqh-flow.h"
@@ -611,16 +611,15 @@ static void RunModeInitializeEveOutput(ConfNode *conf, OutputCtx *parent_ctx)
                 // sub_output_config may be NULL if no config
 
                 /* pass on parent output_ctx */
-                OutputCtx *sub_output_ctx =
-                    sub_module->InitSubFunc(sub_output_config,
-                            parent_ctx);
-                if (sub_output_ctx == NULL) {
+                OutputInitResult result =
+                    sub_module->InitSubFunc(sub_output_config, parent_ctx);
+                if (!result.ok || result.ctx == NULL) {
                     continue;
                 }
 
-                AddOutputToFreeList(sub_module, sub_output_ctx);
+                AddOutputToFreeList(sub_module, result.ctx);
                 SetupOutput(sub_module->name, sub_module,
-                        sub_output_ctx);
+                        result.ctx);
             }
         }
 
@@ -656,15 +655,13 @@ static void RunModeInitializeLuaOutput(ConfNode *conf, OutputCtx *parent_ctx)
         BUG_ON(script == NULL);
 
         /* pass on parent output_ctx */
-        OutputCtx *sub_output_ctx =
-            m->InitSubFunc(script, parent_ctx);
-        if (sub_output_ctx == NULL) {
-            SCLogInfo("sub_output_ctx NULL, skipping");
+        OutputInitResult result = m->InitSubFunc(script, parent_ctx);
+        if (!result.ok || result.ctx == NULL) {
             continue;
         }
 
-        AddOutputToFreeList(m, sub_output_ctx);
-        SetupOutput(m->name, m, sub_output_ctx);
+        AddOutputToFreeList(m, result.ctx);
+        SetupOutput(m->name, m, result.ctx);
     }
 }
 
@@ -756,12 +753,15 @@ void RunModeInitializeOutputs(void)
 
             OutputCtx *output_ctx = NULL;
             if (module->InitFunc != NULL) {
-                output_ctx = module->InitFunc(output_config);
-                if (output_ctx == NULL) {
+                OutputInitResult r = module->InitFunc(output_config);
+                if (!r.ok) {
                     FatalErrorOnInit(SC_ERR_INVALID_ARGUMENT,
                         "output module setup failed");
                     continue;
+                } else if (r.ctx == NULL) {
+                    continue;
                 }
+                output_ctx = r.ctx;
             } else if (module->InitSubFunc != NULL) {
                 SCLogInfo("skipping submodule");
                 continue;
@@ -814,10 +814,15 @@ void RunModeInitializeOutputs(void)
 
                 OutputCtx *output_ctx = NULL;
                 if (module->InitFunc != NULL) {
-                    output_ctx = module->InitFunc(output_config);
-                    if (output_ctx == NULL) {
+                    OutputInitResult r = module->InitFunc(output_config);
+                    if (!r.ok) {
+                        FatalErrorOnInit(SC_ERR_INVALID_ARGUMENT,
+                                "output module setup failed");
+                        continue;
+                    } else if (r.ctx == NULL) {
                         continue;
                     }
+                    output_ctx = r.ctx;
                 }
 
                 AddOutputToFreeList(module, output_ctx);
index c1a963ee6563b1be01f31127741b711ce6615e05..19b15e2811b8eb5d1b2e2c9141e3130483c810fb 100644 (file)
@@ -30,8 +30,8 @@
 #include "conf.h"
 #include "runmodes.h"
 #include "runmode-af-packet.h"
-#include "log-httplog.h"
 #include "output.h"
+#include "log-httplog.h"
 
 #include "detect-engine.h"
 #include "detect-engine-mpm.h"