File logrotate-ignore-duplicates.patch of Package logrotate.35787
commit 986f32af66db7248326ac647cd0b24b79da34b4d
Author: Falk Werner <falk.werner@gmx.net>
Date: Thu Nov 17 18:20:22 2022 +0100
config: introduce `ignoreduplicates` configuration directive
... to allow duplicate file matches
Closes: https://github.com/logrotate/logrotate/pull/473
Index: logrotate-3.18.1/config.c
===================================================================
--- logrotate-3.18.1.orig/config.c
+++ logrotate-3.18.1/config.c
@@ -1385,6 +1385,8 @@ static int readConfigFile(const char *co
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;
@@ -1817,6 +1819,7 @@ static int readConfigFile(const char *co
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) &&
@@ -1830,24 +1833,34 @@ static int readConfigFile(const char *co
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);
Index: logrotate-3.18.1/logrotate.8.in
===================================================================
--- logrotate-3.18.1.orig/logrotate.8.in
+++ logrotate-3.18.1/logrotate.8.in
@@ -299,6 +299,10 @@ message. See also \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
option (\fBifempty\fR is the default).
Index: logrotate-3.18.1/logrotate.h
===================================================================
--- logrotate-3.18.1.orig/logrotate.h
+++ logrotate-3.18.1/logrotate.h
@@ -1,6 +1,7 @@
#ifndef H_LOGROTATE
#define H_LOGROTATE
+#include <stdint.h>
#include <sys/types.h>
#include "queue.h"
#include <glob.h>
@@ -10,22 +11,23 @@
# include <libgen.h>
#endif
-#define LOG_FLAG_COMPRESS (1 << 0)
-#define LOG_FLAG_CREATE (1 << 1)
-#define LOG_FLAG_IFEMPTY (1 << 2)
-#define LOG_FLAG_DELAYCOMPRESS (1 << 3)
-#define LOG_FLAG_COPYTRUNCATE (1 << 4)
-#define LOG_FLAG_MISSINGOK (1 << 5)
-#define LOG_FLAG_MAILFIRST (1 << 6)
-#define LOG_FLAG_SHAREDSCRIPTS (1 << 7)
-#define LOG_FLAG_COPY (1 << 8)
-#define LOG_FLAG_DATEEXT (1 << 9)
-#define LOG_FLAG_SHRED (1 << 10)
-#define LOG_FLAG_SU (1 << 11)
-#define LOG_FLAG_DATEYESTERDAY (1 << 12)
-#define LOG_FLAG_OLDDIRCREATE (1 << 13)
-#define LOG_FLAG_TMPFILENAME (1 << 14)
-#define LOG_FLAG_DATEHOURAGO (1 << 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)
@@ -70,7 +72,7 @@ struct logInfo {
char *uncompress_prog;
char *compress_ext;
char *dateformat; /* specify format for strftime (for dateext) */
- int flags;
+ uint32_t flags;
int shred_cycles; /* if !=0, pass -n shred_cycles to GNU shred */
mode_t createMode; /* if any/all of these are -1, we use the */
uid_t createUid; /* attributes from the log file just rotated */
Index: logrotate-3.18.1/test/test-0107.sh
===================================================================
--- /dev/null
+++ logrotate-3.18.1/test/test-0107.sh
@@ -0,0 +1,15 @@
+#!/bin/sh
+
+. ./test-common.sh
+
+cleanup 107
+
+# ------------------------------- Test 107 ------------------------------------
+preptest test.log 107 1
+preptest zzzz.log 107 1
+$RLR test-config.107 --force || exit 23
+
+checkoutput <<EOF
+test.log.1 0 zero
+zzzz.log.1 0 zero
+EOF
Index: logrotate-3.18.1/test/test-config.107.in
===================================================================
--- /dev/null
+++ logrotate-3.18.1/test/test-config.107.in
@@ -0,0 +1,8 @@
+&DIR&/test.log {
+ rotate 1
+ ignoreduplicates
+}
+
+&DIR&/*.log {
+ rotate 1
+}
Index: logrotate-3.18.1/test/Makefile.am
===================================================================
--- logrotate-3.18.1.orig/test/Makefile.am
+++ logrotate-3.18.1/test/Makefile.am
@@ -93,7 +93,8 @@ TEST_CASES = \
test-0102.sh \
test-0103.sh \
test-0104.sh \
- test-0105.sh
+ test-0105.sh \
+ test-0107.sh
EXTRA_DIST = \
compress \