From a07c97754b90d3a735356053a05a6ee026dd53a5 Mon Sep 17 00:00:00 2001 From: Cropi Date: Tue, 29 Jul 2025 16:02:32 +0200 Subject: [PATCH] imfile: reintroduce deleteStateOnFileMove parameter Resolves: RHEL-92757 --- imfile-delete-state-on-file-move.patch | 101 +++++++++++++++++++++++++ rsyslog.spec | 8 +- 2 files changed, 108 insertions(+), 1 deletion(-) create mode 100644 imfile-delete-state-on-file-move.patch diff --git a/imfile-delete-state-on-file-move.patch b/imfile-delete-state-on-file-move.patch new file mode 100644 index 0000000..ce8c2de --- /dev/null +++ b/imfile-delete-state-on-file-move.patch @@ -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")) { diff --git a/rsyslog.spec b/rsyslog.spec index 8c8e657..557ba8b 100644 --- a/rsyslog.spec +++ b/rsyslog.spec @@ -37,7 +37,7 @@ Summary: Enhanced system logging and kernel message trapping daemon Name: rsyslog Version: 8.2506.0 -Release: 1%{?dist} +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 @@ -71,6 +71,7 @@ BuildRequires: zlib-devel BuildRequires: libcap-ng-devel Patch0: openssl-disable-engines.patch +Patch1: imfile-delete-state-on-file-move.patch Recommends: logrotate Obsoletes: rsyslog-logrotate < 8.2310.0-2 @@ -386,6 +387,7 @@ mv build doc %setup -q -D %patch -P 0 -p1 +%patch -P 1 -p1 %if %{with omamqp1} # Unpack qpid-proton @@ -770,6 +772,10 @@ done %changelog +* Tue Jul 29 2025 Attila Lakatos 8.2506.0-2 +- imfile: reintroduce deleteStateOnFileMove parameter + Resolves: RHEL-92757 + * Thu Jun 12 2025 Attila Lakatos - 8.2506.0-1 - Rebase to 8.2506.0 - imuxsock: track dropped messages by ratelimiting