737b02cf38
Resolves: RHEL-5711
148 lines
6.6 KiB
Diff
148 lines
6.6 KiB
Diff
From b92841ef7539cf51a5fbc1e18ec03981331e242e Mon Sep 17 00:00:00 2001
|
|
From: Falk Werner <falk.werner@gmx.net>
|
|
Date: Thu, 17 Nov 2022 18:20:22 +0100
|
|
Subject: [PATCH 2/3] config: introduce `ignoreduplicates` configuration
|
|
directive
|
|
|
|
... to allow duplicate file matches
|
|
|
|
Closes: https://github.com/logrotate/logrotate/pull/473
|
|
(cherry picked from commit 986f32af66db7248326ac647cd0b24b79da34b4d)
|
|
---
|
|
config.c | 39 ++++++++++++++++++++++++++-------------
|
|
logrotate.8.in | 4 ++++
|
|
logrotate.h | 33 +++++++++++++++++----------------
|
|
3 files changed, 47 insertions(+), 29 deletions(-)
|
|
|
|
diff --git a/config.c b/config.c
|
|
index c0fd4ff..e76fad0 100644
|
|
--- a/config.c
|
|
+++ b/config.c
|
|
@@ -1380,6 +1380,8 @@ static int readConfigFile(const char *configFile, struct logInfo *defConfig)
|
|
newlog->flags |= LOG_FLAG_MISSINGOK;
|
|
} else if (!strcmp(key, "nomissingok")) {
|
|
newlog->flags &= ~LOG_FLAG_MISSINGOK;
|
|
+ } else if (!strcmp(key, "ignoreduplicates")) {
|
|
+ newlog->flags |= LOG_FLAG_IGNOREDUPLICATES;
|
|
} else if (!strcmp(key, "prerotate")) {
|
|
freeLogItem (pre);
|
|
scriptStart = start;
|
|
@@ -1812,6 +1814,7 @@ static int readConfigFile(const char *configFile, struct logInfo *defConfig)
|
|
|
|
for (glob_count = 0; glob_count < globResult.gl_pathc; glob_count++) {
|
|
struct logInfo *log;
|
|
+ int add_file = 1;
|
|
|
|
/* if we glob directories we can get false matches */
|
|
if (!lstat(globResult.gl_pathv[glob_count], &sb) &&
|
|
@@ -1825,24 +1828,34 @@ static int readConfigFile(const char *configFile, struct logInfo *defConfig)
|
|
for (k = 0; k < log->numFiles; k++) {
|
|
if (!strcmp(log->files[k],
|
|
globResult.gl_pathv[glob_count])) {
|
|
- message(MESS_ERROR,
|
|
- "%s:%d duplicate log entry for %s\n",
|
|
- configFile, lineNum,
|
|
- globResult.gl_pathv[glob_count]);
|
|
- logerror = 1;
|
|
- goto duperror;
|
|
+ if (log->flags & LOG_FLAG_IGNOREDUPLICATES) {
|
|
+ add_file = 0;
|
|
+ message(MESS_DEBUG,
|
|
+ "%s:%d ignore duplicate log entry for %s\n",
|
|
+ configFile, lineNum,
|
|
+ globResult.gl_pathv[glob_count]);
|
|
+ } else {
|
|
+ message(MESS_ERROR,
|
|
+ "%s:%d duplicate log entry for %s\n",
|
|
+ configFile, lineNum,
|
|
+ globResult.gl_pathv[glob_count]);
|
|
+ logerror = 1;
|
|
+ goto duperror;
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
|
|
- newlog->files[newlog->numFiles] =
|
|
- strdup(globResult.gl_pathv[glob_count]);
|
|
- if (newlog->files[newlog->numFiles] == NULL) {
|
|
- message_OOM();
|
|
- logerror = 1;
|
|
- goto duperror;
|
|
+ if (add_file) {
|
|
+ newlog->files[newlog->numFiles] =
|
|
+ strdup(globResult.gl_pathv[glob_count]);
|
|
+ if (newlog->files[newlog->numFiles] == NULL) {
|
|
+ message_OOM();
|
|
+ logerror = 1;
|
|
+ goto duperror;
|
|
+ }
|
|
+ newlog->numFiles++;
|
|
}
|
|
- newlog->numFiles++;
|
|
}
|
|
duperror:
|
|
globfree(&globResult);
|
|
diff --git a/logrotate.8.in b/logrotate.8.in
|
|
index f0aa23f..e0a3ed8 100644
|
|
--- a/logrotate.8.in
|
|
+++ b/logrotate.8.in
|
|
@@ -299,6 +299,10 @@ message. See also \fBnomissingok\fR.
|
|
\fBnomissingok\fR
|
|
If a log file does not exist, issue an error. This is the default.
|
|
|
|
+.TP
|
|
+\fBignoreduplicates\fR
|
|
+Ignore any following matches of a log file.
|
|
+
|
|
.TP
|
|
\fBifempty\fR
|
|
Rotate the log file even if it is empty, overriding the \fBnotifempty\fR
|
|
diff --git a/logrotate.h b/logrotate.h
|
|
index 0a086ae..26e516b 100644
|
|
--- a/logrotate.h
|
|
+++ b/logrotate.h
|
|
@@ -11,22 +11,23 @@
|
|
# include <libgen.h>
|
|
#endif
|
|
|
|
-#define LOG_FLAG_COMPRESS (1U << 0)
|
|
-#define LOG_FLAG_CREATE (1U << 1)
|
|
-#define LOG_FLAG_IFEMPTY (1U << 2)
|
|
-#define LOG_FLAG_DELAYCOMPRESS (1U << 3)
|
|
-#define LOG_FLAG_COPYTRUNCATE (1U << 4)
|
|
-#define LOG_FLAG_MISSINGOK (1U << 5)
|
|
-#define LOG_FLAG_MAILFIRST (1U << 6)
|
|
-#define LOG_FLAG_SHAREDSCRIPTS (1U << 7)
|
|
-#define LOG_FLAG_COPY (1U << 8)
|
|
-#define LOG_FLAG_DATEEXT (1U << 9)
|
|
-#define LOG_FLAG_SHRED (1U << 10)
|
|
-#define LOG_FLAG_SU (1U << 11)
|
|
-#define LOG_FLAG_DATEYESTERDAY (1U << 12)
|
|
-#define LOG_FLAG_OLDDIRCREATE (1U << 13)
|
|
-#define LOG_FLAG_TMPFILENAME (1U << 14)
|
|
-#define LOG_FLAG_DATEHOURAGO (1U << 15)
|
|
+#define LOG_FLAG_COMPRESS (1U << 0)
|
|
+#define LOG_FLAG_CREATE (1U << 1)
|
|
+#define LOG_FLAG_IFEMPTY (1U << 2)
|
|
+#define LOG_FLAG_DELAYCOMPRESS (1U << 3)
|
|
+#define LOG_FLAG_COPYTRUNCATE (1U << 4)
|
|
+#define LOG_FLAG_MISSINGOK (1U << 5)
|
|
+#define LOG_FLAG_MAILFIRST (1U << 6)
|
|
+#define LOG_FLAG_SHAREDSCRIPTS (1U << 7)
|
|
+#define LOG_FLAG_COPY (1U << 8)
|
|
+#define LOG_FLAG_DATEEXT (1U << 9)
|
|
+#define LOG_FLAG_SHRED (1U << 10)
|
|
+#define LOG_FLAG_SU (1U << 11)
|
|
+#define LOG_FLAG_DATEYESTERDAY (1U << 12)
|
|
+#define LOG_FLAG_OLDDIRCREATE (1U << 13)
|
|
+#define LOG_FLAG_TMPFILENAME (1U << 14)
|
|
+#define LOG_FLAG_DATEHOURAGO (1U << 15)
|
|
+#define LOG_FLAG_IGNOREDUPLICATES (1U << 17)
|
|
|
|
#define NO_MODE ((mode_t) -1)
|
|
#define NO_UID ((uid_t) -1)
|
|
--
|
|
2.47.1
|
|
|