Blame SOURCES/rsyslog-8.1911.0-rhbz1793569-imfile-file_id.patch

94be23
From 0c69ec76d8cac47bcfa78abae86229ad63c92b0b Mon Sep 17 00:00:00 2001
94be23
From: Jiri Vymazal <jvymazal@redhat.com>
94be23
Date: Tue, 21 Jan 2020 13:58:14 +0100
94be23
Subject: [PATCH] Fixed saving of old file_id for statefiles
94be23
94be23
Previously we saved old file_id unconditionally, which led to not
94be23
deleting old statefiles if files changes without rsyslog running.
94be23
Now it should work correctly.
94be23
---
94be23
 plugins/imfile/imfile.c | 7 +++++--
94be23
 1 file changed, 5 insertions(+), 2 deletions(-)
94be23
94be23
diff --git a/plugins/imfile/imfile.c b/plugins/imfile/imfile.c
94be23
index 908bb5901c..5ad44f6c59 100644
94be23
--- a/plugins/imfile/imfile.c
94be23
+++ b/plugins/imfile/imfile.c
94be23
@@ -1258,8 +1258,8 @@ get_file_id_hash(const char *data, size_t lendata,
94be23
 static void ATTR_NONNULL(1)
94be23
 getFileID(act_obj_t *const act)
94be23
 {
94be23
-	/* save the old id for cleaning purposes */
94be23
-	strncpy(act->file_id_prev, (const char*)act->file_id, FILE_ID_HASH_SIZE);
94be23
+	char tmp_id[FILE_ID_HASH_SIZE];
94be23
+	strncpy(tmp_id, (const char*)act->file_id, FILE_ID_HASH_SIZE);
94be23
 	act->file_id[0] = '\0';
94be23
 	assert(act->fd >= 0); /* fd must have been opened at act_obj_t creation! */
94be23
 	char filedata[FILE_ID_SIZE];
94be23
@@ -1270,6 +1270,9 @@ getFileID(act_obj_t *const act)
94be23
 	} else {
94be23
 		DBGPRINTF("getFileID partial or error read, ret %d\n", r);
94be23
 	}
94be23
+	if (strncmp(tmp_id, act->file_id, FILE_ID_HASH_SIZE)) {/* save the old id for cleaning purposes */
94be23
+		strncpy(act->file_id_prev, tmp_id, FILE_ID_HASH_SIZE);
94be23
+	}
94be23
 	DBGPRINTF("getFileID for '%s', file_id_hash '%s'\n", act->name, act->file_id);
94be23
 }
94be23