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

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