- fix error hadnling after prerotate, postrotate, firstaction script

failure. (http://qa.mandriva.com/show_bug.cgi?id=29979)
This commit is contained in:
Peter Vrabec 2007-03-29 14:07:49 +00:00
parent 42cc6b26d0
commit 66263396dd
2 changed files with 143 additions and 1 deletions

View File

@ -0,0 +1,136 @@
--- logrotate-3.7.5/logrotate.c.errorHandling 2007-03-01 12:05:30.000000000 +0100
+++ logrotate-3.7.5/logrotate.c 2007-03-29 15:55:48.000000000 +0200
@@ -1043,6 +1043,8 @@
message(MESS_ERROR, "error running first action script "
"for %s\n", log->pattern);
hasErrors = 1;
+ /* finish early, firstaction failed, affects all logs in set */
+ return hasErrors;
}
}
}
@@ -1074,9 +1076,16 @@
} else {
message(MESS_DEBUG, "running prerotate script\n");
if (runScript(log->pattern, log->pre)) {
- message(MESS_ERROR,
- "error running shared prerotate script "
- "for %s\n", log->pattern);
+ if (log->flags & LOG_FLAG_SHAREDSCRIPTS)
+ message(MESS_ERROR,
+ "error running shared prerotate script "
+ "for '%s'\n", log->pattern);
+ else {
+ message(MESS_ERROR,
+ "error running non-shared prerotate script "
+ "for %s of '%s'\n", log->files[j], log->pattern);
+ }
+ logHasErrors[j] = 1;
hasErrors = 1;
}
}
@@ -1085,7 +1094,8 @@
for (i = j;
((log->flags & LOG_FLAG_SHAREDSCRIPTS) && i < log->numFiles)
|| (!(log->flags & LOG_FLAG_SHAREDSCRIPTS) && i == j); i++) {
- if (!logHasErrors[i]) {
+ if (! ( (logHasErrors[i] && !(log->flags & LOG_FLAG_SHAREDSCRIPTS))
+ || (hasErrors && (log->flags & LOG_FLAG_SHAREDSCRIPTS)) ) ) {
logHasErrors[i] |=
rotateSingleLog(log, i, state[i], rotNames[i]);
hasErrors |= logHasErrors[i];
@@ -1099,8 +1109,16 @@
} else {
message(MESS_DEBUG, "running postrotate script\n");
if (runScript(log->pattern, log->post)) {
- message(MESS_ERROR, "error running postrotate script "
- "for %s\n", log->pattern);
+ if (log->flags & LOG_FLAG_SHAREDSCRIPTS)
+ message(MESS_ERROR,
+ "error running shared postrotate script "
+ "for '%s'\n", log->pattern);
+ else {
+ message(MESS_ERROR,
+ "error running non-shared postrotate script "
+ "for %s of '%s'\n", log->files[j], log->pattern);
+ }
+ logHasErrors[j] = 1;
hasErrors = 1;
}
}
@@ -1109,7 +1127,8 @@
for (i = j;
((log->flags & LOG_FLAG_SHAREDSCRIPTS) && i < log->numFiles)
|| (!(log->flags & LOG_FLAG_SHAREDSCRIPTS) && i == j); i++) {
- if (!logHasErrors[i]) {
+ if (! ( (logHasErrors[i] && !(log->flags & LOG_FLAG_SHAREDSCRIPTS))
+ || (hasErrors && (log->flags & LOG_FLAG_SHAREDSCRIPTS)) ) ) {
logHasErrors[i] |=
postrotateSingleLog(log, i, state[i], rotNames[i]);
hasErrors |= logHasErrors[i];
--- logrotate-3.7.5/logrotate.8.errorHandling 2006-05-17 16:46:51.000000000 +0200
+++ logrotate-3.7.5/logrotate.8 2007-03-29 15:53:53.000000000 +0200
@@ -326,7 +326,8 @@
\fBnosharedscripts\fR
Run \fBprerotate\fR and \fBpostrotate\fR scripts for every log file which
is rotated (this is the default, and overrides the \fBsharedscripts\fR
-option).
+option). If the scripts exit with error, the remaining actions will
+not be executed for the affected log only.
.TP
\fBnotifempty\fR
@@ -346,7 +347,8 @@
The lines between \fBpostrotate\fR and \fBendscript\fR (both of which
must appear on lines by themselves) are executed after the log file is
rotated. These directives may only appear inside of a log file definition.
-See \fBprerotate\fR as well.
+See \fBprerotate\fR as well. See \fBsharedscripts\fR and
+\fBnosharedscripts\fR for error handling.
.TP
\fBprerotate\fR/\fBendscript\fR
@@ -354,7 +356,8 @@
must appear on lines by themselves) are executed before the log file is
rotated and only if the log will actually be rotated. These directives
may only appear inside of a log file definition. See \fBpostrotate\fR
-as well.
+as well. See \fBsharedscripts\fR and \fBnosharedscripts\fR for error
+handling.
.TP
\fBfirstaction\fR/\fBendscript\fR
@@ -362,7 +365,8 @@
must appear on lines by themselves) are executed once before all log
files that match the wildcarded pattern are rotated, before prerotate script
is run and only if at least one log will actually be rotated. These directives
-may only appear inside of a log file definition. See \fBlastaction\fR as well.
+may only appear inside of a log file definition. If the script exits
+with error, no further processing is done. See \fBlastaction\fR as well.
.TP
\fBlastaction\fR/\fBendscript\fR
@@ -370,7 +374,9 @@
must appear on lines by themselves) are executed once after all log
files that match the wildcarded pattern are rotated, after postrotate script
is run and only if at least one log is rotated. These directives may only
-appear inside of a log file definition. See \fBfirstaction\fR as well.
+appear inside of a log file definition. If the script exits with
+error, just an error message is shown (as this is the last
+action). See \fBfirstaction\fR as well.
.TP
\fBrotate \fIcount\fR
@@ -393,8 +399,10 @@
/var/log/news/* example). If \fBsharedscript\fR is specified, the scripts
are only run once, no matter how many logs match the wildcarded pattern.
However, if none of the logs in the pattern require rotating, the scripts
-will not be run at all. This option overrides the \fBnosharedscripts\fR
-option and implies \fBcreate\fR option.
+will not be run at all. If the scripts exit with error, the remaining
+actions will not be executed for any logs. This option overrides the
+\fBnosharedscripts\fR option and implies \fBcreate\fR option.
+
.TP
\fBstart \fIcount\fR

View File

@ -1,7 +1,7 @@
Summary: Rotates, compresses, removes and mails system log files
Name: logrotate
Version: 3.7.5
Release: 1%{?dist}
Release: 2%{?dist}
License: GPL
Group: System Environment/Base
# The source for this package was pulled from cvs.
@ -12,6 +12,7 @@ Group: System Environment/Base
# cd logrotate
# make create-archive
Source: logrotate-%{version}.tar.gz
Patch1: logrotate-3.7.5-errorHandling.patch
BuildRequires: libselinux-devel
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
@ -28,6 +29,7 @@ log files on your system.
%prep
%setup -q
%patch1 -p1 -b .errorHandling
%build
make %{?_smp_mflags} RPM_OPT_FLAGS="$RPM_OPT_FLAGS" WITH_SELINUX=yes
@ -57,6 +59,10 @@ rm -rf $RPM_BUILD_ROOT
%attr(0644, root, root) %verify(not size md5 mtime) %config(noreplace) %{_localstatedir}/lib/logrotate.status
%changelog
* Thu Mar 29 2007 Peter Vrabec <pvrabec@redhat.com> 3.7.5-2
- fix error hadnling after prerotate, postrotate, firstaction
script failure. (http://qa.mandriva.com/show_bug.cgi?id=29979)
* Thu Mar 01 2007 Peter Vrabec <pvrabec@redhat.com> 3.7.5-1
- new upstream release.