From: Philippe Antoine Date: Tue, 27 Feb 2024 20:45:03 +0000 (+0100) Subject: output/filestore: delay snprintf until needed X-Git-Tag: suricata-8.0.0-beta1~1700 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d255a5c7a309c067e15dde01560631f4ed427db1;p=thirdparty%2Fsuricata.git output/filestore: delay snprintf until needed Perf optimization so that we do not call snprintf in the common code path. Ticket: 6796 --- diff --git a/src/output-filestore.c b/src/output-filestore.c index d67014d49e..5960f4ea47 100644 --- a/src/output-filestore.c +++ b/src/output-filestore.c @@ -194,9 +194,8 @@ static int OutputFilestoreLogger(ThreadVars *tv, void *thread_data, const Packet SCLogDebug("ff %p, data %p, data_len %u", ff, data, data_len); - snprintf(filename, sizeof(filename), "%s/file.%u", ctx->tmpdir, ff->file_store_id); - if (flags & OUTPUT_FILEDATA_FLAG_OPEN) { + snprintf(filename, sizeof(filename), "%s/file.%u", ctx->tmpdir, ff->file_store_id); file_fd = open(filename, O_CREAT | O_TRUNC | O_NOFOLLOW | O_WRONLY, 0644); if (file_fd == -1) { @@ -217,6 +216,7 @@ static int OutputFilestoreLogger(ThreadVars *tv, void *thread_data, const Packet /* we can get called with a NULL ffd when we need to close */ } else if (data != NULL) { if (ff->fd == -1) { + snprintf(filename, sizeof(filename), "%s/file.%u", ctx->tmpdir, ff->file_store_id); file_fd = open(filename, O_APPEND | O_NOFOLLOW | O_WRONLY); if (file_fd == -1) { StatsIncr(tv, aft->fs_error_counter); @@ -232,6 +232,7 @@ static int OutputFilestoreLogger(ThreadVars *tv, void *thread_data, const Packet if (file_fd != -1) { ssize_t r = write(file_fd, (const void *)data, (size_t)data_len); if (r == -1) { + snprintf(filename, sizeof(filename), "%s/file.%u", ctx->tmpdir, ff->file_store_id); StatsIncr(tv, aft->fs_error_counter); WARN_ONCE(WOT_WRITE, "Filestore (v2) failed to write to %s: %s", filename, strerror(errno));