tag 519432 +patch
thanks

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.


Paul
put name of rotated logfile into environment.
closes: #519432

Index: logrotate-3.7.7/logrotate.c
===================================================================
--- logrotate-3.7.7/logrotate.c.orig
+++ logrotate-3.7.7/logrotate.c
@@ -1275,6 +1275,14 @@
 		message(MESS_DEBUG, "not running postrotate script, "
 			"since no logs were rotated\n");
 	    } else {
+                static char *env_LOGROTATED_FILE = NULL;
+                char *p = rotNames[j]->finalName ? rotNames[j]->finalName : "";
+                int len = strlen("LOGROTATED_FILE=x") + strlen(p); /* the x accounts for the null byte */
+                if (env_LOGROTATED_FILE == NULL || strlen(env_LOGROTATED_FILE) + 1 != len) {
+                        env_LOGROTATED_FILE = realloc(env_LOGROTATED_FILE, len);
+                }
+                sprintf(env_LOGROTATED_FILE, "LOGROTATED_FILE=%s", p);
+                putenv(env_LOGROTATED_FILE);
 		message(MESS_DEBUG, "running postrotate script\n");
 		if (runScript(log->pattern, log->post)) {
 		    if (log->flags & LOG_FLAG_SHAREDSCRIPTS)
@@ -1289,6 +1297,7 @@
 		    logHasErrors[j] = 1;
 		    hasErrors = 1;
 		}
+                putenv("LOGROTATED_FILE"); /* remove from environment */
 	    }
 	}
 

Reply via email to