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

38 lines
1.5 KiB
Diff
Raw Normal View History

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