Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

output/log: Improve error handling if log output initialization/open fails. #12271

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions src/util-logopenfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -346,14 +346,17 @@ static void ThreadLogFileHashFreeFunc(void *data)
BUG_ON(data == NULL);
ThreadLogFileHashEntry *thread_ent = (ThreadLogFileHashEntry *)data;

if (thread_ent) {
if (!thread_ent)
return;

if (thread_ent->isopen) {
LogFileCtx *lf_ctx = thread_ent->ctx;
/* Free the leaf log file entries */
if (!lf_ctx->threaded) {
LogFileFreeCtx(lf_ctx);
}
SCFree(thread_ent);
}
SCFree(thread_ent);
}

bool SCLogOpenThreadedFile(const char *log_path, const char *append, LogFileCtx *parent_ctx)
Expand Down Expand Up @@ -712,6 +715,7 @@ LogFileCtx *LogFileEnsureExists(ThreadId thread_id, LogFileCtx *parent_ctx)
if (!parent_ctx->threaded)
return parent_ctx;

LogFileCtx *ret_ctx = NULL;
SCMutexLock(&parent_ctx->threads->mutex);
/* Find this thread's entry */
ThreadLogFileHashEntry *entry = LogFileThread2Slot(parent_ctx->threads, thread_id);
Expand All @@ -721,14 +725,15 @@ LogFileCtx *LogFileEnsureExists(ThreadId thread_id, LogFileCtx *parent_ctx)

bool new = entry->isopen;
/* has it been opened yet? */
if (!entry->isopen) {
if (!new) {
SCLogDebug("%s: Opening new file for thread/id %d to file %s [ctx %p]", t_thread_name,
thread_id, parent_ctx->filename, parent_ctx);
if (LogFileNewThreadedCtx(
parent_ctx, parent_ctx->filename, parent_ctx->threads->append, entry)) {
entry->isopen = true;
ret_ctx = entry->ctx;
} else {
SCLogError(
SCLogDebug(
"Unable to open slot %d for file %s", entry->slot_number, parent_ctx->filename);
(void)HashTableRemove(parent_ctx->threads->ht, entry, 0);
}
Expand All @@ -742,7 +747,7 @@ LogFileCtx *LogFileEnsureExists(ThreadId thread_id, LogFileCtx *parent_ctx)
}
}

return entry->ctx;
return ret_ctx;
}

/** \brief LogFileThreadedName() Create file name for threaded EVE storage
Expand Down
Loading