Sophie

Sophie

distrib > Mandriva > 2009.0 > i586 > by-pkgid > 5872f73fb50a17df836f411b30e6e874 > files > 3

logrotate-3.7.5-9mdv2009.0.src.rpm

diff --git a/logrotate.8 b/logrotate.8
index cd72ecd..9e2a187 100644
--- a/logrotate.8
+++ b/logrotate.8
@@ -326,7 +326,8 @@ overrides the \fBolddir\fR option).
 \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 @@ overriden by the \fBnoolddir\fR option.
 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 @@ The lines between \fBprerotate\fR and \fBendscript\fR (both of which
 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 @@ The lines between \fBfirstaction\fR and \fBendscript\fR (both of which
 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 @@ The lines between \fBlastaction\fR and \fBendscript\fR (both of which
 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 @@ times for log file entries which match multiple files (such as the
 /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
diff --git a/logrotate.c b/logrotate.c
index a0b6873..9f10a10 100644
--- a/logrotate.c
+++ b/logrotate.c
@@ -1043,6 +1043,8 @@ int rotateLogSet(logInfo * log, struct stateSet *sip, int force)
 		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;
 	    }
 	}
     }
@@ -1067,16 +1069,25 @@ int rotateLogSet(logInfo * log, struct stateSet *sip, int force)
 	    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)) {
-		    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,22 +1096,33 @@ int rotateLogSet(logInfo * log, struct stateSet *sip, int force)
 	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];
 	    }
 	}
 
-	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)) {
-		    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 +1131,8 @@ int rotateLogSet(logInfo * log, struct stateSet *sip, int force)
 	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];