add error checking before running prerotate and postrotate scripts

This commit is contained in:
Peter Vrabec 2007-03-31 10:56:49 +00:00
parent 66263396dd
commit d39149986b
2 changed files with 29 additions and 7 deletions

View File

@ -1,5 +1,5 @@
--- logrotate-3.7.5/logrotate.c.errorHandling 2007-03-01 12:05:30.000000000 +0100 --- 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 +++ logrotate-3.7.5/logrotate.c 2007-03-31 12:50:33.000000000 +0200
@@ -1043,6 +1043,8 @@ @@ -1043,6 +1043,8 @@
message(MESS_ERROR, "error running first action script " message(MESS_ERROR, "error running first action script "
"for %s\n", log->pattern); "for %s\n", log->pattern);
@ -9,7 +9,17 @@
} }
} }
} }
@@ -1074,9 +1076,16 @@ @@ -1067,16 +1069,25 @@
hasErrors |= logHasErrors[i];
}
- if (log->pre) {
+ if (log->pre
+ && (! ( (logHasErrors[j] && !(log->flags & LOG_FLAG_SHAREDSCRIPTS))
+ || (hasErrors && (log->flags & LOG_FLAG_SHAREDSCRIPTS)) ) )) {
if (!numRotated) {
message(MESS_DEBUG, "not running prerotate script, "
"since no logs will be rotated\n");
} else { } else {
message(MESS_DEBUG, "running prerotate script\n"); message(MESS_DEBUG, "running prerotate script\n");
if (runScript(log->pattern, log->pre)) { if (runScript(log->pattern, log->pre)) {
@ -29,7 +39,7 @@
hasErrors = 1; hasErrors = 1;
} }
} }
@@ -1085,7 +1094,8 @@ @@ -1085,22 +1096,33 @@
for (i = j; for (i = j;
((log->flags & LOG_FLAG_SHAREDSCRIPTS) && i < log->numFiles) ((log->flags & LOG_FLAG_SHAREDSCRIPTS) && i < log->numFiles)
|| (!(log->flags & LOG_FLAG_SHAREDSCRIPTS) && i == j); i++) { || (!(log->flags & LOG_FLAG_SHAREDSCRIPTS) && i == j); i++) {
@ -39,7 +49,16 @@
logHasErrors[i] |= logHasErrors[i] |=
rotateSingleLog(log, i, state[i], rotNames[i]); rotateSingleLog(log, i, state[i], rotNames[i]);
hasErrors |= logHasErrors[i]; hasErrors |= logHasErrors[i];
@@ -1099,8 +1109,16 @@ }
}
- if (log->post) {
+ if (log->post
+ && (! ( (logHasErrors[j] && !(log->flags & LOG_FLAG_SHAREDSCRIPTS))
+ || (hasErrors && (log->flags & LOG_FLAG_SHAREDSCRIPTS)) ) )) {
if (!numRotated) {
message(MESS_DEBUG, "not running postrotate script, "
"since no logs were rotated\n");
} else { } else {
message(MESS_DEBUG, "running postrotate script\n"); message(MESS_DEBUG, "running postrotate script\n");
if (runScript(log->pattern, log->post)) { if (runScript(log->pattern, log->post)) {
@ -58,7 +77,7 @@
hasErrors = 1; hasErrors = 1;
} }
} }
@@ -1109,7 +1127,8 @@ @@ -1109,7 +1131,8 @@
for (i = j; for (i = j;
((log->flags & LOG_FLAG_SHAREDSCRIPTS) && i < log->numFiles) ((log->flags & LOG_FLAG_SHAREDSCRIPTS) && i < log->numFiles)
|| (!(log->flags & LOG_FLAG_SHAREDSCRIPTS) && i == j); i++) { || (!(log->flags & LOG_FLAG_SHAREDSCRIPTS) && i == j); i++) {
@ -69,7 +88,7 @@
postrotateSingleLog(log, i, state[i], rotNames[i]); postrotateSingleLog(log, i, state[i], rotNames[i]);
hasErrors |= logHasErrors[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.errorHandling 2006-05-17 16:46:51.000000000 +0200
+++ logrotate-3.7.5/logrotate.8 2007-03-29 15:53:53.000000000 +0200 +++ logrotate-3.7.5/logrotate.8 2007-03-31 12:37:06.000000000 +0200
@@ -326,7 +326,8 @@ @@ -326,7 +326,8 @@
\fBnosharedscripts\fR \fBnosharedscripts\fR
Run \fBprerotate\fR and \fBpostrotate\fR scripts for every log file which Run \fBprerotate\fR and \fBpostrotate\fR scripts for every log file which

View File

@ -1,7 +1,7 @@
Summary: Rotates, compresses, removes and mails system log files Summary: Rotates, compresses, removes and mails system log files
Name: logrotate Name: logrotate
Version: 3.7.5 Version: 3.7.5
Release: 2%{?dist} Release: 3%{?dist}
License: GPL License: GPL
Group: System Environment/Base Group: System Environment/Base
# The source for this package was pulled from cvs. # The source for this package was pulled from cvs.
@ -59,6 +59,9 @@ rm -rf $RPM_BUILD_ROOT
%attr(0644, root, root) %verify(not size md5 mtime) %config(noreplace) %{_localstatedir}/lib/logrotate.status %attr(0644, root, root) %verify(not size md5 mtime) %config(noreplace) %{_localstatedir}/lib/logrotate.status
%changelog %changelog
* Sat Mar 31 2007 Peter Vrabec <pvrabec@redhat.com> 3.7.5-3
- add error checking before running prerotate and postrotate scripts
* Thu Mar 29 2007 Peter Vrabec <pvrabec@redhat.com> 3.7.5-2 * Thu Mar 29 2007 Peter Vrabec <pvrabec@redhat.com> 3.7.5-2
- fix error hadnling after prerotate, postrotate, firstaction - fix error hadnling after prerotate, postrotate, firstaction
script failure. (http://qa.mandriva.com/show_bug.cgi?id=29979) script failure. (http://qa.mandriva.com/show_bug.cgi?id=29979)