On Tue, Mar 24, 2009 at 12:59:42PM +0100, Paul Slootman wrote:
> On Thu 12 Mar 2009, Paul Slootman wrote:
> 
> > It would be great if an environment variable was made available to the
> > postrotate script so that the script can do something relevant to it.
> > Something like LOGROTATED_LOG for example... This would then contain the
> > name of the rotated log (including the .gz if nodelaycompress is in
> > force).
> 
> I've hacked up a patch to do this, see attachment.

How about this as an alternative? (untested)

Your patch doesn't allow for multiple files to be notified to the script.

$1   = pattern
$2.. = rotated files

-- 
Paul Martin <p...@debian.org>
Index: logrotate-3.7.8/logrotate.c
===================================================================
--- logrotate-3.7.8.orig/logrotate.c	2009-03-24 13:25:47.049294317 +0000
+++ logrotate-3.7.8/logrotate.c	2009-03-24 13:43:13.921294228 +0000
@@ -189,6 +189,43 @@
     return rc;
 }
 
+static int runScriptMultiple(char *logfn, char *script, struct logNames *rotNames, int numFiles)
+{
+    int rc,i;
+    char **argv;
+
+    if (debug) {
+	message(MESS_DEBUG, "running script (multiple) with arg %s: \"%s\"\n",
+		logfn, script);
+	return 0;
+    }
+
+    argv = calloc(numFiles+6,sizeof(char*));
+    if (NULL == argv) {
+	message(MESS_ERROR,"error allocating memory to runScriptMultiple\n");
+	return -1;
+    }
+
+    argv[0] = "sh";
+    argv[1] = "-c";
+    argv[2] = script;
+    argv[3] = "logrotate_script";
+    argv[4] = logfn;
+
+    for (i = 0; i<numFiles; i++) {
+	argv[i+5] = rotnames[i]->finalName;
+    }
+    argv[i+5] = NULL;
+
+    if (!fork()) {
+	execv("/bin/sh",argv);
+	exit(1);
+    }
+
+    wait(&rc);
+    return rc;
+}
+
 int createOutputFile(char *fileName, int flags, struct stat *sb)
 {
     int fd;
@@ -1300,7 +1337,7 @@
 			"since no logs will be rotated\n");
 	    } else {
 		message(MESS_DEBUG, "running prerotate script\n");
-		if (runScript(log->pattern, log->pre)) {
+		if (runScriptMultiple(log->pattern, log->pre, rotNames, log->numFiles)) {
 		    if (log->flags & LOG_FLAG_SHAREDSCRIPTS)
 			message(MESS_ERROR,
 				"error running shared prerotate script "
@@ -1335,7 +1372,7 @@
 			"since no logs were rotated\n");
 	    } else {
 		message(MESS_DEBUG, "running postrotate script\n");
-		if (runScript(log->pattern, log->post)) {
+		if (runScriptMultiple(log->pattern, log->post, rotNames, log->numFiles)) {
 		    if (log->flags & LOG_FLAG_SHAREDSCRIPTS)
 			message(MESS_ERROR,
 				"error running shared postrotate script "

Reply via email to