!21 do not rotate logs on prerotate failure

From: @han_hui_hui 
Reviewed-by: @yanan-rock 
Signed-off-by: @yanan-rock
This commit is contained in:
openeuler-ci-bot 2023-06-07 03:59:56 +00:00 committed by Gitee
commit e3bb8abc4d
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
2 changed files with 50 additions and 1 deletions

View File

@ -0,0 +1,45 @@
From 5f24239f282b8c6291cf35ea5f871ed0ca6b2672 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= <cgzones@googlemail.com>
Date: Tue, 4 Apr 2023 17:49:06 +0200
Subject: [PATCH] do not rotate old logs on prerotate failure
Ensures old logs are preserved and not rotated out for logs with a
failing prerotate script.
Alternative to #502
---
logrotate.c | 14 ++++++++++----
1 files changed, 10 insertions(+), 4 deletions(-)
diff --git a/logrotate.c b/logrotate.c
index f44b3851..d3ccb447 100644
--- a/logrotate.c
+++ b/logrotate.c
@@ -2476,10 +2476,6 @@ static int rotateLogSet(const struct logInfo *log, int force)
return 1;
}
memset(rotNames[i], 0, sizeof(struct logNames));
-
- logHasErrors[i] |=
- prerotateSingleLog(log, i, state[i], rotNames[i]);
- hasErrors |= logHasErrors[i];
}
if (log->pre
@@ -2509,6 +2505,16 @@ static int rotateLogSet(const struct logInfo *log, int force)
}
}
+ for (i = j;
+ ((log->flags & LOG_FLAG_SHAREDSCRIPTS) && i < log->numFiles)
+ || (!(log->flags & LOG_FLAG_SHAREDSCRIPTS) && i == j); i++) {
+ if (! ( (logHasErrors[i] && !(log->flags & LOG_FLAG_SHAREDSCRIPTS))
+ || (hasErrors && (log->flags & LOG_FLAG_SHAREDSCRIPTS)) ) ) {
+ logHasErrors[i] |= prerotateSingleLog(log, i, state[i], rotNames[i]);
+ hasErrors |= logHasErrors[i];
+ }
+ }
+
for (i = j;
((log->flags & LOG_FLAG_SHAREDSCRIPTS) && i < log->numFiles)
|| (!(log->flags & LOG_FLAG_SHAREDSCRIPTS) && i == j); i++) {

View File

@ -2,7 +2,7 @@
Name: logrotate
Version: 3.16.0
Release: 4
Release: 5
Summary: simplify the administration of log files
License: GPLv2+
Url: https://github.com/logrotate/logrotate
@ -13,6 +13,7 @@ Patch6001: backport-add-sanity-check.patch
Patch6002: backport-improve-debug-logging.patch
Patch6003: backport-call-switch_user_back-on-early-return.patch
Patch6004: backport-Also-check-seteuid-fails-after-dropping-privileges.patch
Patch6005: backport-do-not-rotate-old-logs-on-prerotate-failure.patch
BuildRequires: acl gcc automake libacl-devel libselinux-devel popt-devel
Requires: coreutils
@ -80,6 +81,9 @@ fi
%{_mandir}/man5/logrotate.conf.5*
%changelog
* Mon Jun 5 2023 hanhuihui <hanhuihui5@huawei.com> - 3.16.0-5
- do not rotate old logs on prerotate failure
* Tue Mar 29 2022 dongyuzhen <dongyuzhen@h-partners.com> - 3.16.0-4
- fix switch_user_permanently: skip switchback check if switched to root