-/* Copyright (C) 2020-2023 Open Information Security Foundation
+/* Copyright (C) 2020-2024 Open Information Security Foundation
*
* You can copy, redistribute or modify this Program under the terms of
* the GNU General Public License version 2 as published by the Free
typedef struct Context_ {
/** Verbose, or print to stdout. */
int verbose;
-
- /** A thread context to use when not running in threaded mode. */
- ThreadData *thread;
} Context;
/**
* \param data A pointer where context data can be stored relevant to this
* output.
*
- * Eve output plugins need to be thread aware as the threading happens at lower
- * level than the EVE output, so a flag is provided here to notify the plugin if
- * threading is enabled or not.
+ * Eve output plugins need to be thread aware as the threading happens
+ * at a lower level than the EVE output, so a flag is provided here to
+ * notify the plugin if threading is enabled or not.
*
* If the plugin does not work with threads disabled, or enabled, this function
* should return -1.
}
context->verbose = verbose;
- if (!threaded) {
- /* We're not running in threaded mode so allocate a thread context here
- * to avoid duplication of context data such as file pointers, database
- * connections, etc. */
- if (FiletypeThreadInit(context, 0, (void **)&context->thread) != 0) {
- SCFree(context);
- return -1;
- }
- }
*data = context;
return 0;
}
*/
static void FiletypeDeinit(void *data)
{
- printf("TemplateClose\n");
+ SCLogNotice("data=%p", data);
Context *ctx = data;
if (ctx != NULL) {
- if (ctx->thread) {
- FiletypeThreadDeinit(ctx, (void *)ctx->thread);
- }
SCFree(ctx);
}
}
* of "eve.<thread_id>.json". This plugin may want to do similar, or open
* multiple connections to whatever the final logging location might be.
*
- * In the case of non-threaded EVE logging this function is NOT called by
- * Suricata, but instead this plugin chooses to use this method to create a
- * default (single) thread context.
+ * In the case of non-threaded EVE logging this function is called
+ * once with a thread_id of 0.
*/
static int FiletypeThreadInit(void *ctx, ThreadId thread_id, void **thread_data)
{
+ SCLogNotice("thread_id=%d", thread_id);
ThreadData *tdata = SCCalloc(1, sizeof(ThreadData));
if (tdata == NULL) {
SCLogError("Failed to allocate thread data");
*/
static int FiletypeThreadDeinit(void *ctx, void *thread_data)
{
+ SCLogNotice("thread_data=%p", thread_data);
if (thread_data == NULL) {
// Nothing to do.
return 0;
Context *ctx = data;
ThreadData *thread = thread_data;
- /* The thread_data could be null which is valid, or it could be that we are
- * in single threaded mode. */
- if (thread == NULL) {
- thread = ctx->thread;
- }
+ SCLogNotice("thread_id=%d, data=%p, thread_data=%p", thread->thread_id, data, thread_data);
thread->count++;
return -1;
}
}
- void *init_data = NULL;
- if (json_ctx->filetype->Init(conf, json_ctx->file_ctx->threaded, &init_data) < 0) {
+ if (json_ctx->filetype->Init(conf, json_ctx->file_ctx->threaded,
+ &json_ctx->file_ctx->filetype.init_data) < 0) {
+ return -1;
+ }
+ if (json_ctx->filetype->ThreadInit(json_ctx->file_ctx->filetype.init_data, 0,
+ &json_ctx->file_ctx->filetype.thread_data) < 0) {
return -1;
}
json_ctx->file_ctx->filetype.filetype = json_ctx->filetype;
- json_ctx->file_ctx->filetype.init_data = init_data;
}
return 0;