log/tcp-data: replace BUG_ON with graceful error handling

Replace the BUG_ON with proper error handling so that any fopen() failure
logs a warning and skips the chunk instead of causing a crash.

Adds a few more warnings for error conditions.

Ticket: #8823.
pull/16213/head
Victor Julien 3 months ago committed by Victor Julien
parent 710fbb81a5
commit 26d6410d16

@ -103,12 +103,19 @@ static int LogTcpDataLoggerDir(ThreadVars *tv, void *thread_data, const Flow *f,
flags & OUTPUT_STREAMING_FLAG_TOSERVER ? "ts" : "tc");
FILE *fp = fopen(name, mode);
BUG_ON(fp == NULL);
if (fp == NULL) {
SCLogWarning("failed to open '%s': %s", name, strerror(errno));
SCReturnInt(TM_ECODE_OK);
}
// PrintRawDataFp(stdout, (uint8_t *)data, data_len);
fwrite(data, data_len, 1, fp);
if (fwrite(data, data_len, 1, fp) != 1) {
SCLogWarning("write to '%s' failed: %s", name, strerror(errno));
}
fclose(fp);
if (fclose(fp) != 0) {
SCLogWarning("failed to close '%s': %s", name, strerror(errno));
}
}
SCReturnInt(TM_ECODE_OK);
}
@ -281,8 +288,13 @@ OutputInitResult LogTcpDataLogInitCtx(SCConfNode *conf)
SCLogInfo("using directory %s", dirfull);
/* if mkdir fails file open will fail, so deal with errors there */
(void)SCMkDir(dirfull, 0700);
if (SCMkDir(dirfull, 0700) < 0 && errno != EEXIST) {
SCLogError("failed to create log directory '%s': %s", dirfull, strerror(errno));
LogFileFreeCtx(file_ctx);
SCFree(tcpdatalog_ctx);
result = (OutputInitResult){ NULL, false };
return result;
}
}
OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx));

Loading…
Cancel
Save