imfile: reintroduce deleteStateOnFileMove parameter

Resolves: RHEL-92262
This commit is contained in:
Cropi 2025-07-29 16:12:30 +02:00
parent 0d5d113585
commit 93bce384d2
3 changed files with 108 additions and 39 deletions

View File

@ -0,0 +1,101 @@
diff -up a/plugins/imfile/imfile.c.orig b/plugins/imfile/imfile.c
--- a/plugins/imfile/imfile.c.orig 2025-07-29 15:54:35.659288215 +0200
+++ b/plugins/imfile/imfile.c 2025-07-29 15:54:40.119329980 +0200
@@ -157,6 +157,7 @@ struct instanceConf_s {
int readTimeout;
unsigned delay_perMsg;
sbool bRMStateOnDel;
+ sbool bRMStateOnMove;
uint8_t readMode;
uchar *startRegex;
uchar *endRegex;
@@ -253,6 +254,7 @@ struct modConfData_s {
instanceConf_t *root, *tail;
fs_node_t *conf_tree;
uint8_t opMode;
+ sbool bRMStateOnMove;
sbool configSetViaV2Method;
uchar *stateFileDirectory;
sbool sortFiles;
@@ -310,7 +312,8 @@ static struct cnfparamdescr modpdescr[]
{ "sortfiles", eCmdHdlrBinary, 0 },
{ "statefile.directory", eCmdHdlrString, 0 },
{ "normalizepath", eCmdHdlrBinary, 0 },
- { "mode", eCmdHdlrGetWord, 0 }
+ { "mode", eCmdHdlrGetWord, 0 },
+ { "deletestateonfilemove", eCmdHdlrBinary, 0 },
};
static struct cnfparamblk modpblk =
{ CNFPARAMBLK_VERSION,
@@ -350,7 +353,8 @@ static struct cnfparamdescr inppdescr[]
{ "needparse", eCmdHdlrBinary, 0},
{ "ignoreolderthan", eCmdHdlrInt, 0},
{ "maxbytesperminute", eCmdHdlrInt, 0},
- { "maxlinesperminute", eCmdHdlrInt, 0}
+ { "maxlinesperminute", eCmdHdlrInt, 0},
+ { "deletestateonfilemove", eCmdHdlrBinary, 0}
};
static struct cnfparamblk inppblk =
{ CNFPARAMBLK_VERSION,
@@ -856,7 +860,7 @@ detect_updates(fs_edge_t *const edge)
*/
sbool is_file = act->edge->is_file;
if (!is_file || act->time_to_delete + FILE_DELETE_DELAY < ttNow) {
- DBGPRINTF("detect_updates obj gone away, unlinking: "
+ DBGPRINTF("detect_updates obj gone away, unlinking: "
"'%s', ttDelete: %"PRId64"s, ttNow:%"PRId64" isFile: %d\n",
act->name, (int64_t) ttNow - (act->time_to_delete + FILE_DELETE_DELAY),
(int64_t) ttNow, is_file);
@@ -1061,8 +1065,17 @@ act_obj_destroy(act_obj_t *const act, co
}
persistStrmState(act);
strm.Destruct(&act->pStrm);
- /* we delete state file after destruct in case strm obj initiated a write */
- if(is_deleted && !act->in_move && inst->bRMStateOnDel) {
+
+ /*
+ * We delete the state file after the destruct operation to ensure that any pending
+ * writes initiated by the stream object are completed before removal. The state file
+ * is deleted in the following scenarios:
+ * - If the file has not been moved and we are configured to delete the state file
+ * when the original file is removed.
+ * - If the configuration specifies not to preserve the state file after the file
+ * has been renamed. This prevents orphaned state files.
+ */
+ if(is_deleted && ((!act->in_move && inst->bRMStateOnDel) || inst->bRMStateOnMove)) {
DBGPRINTF("act_obj_destroy: deleting state file %s\n", statefn);
unlink((char*)statefn);
}
@@ -1773,6 +1786,7 @@ createInstance(instanceConf_t **const pi
inst->discardTruncatedMsg = 0;
inst->msgDiscardingError = 1;
inst->bRMStateOnDel = 1;
+ inst->bRMStateOnMove = loadModConf->bRMStateOnMove;
inst->escapeLF = 1;
inst->escapeLFString = NULL;
inst->reopenOnTruncate = 0;
@@ -1932,6 +1946,7 @@ addInstance(void __attribute__((unused))
inst->addMetadata = 0;
inst->addCeeTag = 0;
inst->bRMStateOnDel = 0;
+ inst->bRMStateOnMove = loadModConf->bRMStateOnMove;
inst->readTimeout = loadModConf->readTimeout;
inst->msgFlag = 0;
@@ -2089,6 +2104,7 @@ CODESTARTbeginCnfLoad
/* init our settings */
loadModConf->opMode = OPMODE_POLLING;
loadModConf->iPollInterval = DFLT_PollInterval;
+ loadModConf->bRMStateOnMove = 0;
loadModConf->configSetViaV2Method = 0;
loadModConf->readTimeout = 0; /* default: no timeout */
loadModConf->timeoutGranularity = 1000; /* default: 1 second */
@@ -2142,6 +2158,8 @@ CODESTARTsetModCnf
continue;
if(!strcmp(modpblk.descr[i].name, "pollinginterval")) {
loadModConf->iPollInterval = (int) pvals[i].val.d.n;
+ } else if(!strcmp(modpblk.descr[i].name, "deletestateonfilemove")) {
+ loadModConf->bRMStateOnMove = (sbool) pvals[i].val.d.n;
} else if(!strcmp(modpblk.descr[i].name, "readtimeout")) {
loadModConf->readTimeout = (int) pvals[i].val.d.n;
} else if(!strcmp(modpblk.descr[i].name, "timeoutgranularity")) {

View File

@ -1,36 +0,0 @@
diff -up rsyslog-8.2506.0/plugins/imfile/imfile.c.orig rsyslog-8.2506.0/plugins/imfile/imfile.c
--- rsyslog-8.2506.0/plugins/imfile/imfile.c.orig 2025-06-12 13:30:00.769607775 +0200
+++ rsyslog-8.2506.0/plugins/imfile/imfile.c 2025-06-12 13:30:26.453852622 +0200
@@ -157,6 +157,7 @@ struct instanceConf_s {
int readTimeout;
unsigned delay_perMsg;
sbool bRMStateOnDel;
+ sbool deleteStateOnFileMove; /* delete state file when file being monitored is moved */
uint8_t readMode;
uchar *startRegex;
uchar *endRegex;
@@ -340,6 +341,7 @@ static struct cnfparamdescr inppdescr[]
{ "persiststateinterval", eCmdHdlrInt, 0 },
{ "persiststateaftersubmission", eCmdHdlrBinary, 0 },
{ "deletestateonfiledelete", eCmdHdlrBinary, 0 },
+ { "deletestateonfilemove", eCmdHdlrBinary, 0 },
{ "delay.message", eCmdHdlrNonNegInt, 0 },
{ "addmetadata", eCmdHdlrBinary, 0 },
{ "addceetag", eCmdHdlrBinary, 0 },
@@ -1773,6 +1775,7 @@ createInstance(instanceConf_t **const pi
inst->discardTruncatedMsg = 0;
inst->msgDiscardingError = 1;
inst->bRMStateOnDel = 1;
+ inst->deleteStateOnFileMove = 0; /* default to not deleting state on file move */
inst->escapeLF = 1;
inst->escapeLFString = NULL;
inst->reopenOnTruncate = 0;
@@ -1995,6 +1998,8 @@ CODESTARTnewInpInst
inst->msgDiscardingError = (sbool) pvals[i].val.d.n;
} else if(!strcmp(inppblk.descr[i].name, "deletestateonfiledelete")) {
inst->bRMStateOnDel = (sbool) pvals[i].val.d.n; // TODO: duplicate!
+ } else if(!strcmp(inppblk.descr[i].name, "deletestateonfilemove")) {
+ inst->deleteStateOnFileMove = (sbool) pvals[i].val.d.n;
} else if(!strcmp(inppblk.descr[i].name, "addmetadata")) {
inst->addMetadata = (sbool) pvals[i].val.d.n;
} else if(!strcmp(inppblk.descr[i].name, "delay.message")) {

View File

@ -6,8 +6,8 @@
Summary: Enhanced system logging and kernel message trapping daemon
Name: rsyslog
Version: 8.2506.0
Release: 1%{?dist}
License: (GPLv3+ and ASL 2.0)
Release: 2%{?dist}
License: GPL-3.0-or-later AND Apache-2.0
URL: http://www.rsyslog.com/
Source0: http://www.rsyslog.com/files/download/rsyslog/%{name}-%{version}.tar.gz
Source1: http://www.rsyslog.com/files/download/rsyslog/%{name}-doc-%{version}.tar.gz
@ -21,7 +21,7 @@ Source6: https://archive.apache.org/dist/qpid/proton/%{qpid_proton_v}/qpid-proto
Source7: rsyslog-tmpfiles.conf
Patch0: openssl-disable-engines.patch
Patch1: imfile-deleteStateOnFileMove.patch
Patch1: imfile-delete-state-on-file-move.patch
BuildRequires: make
BuildRequires: gcc
@ -525,6 +525,10 @@ done
%changelog
* Tue Jul 29 2025 Attila Lakatos <alakatos@redhat.com> 8.2506.0-2
- imfile: reintroduce deleteStateOnFileMove parameter
Resolves: RHEL-92262
* Thu Jun 12 2025 Attila Lakatos <alakatos@redhat.com> - 8.2506.0-1
- Rebase to 8.2506.0
- imuxsock: track dropped messages by ratelimiting