diff --git a/SOURCES/logrotate-3.8.6-config-mode-err.patch b/SOURCES/logrotate-3.8.6-config-mode-err.patch new file mode 100644 index 0000000..ea4d956 --- /dev/null +++ b/SOURCES/logrotate-3.8.6-config-mode-err.patch @@ -0,0 +1,29 @@ +From c8cd3cecb8c8191ba40ec6c6a835f03c5adc5068 Mon Sep 17 00:00:00 2001 +From: jkaluza +Date: Fri, 7 Nov 2014 12:13:12 +0000 +Subject: [PATCH] Better error message when the config file has bad mode + +Upstream-commit: 367640762bef15ac0850113c591e3de7193c1764 +Signed-off-by: Kamil Dudka +--- + config.c | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/config.c b/config.c +index 700ad85..2a610de 100644 +--- a/config.c ++++ b/config.c +@@ -795,8 +795,8 @@ static int readConfigFile(const char *configFile, struct logInfo *defConfig) + + if (getuid() == ROOT_UID) { + if ((sb.st_mode & 07533) != 0400) { +- message(MESS_DEBUG, +- "Ignoring %s because of bad file mode.\n", ++ message(MESS_ERROR, ++ "Ignoring %s because of bad file mode - must be 0644 or 0444.\n", + configFile); + close(fd); + return 0; +-- +2.13.5 + diff --git a/SOURCES/logrotate-3.8.6-copy-and-copytruncate.patch b/SOURCES/logrotate-3.8.6-copy-and-copytruncate.patch new file mode 100644 index 0000000..505a999 --- /dev/null +++ b/SOURCES/logrotate-3.8.6-copy-and-copytruncate.patch @@ -0,0 +1,69 @@ +From ba18db9a3c47f3283bb3493a84946fe27d7b1bc4 Mon Sep 17 00:00:00 2001 +From: Kamil Dudka +Date: Tue, 20 Jun 2017 13:35:37 +0200 +Subject: [PATCH] make 'copy' and 'copytruncate' work together + +This commit fixes a regression introduced +by 3b26f4d8bbb338981aa2796c4076792c63d850c0. + +Upstream-commit: 65faf212e51115699f55f491d464f0ead9c2047e +Signed-off-by: Kamil Dudka +--- + logrotate.c | 5 ++++- + test/test | 13 +++++++++++++ + test/test-config.73.in | 4 ++++ + 3 files changed, 21 insertions(+), 1 deletion(-) + create mode 100644 test/test-config.73.in + +diff --git a/logrotate.c b/logrotate.c +index 20f6ea5..d5da299 100644 +--- a/logrotate.c ++++ b/logrotate.c +@@ -760,7 +760,10 @@ static int copyTruncate(char *currLog, char *saveLog, struct stat *sb, + message(MESS_DEBUG, "copying %s to %s\n", currLog, saveLog); + + if (!debug) { +- if ((fdcurr = open(currLog, ((flags & LOG_FLAG_COPY) ? O_RDONLY : O_RDWR) | O_NOFOLLOW)) < 0) { ++ /* read access is sufficient for 'copy' but not for 'copytruncate' */ ++ const int read_only = (flags & LOG_FLAG_COPY) ++ && !(flags & LOG_FLAG_COPYTRUNCATE); ++ if ((fdcurr = open(currLog, ((read_only) ? O_RDONLY : O_RDWR) | O_NOFOLLOW)) < 0) { + message(MESS_ERROR, "error opening %s: %s\n", currLog, + strerror(errno)); + return 1; +diff --git a/test/test b/test/test +index 54d57d2..bcdfe05 100755 +--- a/test/test ++++ b/test/test +@@ -1586,5 +1586,18 @@ EOF + rm -rf testdir adir + rm -rf testdir bdir + ++cleanup 73 ++ ++# ------------------------------- Test 73 ------------------------------------ ++# make sure that 'copy' and 'copytruncate' work together ++preptest test.log 73 2 ++ ++$RLR test-config.73 --force ++ ++checkoutput < +Date: Tue, 2 Aug 2016 16:54:20 +0200 +Subject: [PATCH] logrotate.8: update references to project page + +Reported-by: Paul Campbell +Bug: https://bugzilla.redhat.com/1357215 + +Upstream-commit: bd0edbb4f820abe424b75c8427a6b2e488265eca +Signed-off-by: Kamil Dudka +--- + logrotate.8 | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/logrotate.8 b/logrotate.8 +index 468ba0e..e48dd0b 100644 +--- a/logrotate.8 ++++ b/logrotate.8 +@@ -549,12 +549,12 @@ Configuration options. + .SH SEE ALSO + .BR gzip (1) + +- ++ + + .SH AUTHORS + .nf + Erik Troan, Preston Brown, Jan Kaluza. + +- ++ + + .fi +-- +2.13.5 + diff --git a/SOURCES/logrotate-3.8.6-weekly.patch b/SOURCES/logrotate-3.8.6-weekly.patch new file mode 100644 index 0000000..c720c89 --- /dev/null +++ b/SOURCES/logrotate-3.8.6-weekly.patch @@ -0,0 +1,162 @@ +From 7cb2dde2b3423158f5cba06df0df078ab3bee09b Mon Sep 17 00:00:00 2001 +From: Kamil Dudka +Date: Wed, 7 Dec 2016 16:34:13 +0100 +Subject: [PATCH] weekly: trigger the rotation more predictably + +... by ignoring the exact time. If the (absolute) day counter +advances by 7+ days since the last rotation, a new rotation is +triggered. + +Additionally, introduce an optional argument of the 'weekly' directive +to trigger the rotation on a selected day of the week. If the argument +is omitted, default to Sunday to preserve backward compatibility. + +Closes #93 + +Upstream-commit: bd2638856dbbb6c0a47beb85fe8a8a628160772e +Signed-off-by: Kamil Dudka +--- + config.c | 19 +++++++++++++++++++ + logrotate.8 | 12 ++++++------ + logrotate.c | 39 +++++++++++++++++++++++++++++---------- + logrotate.h | 3 ++- + 4 files changed, 56 insertions(+), 17 deletions(-) + +diff --git a/config.c b/config.c +index 5e7951e..700ad85 100644 +--- a/config.c ++++ b/config.c +@@ -410,6 +410,7 @@ static void copyLogInfo(struct logInfo *to, struct logInfo *from) + if (from->oldDir) + to->oldDir = strdup(from->oldDir); + to->criterium = from->criterium; ++ to->weekday = from->weekday; + to->threshhold = from->threshhold; + to->minsize = from->minsize; + to->maxsize = from->maxsize; +@@ -1050,7 +1051,25 @@ static int readConfigFile(const char *configFile, struct logInfo *defConfig) + } else if (!strcmp(key, "monthly")) { + newlog->criterium = ROT_MONTHLY; + } else if (!strcmp(key, "weekly")) { ++ unsigned weekday; ++ char tmp; + newlog->criterium = ROT_WEEKLY; ++ free(key); ++ key = isolateLine(&start, &buf, length); ++ if (key == NULL || key[0] == '\0') { ++ /* default to Sunday if no argument was given */ ++ newlog->weekday = 0; ++ continue; ++ } ++ ++ if (1 == sscanf(key, "%u%c", &weekday, &tmp) && weekday <= 7) { ++ /* use the selected weekday, 7 means "once per week" */ ++ newlog->weekday = weekday; ++ continue; ++ } ++ message(MESS_ERROR, "%s:%d bad weekly directive '%s'\n", ++ configFile, lineNum, key); ++ goto error; + } else if (!strcmp(key, "yearly")) { + newlog->criterium = ROT_YEARLY; + } else if (!strcmp(key, "rotate")) { +diff --git a/logrotate.8 b/logrotate.8 +index 2db6f65..468ba0e 100644 +--- a/logrotate.8 ++++ b/logrotate.8 +@@ -526,12 +526,12 @@ is replaced. At startup, the taboo extension list + contains .rpmsave, .rpmorig, ~, .disabled, .dpkg\-old, .dpkg\-dist, .dpkg\-new, .cfsaved, .ucf\-old, .ucf\-dist, .ucf\-new, .rpmnew, .swp, .cfsaved, .rhn\-cfg\-tmp\-* + + .TP +-\fBweekly\fR +-Log files are rotated if the current weekday is less than the weekday +-of the last rotation or if more than a week has passed since the last +-rotation. This is normally the same as rotating logs on the first day +-of the week, but it works better if \fIlogrotate\fR is not run every +-night. ++\fBweekly\fR [\fIweekday\fR] ++Log files are rotated once each \fIweekday\fR, or if the date is advanced by at ++least 7 days since the last rotation (while ignoring the exact time). The ++\fIweekday\fR intepretation is following: 0 means Sunday, 1 means Monday, ..., ++6 means Saturday; the special value 7 means each 7 days, irrespectively of ++weekday. Defaults to 0 if the \fIweekday\fR argument is omitted. + + .TP + \fByearly\fR +diff --git a/logrotate.c b/logrotate.c +index d5da299..e056ccd 100644 +--- a/logrotate.c ++++ b/logrotate.c +@@ -842,6 +842,27 @@ static int copyTruncate(char *currLog, char *saveLog, struct stat *sb, + return 0; + } + ++/* return value similar to mktime() but the exact time is ignored */ ++static time_t mktimeFromDateOnly(const struct tm *src) ++{ ++ /* explicit struct copy to retain C89 compatibility */ ++ struct tm tmp; ++ memcpy(&tmp, src, sizeof tmp); ++ ++ /* abstract out (nullify) fields expressing the exact time */ ++ tmp.tm_hour = 0; ++ tmp.tm_min = 0; ++ tmp.tm_sec = 0; ++ return mktime(&tmp); ++} ++ ++/* return by how many days the date was advanced but ignore exact time */ ++static int daysElapsed(const struct tm *now, const struct tm *last) ++{ ++ const time_t diff = mktimeFromDateOnly(now) - mktimeFromDateOnly(last); ++ return diff / (24 * 3600); ++} ++ + int findNeedRotating(struct logInfo *log, int logNum, int force) + { + struct stat sb; +@@ -924,18 +945,16 @@ int findNeedRotating(struct logInfo *log, int logNum, int force) + state->lastRotated.tm_mon != now.tm_mon || + state->lastRotated.tm_mday != now.tm_mday || + state->lastRotated.tm_hour != now.tm_hour) { ++ int days; + switch (log->criterium) { + case ROT_WEEKLY: +- /* rotate if: +- 1) the current weekday is before the weekday of the +- last rotation +- 2) more then a week has passed since the last +- rotation */ +- state->doRotate = ((now.tm_wday < state->lastRotated.tm_wday) +- || +- ((mktime(&now) - +- mktime(&state->lastRotated)) > +- (7 * 24 * 3600))); ++ days = daysElapsed(&now, &state->lastRotated); ++ /* rotate if date is advanced by 7+ days (exact time is ignored) */ ++ state->doRotate = (days >= 7) ++ /* ... or if we have not yet rotated today */ ++ || (days >= 1 ++ /* ... and the selected weekday is today */ ++ && now.tm_wday == log->weekday); + if (!state->doRotate) { + message(MESS_DEBUG, " log does not need rotating " + "(log has been rotated at %d-%d-%d %d:%d, " +diff --git a/logrotate.h b/logrotate.h +index cf42703..f2d2103 100644 +--- a/logrotate.h ++++ b/logrotate.h +@@ -36,8 +36,9 @@ struct logInfo { + char *oldDir; + enum { ROT_HOURLY, ROT_DAYS, ROT_WEEKLY, ROT_MONTHLY, ROT_YEARLY, ROT_SIZE + } criterium; ++ int weekday; /* used by ROT_WEEKLY only */ + unsigned long long threshhold; +- unsigned long long maxsize; ++ unsigned long long maxsize; + unsigned long long minsize; + int rotateCount; + int rotateAge; +-- +2.13.5 + diff --git a/SPECS/logrotate.spec b/SPECS/logrotate.spec index c66cf89..c22af07 100644 --- a/SPECS/logrotate.spec +++ b/SPECS/logrotate.spec @@ -1,10 +1,10 @@ Summary: Rotates, compresses, removes and mails system log files Name: logrotate Version: 3.8.6 -Release: 14%{?dist} +Release: 15%{?dist} License: GPL+ Group: System Environment/Base -Url: https://fedorahosted.org/logrotate/ +URL: https://github.com/logrotate/logrotate Source: https://fedorahosted.org/releases/l/o/logrotate/logrotate-%{version}.tar.gz Source1: rwtab Patch0: logrotate-3.8.6-force.patch @@ -36,6 +36,18 @@ Patch13: logrotate-3.8.6-selinux.patch # fix #1387533 - make 'su' directive accept usernames starting with digits Patch14: logrotate-3.8.6-su-username.patch +# fix #1461907 - make 'copy' and 'copytruncate' work together +Patch15: logrotate-3.8.6-copy-and-copytruncate.patch + +# fix #1465720 - trigger weekly rotations more predictably +Patch16: logrotate-3.8.6-weekly.patch + +# fix #1472984 - improve the error message for bad config file mode +Patch17: logrotate-3.8.6-config-mode-err.patch + +# fix #1483800 - update references to project page +Patch18: logrotate-3.8.6-upstream-url.patch + Requires: coreutils >= 5.92 popt BuildRequires: libselinux-devel popt-devel libacl-devel acl BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n) @@ -68,6 +80,10 @@ log files on your system. %patch12 -p1 %patch13 -p1 %patch14 -p1 +%patch15 -p1 +%patch16 -p1 +%patch17 -p1 +%patch18 -p1 %build make %{?_smp_mflags} RPM_OPT_FLAGS="$RPM_OPT_FLAGS" WITH_SELINUX=yes WITH_ACL=yes @@ -116,6 +132,12 @@ rm -rf $RPM_BUILD_ROOT %config(noreplace) %{_sysconfdir}/rwtab.d/logrotate %changelog +* Mon Sep 25 2017 Kamil Dudka - 3.8.6-15 +- fix #1483800 - update references to project page +- fix #1472984 - improve the error message for bad config file mode +- fix #1465720 - trigger weekly rotations more predictably +- fix #1461907 - make 'copy' and 'copytruncate' work together + * Tue Jan 24 2017 Kamil Dudka - 3.8.6-14 - fix #1381719 - make /var/lib/logrotate/logrotate.status the default state file - fix #1387533 - make 'su' directive accept usernames starting with digits