]> granicus.if.org Git - apache/commitdiff
Add -L option to create a hard link to the current log file.
authorDaniel Earl Poirier <poirier@apache.org>
Thu, 25 Feb 2010 18:00:42 +0000 (18:00 +0000)
committerDaniel Earl Poirier <poirier@apache.org>
Thu, 25 Feb 2010 18:00:42 +0000 (18:00 +0000)
PR: 48761
Submitted by: <lindon orthanc.ca>
With additional changes by: poirier

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@916377 13f79535-47bb-0310-9956-ffa450edef68

CHANGES
docs/manual/programs/rotatelogs.xml
support/rotatelogs.c

diff --git a/CHANGES b/CHANGES
index 7a3b3a02f76d5a6a2d97615683151aa070d731ad..d4be4e4bb23a94d690afbf45810def87287b2d06 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -2,6 +2,9 @@
 
 Changes with Apache 2.3.7
 
+  *) support/rotatelogs: Add -L option to create a link to the current
+     log file.  PR 48761 [<lyndon orthanc.ca>, Dan Poirier]
+
   *) mod_ldap: Update LDAPTrustedClientCert to consistently be a per-directory
      setting only, matching most of the documentation and examples. 
      PR 46541 [Paul Reder, Eric Covener] 
index 7c7443a37b5d9254817ca7b0d800a20a299f0060..9d55ec38957c47c406d175b71c399f02eaeca9a7 100644 (file)
@@ -35,6 +35,7 @@
 
      <p><code><strong>rotatelogs</strong>
      [ -<strong>l</strong> ]
+     [ -<strong>L</strong> <var>linkname</var> ]
      [ -<strong>f</strong> ]
      [ -<strong>v</strong> ]
      <var>logfile</var>
@@ -53,6 +54,12 @@ rotation.  Note that using <code>-l</code> in an environment which
 changes the GMT offset (such as for BST or DST) can lead to unpredictable
 results!</dd>
 
+<dt><code>-L</code> <var>linkname</var></dt>
+<dd>Causes a hard link to be made from the current logfile
+to the specified link name.  This can be used to watch
+the log continuously across rotations using a command like 
+<code>tail -F linkname</code>.</dd>
+
 <dt><code>-f</code></dt>
 <dd>Causes the logfile to be opened immediately, as soon as
 <code>rotatelogs</code> starts, instead of waiting for the
index a295ad0a7bcb8f267407eb4e8c1663c31bbeb35f..b011c358f8ca110b6339bff85af7efd6d3173e82 100644 (file)
@@ -89,6 +89,7 @@ struct rotate_config {
     int verbose;
     const char *szLogRoot;
     int truncate;
+    const char *linkfile;
 };
 
 typedef struct rotate_status rotate_status_t;
@@ -115,7 +116,7 @@ static void usage(const char *argv0, const char *reason)
         fprintf(stderr, "%s\n", reason);
     }
     fprintf(stderr,
-            "Usage: %s [-v] [-l] [-f] [-t] <logfile> "
+            "Usage: %s [-v] [-l] [-L linkname] [-f] [-t] <logfile> "
             "{<rotation time in seconds>|<rotation size>(B|K|M|G)} "
             "[offset minutes from UTC]\n\n",
             argv0);
@@ -139,7 +140,9 @@ static void usage(const char *argv0, const char *reason)
             "when the file size\nis reached a new log is started. If the "
             "-t option is specified, the specified\nfile will be truncated "
             "instead of rotated, and is useful where tail is used to\n"
-            "process logs in real time.\n");
+            "process logs in real time.  If the -L option is specified, "
+            "a hard link will be\nmade from the current log file to the "
+            "specified filename.\n");
     exit(1);
 }
 
@@ -351,6 +354,20 @@ static void doRotate(rotate_config_t *config, rotate_status_t *status)
         status->pfile_prev = NULL;
     }
     status->nMessCount = 0;
+    if (config->linkfile) {
+        apr_file_remove(config->linkfile, status->pfile);
+        if (config->verbose) {
+            fprintf(stderr,"Linking %s to %s\n", status->filename, config->linkfile);
+        }
+        rv = apr_file_link(status->filename, config->linkfile);
+        if (rv != APR_SUCCESS) {
+            char error[120];
+            apr_strerror(rv, error, sizeof error);
+            fprintf(stderr, "Error linking file %s to %s (%s)\n",
+                    status->filename, config->linkfile, error);
+            exit(2);
+        }
+    }
 }
 
 /*
@@ -440,11 +457,14 @@ int main (int argc, const char * const argv[])
 
     apr_pool_create(&status.pool, NULL);
     apr_getopt_init(&opt, status.pool, argc, argv);
-    while ((rv = apr_getopt(opt, "lftv", &c, &optarg)) == APR_SUCCESS) {
+    while ((rv = apr_getopt(opt, "lL:ftv", &c, &optarg)) == APR_SUCCESS) {
         switch (c) {
         case 'l':
             config.use_localtime = 1;
             break;
+        case 'L':
+            config.linkfile = optarg;
+            break;
         case 'f':
             config.force_open = 1;
             break;