From d39149986b9e03a718d72a279067f3fdc4f64c7a Mon Sep 17 00:00:00 2001 From: Peter Vrabec Date: Sat, 31 Mar 2007 10:56:49 +0000 Subject: [PATCH] add error checking before running prerotate and postrotate scripts --- logrotate-3.7.5-errorHandling.patch | 31 +++++++++++++++++++++++------ logrotate.spec | 5 ++++- 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/logrotate-3.7.5-errorHandling.patch b/logrotate-3.7.5-errorHandling.patch index 06027d0..cf1d413 100644 --- a/logrotate-3.7.5-errorHandling.patch +++ b/logrotate-3.7.5-errorHandling.patch @@ -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 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 @@ message(MESS_ERROR, "error running first action script " "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 { message(MESS_DEBUG, "running prerotate script\n"); if (runScript(log->pattern, log->pre)) { @@ -29,7 +39,7 @@ hasErrors = 1; } } -@@ -1085,7 +1094,8 @@ +@@ -1085,22 +1096,33 @@ for (i = j; ((log->flags & LOG_FLAG_SHAREDSCRIPTS) && i < log->numFiles) || (!(log->flags & LOG_FLAG_SHAREDSCRIPTS) && i == j); i++) { @@ -39,7 +49,16 @@ logHasErrors[i] |= rotateSingleLog(log, i, state[i], rotNames[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 { message(MESS_DEBUG, "running postrotate script\n"); if (runScript(log->pattern, log->post)) { @@ -58,7 +77,7 @@ hasErrors = 1; } } -@@ -1109,7 +1127,8 @@ +@@ -1109,7 +1131,8 @@ for (i = j; ((log->flags & LOG_FLAG_SHAREDSCRIPTS) && i < log->numFiles) || (!(log->flags & LOG_FLAG_SHAREDSCRIPTS) && i == j); i++) { @@ -69,7 +88,7 @@ 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 ++++ logrotate-3.7.5/logrotate.8 2007-03-31 12:37:06.000000000 +0200 @@ -326,7 +326,8 @@ \fBnosharedscripts\fR Run \fBprerotate\fR and \fBpostrotate\fR scripts for every log file which diff --git a/logrotate.spec b/logrotate.spec index c6de4b5..36be7a0 100644 --- a/logrotate.spec +++ b/logrotate.spec @@ -1,7 +1,7 @@ Summary: Rotates, compresses, removes and mails system log files Name: logrotate Version: 3.7.5 -Release: 2%{?dist} +Release: 3%{?dist} License: GPL Group: System Environment/Base # 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 %changelog +* Sat Mar 31 2007 Peter Vrabec 3.7.5-3 +- add error checking before running prerotate and postrotate scripts + * Thu Mar 29 2007 Peter Vrabec 3.7.5-2 - fix error hadnling after prerotate, postrotate, firstaction script failure. (http://qa.mandriva.com/show_bug.cgi?id=29979)