From 039cb755061802af0f235a26e4715b3ef4d89bea Mon Sep 17 00:00:00 2001 From: Jan Macku Date: Fri, 30 May 2025 14:10:21 +0200 Subject: [PATCH] allow to disable state management Resolves: RHEL-69959 --- ...tion-for-state-dev-null-special-case.patch | 30 +++++++++++ ...18.0-Do-not-lock-state-file-dev-null.patch | 52 +++++++++++++++++++ logrotate.spec | 9 +++- 3 files changed, 90 insertions(+), 1 deletion(-) create mode 100644 0009-logrotate-3.18.0-add-documentation-for-state-dev-null-special-case.patch create mode 100644 0010-logrotate-3.18.0-Do-not-lock-state-file-dev-null.patch diff --git a/0009-logrotate-3.18.0-add-documentation-for-state-dev-null-special-case.patch b/0009-logrotate-3.18.0-add-documentation-for-state-dev-null-special-case.patch new file mode 100644 index 0000000..0a25d62 --- /dev/null +++ b/0009-logrotate-3.18.0-add-documentation-for-state-dev-null-special-case.patch @@ -0,0 +1,30 @@ +From 4ad3d9c362ecd72dd733338d36dde740e5363857 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Posp=C3=AD=C5=A1ek?= + +Date: Thu, 3 Jun 2021 10:37:47 +0200 +Subject: [PATCH 1/2] add documentation for --state /dev/null special case + +This is documentation for the suggested implementation of #395 aka `--state /dev/null` will not write any state file. + +Closes: https://github.com/logrotate/logrotate/pull/396 +(cherry picked from commit ecccf4778695dc5cb3c25bfd13e7a0ab9dc50ec4) +--- + logrotate.8.in | 2 ++ + 1 file changed, 2 insertions(+) + +diff --git a/logrotate.8.in b/logrotate.8.in +index e0a3ed8..bde2a0e 100644 +--- a/logrotate.8.in ++++ b/logrotate.8.in +@@ -75,6 +75,8 @@ if \fBlogrotate\fR is being run as a different user for various sets of + log files. To prevent parallel execution \fBlogrotate\fR by default + acquires a lock on the state file, if it cannot be acquired \fBlogrotate\fR + will exit with value 3. The default state file is \fI@STATE_FILE_PATH@\fR. ++If \fI/dev/null\fR is given as the state file, then \fBlogrotate\fR will ++not try to write the state file. + + .TP + \fB\-\-skip-state-lock\fR +-- +2.49.0 + diff --git a/0010-logrotate-3.18.0-Do-not-lock-state-file-dev-null.patch b/0010-logrotate-3.18.0-Do-not-lock-state-file-dev-null.patch new file mode 100644 index 0000000..fbe8262 --- /dev/null +++ b/0010-logrotate-3.18.0-Do-not-lock-state-file-dev-null.patch @@ -0,0 +1,52 @@ +From 887287f6b7e7e6bd991d262d71436237617ab696 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= +Date: Mon, 17 Jan 2022 17:39:08 +0100 +Subject: [PATCH 2/2] Do not lock state file /dev/null + +state file is desired. +lockState() tries to open and lock the state file to avoid issues with +concurrent instances, see #295. +Locking the character file /dev/null might either be not supported, e.g. +on Debian GNU/Hurd (hurd-i386), nor not allowed, e.g. by SELinux. + +(cherry picked from commit c7078c2b393fce376d79317a9a03de8b8e404cde) +--- + logrotate.8.in | 2 +- + logrotate.c | 8 +++++++- + 2 files changed, 8 insertions(+), 2 deletions(-) + +diff --git a/logrotate.8.in b/logrotate.8.in +index bde2a0e..c0ac5c4 100644 +--- a/logrotate.8.in ++++ b/logrotate.8.in +@@ -76,7 +76,7 @@ log files. To prevent parallel execution \fBlogrotate\fR by default + acquires a lock on the state file, if it cannot be acquired \fBlogrotate\fR + will exit with value 3. The default state file is \fI@STATE_FILE_PATH@\fR. + If \fI/dev/null\fR is given as the state file, then \fBlogrotate\fR will +-not try to write the state file. ++not try to lock or write the state file. + + .TP + \fB\-\-skip-state-lock\fR +diff --git a/logrotate.c b/logrotate.c +index 819aaed..1bb95b2 100644 +--- a/logrotate.c ++++ b/logrotate.c +@@ -2906,7 +2906,13 @@ static int readState(const char *stateFilename) + static int lockState(const char *stateFilename, int skip_state_lock) + { + struct stat sb; +- int lockFd = open(stateFilename, O_RDWR | O_CLOEXEC); ++ int lockFd; ++ ++ if (!strcmp(stateFilename, "/dev/null")) { ++ return 0; ++ } ++ ++ lockFd = open(stateFilename, O_RDWR | O_CLOEXEC); + if (lockFd == -1) { + if (errno == ENOENT) { + message(MESS_DEBUG, "Creating stub state file: %s\n", +-- +2.49.0 + diff --git a/logrotate.spec b/logrotate.spec index d09f857..8ae5956 100644 --- a/logrotate.spec +++ b/logrotate.spec @@ -1,7 +1,7 @@ Summary: Rotates, compresses, removes and mails system log files Name: logrotate Version: 3.18.0 -Release: 9%{?dist} +Release: 10%{?dist} License: GPLv2+ URL: https://github.com/logrotate/logrotate Source0: https://github.com/logrotate/logrotate/releases/download/%{version}/logrotate-%{version}.tar.xz @@ -27,6 +27,10 @@ Patch: 0006-logrotate-3.18.0-Ensure-the-type-for-configuration-flags-is-wide-e Patch: 0007-logrotate-3.18.0-config-introduce-ignoreduplicates-configuration-dire.patch Patch: 0008-logrotate-3.18.0-test-0107-cover-the-ignoreduplicates-configuration-d.patch +# allow to disable state management (RHEL-69959) +Patch: 0009-logrotate-3.18.0-add-documentation-for-state-dev-null-special-case.patch +Patch: 0010-logrotate-3.18.0-Do-not-lock-state-file-dev-null.patch + BuildRequires: acl BuildRequires: automake BuildRequires: gcc @@ -127,6 +131,9 @@ fi %config(noreplace) %{_sysconfdir}/rwtab.d/logrotate %changelog +* Fri May 30 2025 Jan Macku - 3.18.0-10 +- allow to disable state management (RHEL-69959) + * Thu Jan 02 2025 Jan Macku - 3.18.0-9 - config: introduce `ignoreduplicates` configuration directive (#RHEL-5711)