allow to disable state management

Resolves: RHEL-69959
This commit is contained in:
Jan Macku 2025-05-30 14:10:21 +02:00
parent 737b02cf38
commit 039cb75506
3 changed files with 90 additions and 1 deletions

View File

@ -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?=
<tpo_deb@sourcepole.ch>
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

View File

@ -0,0 +1,52 @@
From 887287f6b7e7e6bd991d262d71436237617ab696 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= <cgzones@googlemail.com>
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

View File

@ -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 <jamacku@redhat.com> - 3.18.0-10
- allow to disable state management (RHEL-69959)
* Thu Jan 02 2025 Jan Macku <jamacku@redhat.com> - 3.18.0-9
- config: introduce `ignoreduplicates` configuration directive (#RHEL-5711)