httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jor...@apache.org
Subject svn commit: r1140099 - in /httpd/httpd/trunk: docs/manual/programs/rotatelogs.xml support/rotatelogs.c
Date Mon, 27 Jun 2011 10:57:10 GMT
Author: jorton
Date: Mon Jun 27 10:57:10 2011
New Revision: 1140099

URL: http://svn.apache.org/viewvc?rev=1140099&view=rev
Log:
Tweak rotatelogs -p such that the program is invoked the first time a
new log file is opened as well as for rotations:

* support/rotatelogs.c (usage): Update.
  (post_rotate): Omit third arg if no prev logfile known.
  (doRotate): Invoke even if no previous logfile was open.


Modified:
    httpd/httpd/trunk/docs/manual/programs/rotatelogs.xml
    httpd/httpd/trunk/support/rotatelogs.c

Modified: httpd/httpd/trunk/docs/manual/programs/rotatelogs.xml
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/docs/manual/programs/rotatelogs.xml?rev=1140099&r1=1140098&r2=1140099&view=diff
==============================================================================
--- httpd/httpd/trunk/docs/manual/programs/rotatelogs.xml (original)
+++ httpd/httpd/trunk/docs/manual/programs/rotatelogs.xml Mon Jun 27 10:57:10 2011
@@ -61,13 +61,16 @@ the log continuously across rotations us
 <code>tail -F linkname</code>.</dd>
 
 <dt><code>-p</code> <var>program</var></dt>
-<dd>Causes the specified program to be executed after each rotation.
-Two arguments are supplied upon execution: the newly opened file and
-the previous file, respectively.  <code>rotatelogs</code> does not
-wait for the specified program to terminate before continuing to
-operate, and will not log any error code returned on termination.  The
-spawned program uses the same stdin, stdout, and stderr as rotatelogs
-itself, and also inherits the environment.</dd>
+
+<dd>If given, <code>rotatelogs</code> will execute the specified
+program every time a new log file is opened.  The filename of the
+newly opened file is passed as the first argument to the program.  If
+executing after a rotation, the old log file is passed as the second
+argument.  <code>rotatelogs</code> does not wait for the specified
+program to terminate before continuing to operate, and will not log
+any error code returned on termination.  The spawned program uses the
+same stdin, stdout, and stderr as rotatelogs itself, and also inherits
+the environment.</dd>
 
 <dt><code>-f</code></dt>
 <dd>Causes the logfile to be opened immediately, as soon as

Modified: httpd/httpd/trunk/support/rotatelogs.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/support/rotatelogs.c?rev=1140099&r1=1140098&r2=1140099&view=diff
==============================================================================
--- httpd/httpd/trunk/support/rotatelogs.c (original)
+++ httpd/httpd/trunk/support/rotatelogs.c Mon Jun 27 10:57:10 2011
@@ -149,16 +149,14 @@ static void usage(const char *argv0, con
             "  -v       Verbose operation. Messages are written to stderr.\n"
             "  -l       Base rotation on local time instead of UTC.\n"
             "  -L path  Create hard link from current log to specified path.\n"
-            "  -p prog  Run specified program on log rotation. See below.\n"
+            "  -p prog  Run specified program after opening a new log file. See below.\n"
             "  -f       Force opening of log on program start.\n"
             "  -t       Truncate logfile instead of rotating, tail friendly.\n"
             "  -e       Echo log to stdout for further processing.\n"
             "\n"
-            "The post-rotation program must be an executable program or script.\n"
-            "Scripts are supported as long as the shebang line uses a working\n"
-            "interpreter. The program is invoked as \"[prog] <curfile> <prevfile>\"\n"
-            "where <curfile> is the filename of the currently used logfile, and\n"
-            "<prevfile> is the filename of the previously used logfile.\n"
+            "The program is invoked as \"[prog] <curfile> [<prevfile>]\"\n"
+            "where <curfile> is the filename of the newly opened logfile, and\n"
+            "<prevfile>, if given, is the filename of the previously used logfile.\n"
             "\n");
     exit(1);
 }
@@ -313,8 +311,13 @@ static void post_rotate(apr_pool_t *pool
 
     argv[0] = config->postrotate_prog;
     argv[1] = status->filename;
-    argv[2] = status->filenameprev;
-    argv[3] = NULL;
+    if (status->filenameprev[0]) {
+        argv[2] = status->filenameprev;
+        argv[3] = NULL;
+    }
+    else {
+        argv[2] = NULL;
+    }
 
     if (config->verbose)
         fprintf(stderr, "Calling post-rotate program: %s\n", argv[0]);
@@ -426,9 +429,8 @@ static void doRotate(rotate_config_t *co
         }
     }
     else {
-        /* If postrotate configured, and this is a real rotate rather
-         * than an initial open, run the post-rotate program: */
-        if (config->postrotate_prog && status->pfile_prev) {
+        /* If postrotate configured, run the post-rotate program: */
+        if (config->postrotate_prog) {
             post_rotate(status->pfile, config, status);
         }
 



Mime
View raw message