]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
log/eve: Ensure eve logs have sequential suffixes
authorJeff Lucovsky <jeff@lucovsky.org>
Wed, 9 Sep 2020 12:59:32 +0000 (08:59 -0400)
committerVictor Julien <victor@inliniac.net>
Thu, 10 Sep 2020 18:41:12 +0000 (20:41 +0200)
This commit ensures that the eve logs have sequential suffixes without
gaps.

src/util-logopenfile.c

index 3eb6566aba884618dd92a3c4dfea8f0ad3ccec4c..f3af0c2b2b026a9e95f7b7a91e8e71f53bb6b155 100644 (file)
@@ -44,6 +44,9 @@
 static bool LogFileNewThreadedCtx(LogFileCtx *parent_ctx, const char *log_path, const char *append, int i);
 static bool SCLogOpenThreadedFileFp(const char *log_path, const char *append, LogFileCtx *parent_ctx, int slot_count);
 
+// Threaded eve.json suffixes
+static SC_ATOMIC_DECL_AND_INIT_WITH_VAL(uint32_t, eve_file_suffix, 1);
+
 #ifdef BUILD_WITH_UNIXSOCKET
 /** \brief connect to the indicated local stream socket, logging any errors
  *  \param path filesystem path to connect to
@@ -721,7 +724,7 @@ static bool LogFileNewThreadedCtx(LogFileCtx *parent_ctx, const char *log_path,
 
     *thread = *parent_ctx;
     char fname[NAME_MAX];
-    snprintf(fname, sizeof(fname), "%s.%d", log_path, thread_id);
+    snprintf(fname, sizeof(fname), "%s.%d", log_path, SC_ATOMIC_ADD(eve_file_suffix, 1));
     SCLogDebug("Thread open -- using name %s [replaces %s]", fname, log_path);
     thread->fp = SCLogOpenFileFp(fname, append, thread->filemode);
     if (thread->fp == NULL) {
@@ -745,6 +748,7 @@ static bool LogFileNewThreadedCtx(LogFileCtx *parent_ctx, const char *log_path,
     return true;
 
 error:
+    SC_ATOMIC_SUB(eve_file_suffix, 1);
     if (thread->fp) {
         thread->Close(thread);
     }