WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-changelog

[Xen-changelog] [xen-unstable] libxl: Report error if logfile rotation f

To: xen-changelog@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-changelog] [xen-unstable] libxl: Report error if logfile rotation fails
From: Xen patchbot-unstable <patchbot-unstable@xxxxxxxxxxxxxxxxxxx>
Date: Tue, 13 Apr 2010 14:55:20 -0700
Delivery-date: Tue, 13 Apr 2010 14:59:53 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-changelog-request@lists.xensource.com?subject=help>
List-id: BK change log <xen-changelog.lists.xensource.com>
List-post: <mailto:xen-changelog@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=unsubscribe>
Reply-to: xen-devel@xxxxxxxxxxxxxxxxxxx
Sender: xen-changelog-bounces@xxxxxxxxxxxxxxxxxxx
# HG changeset patch
# User Keir Fraser <keir.fraser@xxxxxxxxxx>
# Date 1271090322 -3600
# Node ID 37e4d8e11554404b674fede858668f7bf8d1410b
# Parent  5993c6b9f4e5a2431e0ae7590aef9884a9387382
libxl: Report error if logfile rotation fails

Check the return values from renames and errors from stat in
libxl_create_logfile (which, misleadingly, does not actually create
the logfile).

Signed-off-by: Ian Jackson <Ian.Jackson@xxxxxxxxxxxxx>
---
 tools/libxl/libxl_utils.c |   28 +++++++++++++++++++++++++---
 1 files changed, 25 insertions(+), 3 deletions(-)

diff -r 5993c6b9f4e5 -r 37e4d8e11554 tools/libxl/libxl_utils.c
--- a/tools/libxl/libxl_utils.c Mon Apr 12 17:38:17 2010 +0100
+++ b/tools/libxl/libxl_utils.c Mon Apr 12 17:38:42 2010 +0100
@@ -101,11 +101,25 @@ int libxl_is_stubdom(struct libxl_ctx *c
     return 1;
 }
 
+static int logrename(struct libxl_ctx *ctx, const char *old, const char *new) {
+    int r;
+
+    r = rename(old, new);
+    if (r) {
+        if (errno == ENOENT) return 0; /* ok */
+
+        XL_LOG_ERRNO(ctx, XL_LOG_ERROR, "failed to rotate logfile - could not"
+                     " rename %s to %s", old, new);
+        return ERROR_FAIL;
+    }
+    return 0;
+}
+
 int libxl_create_logfile(struct libxl_ctx *ctx, char *name, char **full_name)
 {
     struct stat stat_buf;
     char *logfile, *logfile_new;
-    int i;
+    int i, rc;
 
     logfile = libxl_sprintf(ctx, "/var/log/xen/%s.log", name);
     if (stat(logfile, &stat_buf) == 0) {
@@ -115,11 +129,19 @@ int libxl_create_logfile(struct libxl_ct
         for (i = 9; i > 0; i--) {
             logfile = libxl_sprintf(ctx, "/var/log/xen/%s.log.%d", name, i);
             logfile_new = libxl_sprintf(ctx, "/var/log/xen/%s.log.%d", name, i 
+ 1);
-            rename(logfile, logfile_new);
+            rc = logrename(ctx, logfile, logfile_new);
+            if (rc) return rc;
         }
         logfile = libxl_sprintf(ctx, "/var/log/xen/%s.log", name);
         logfile_new = libxl_sprintf(ctx, "/var/log/xen/%s.log.1", name);
-        rename(logfile, logfile_new);
+
+        rc = logrename(ctx, logfile, logfile_new);
+        if (rc) return rc;
+    } else {
+        if (errno != ENOENT)
+            XL_LOG_ERRNO(ctx, XL_LOG_WARNING, "problem checking existence of"
+                         " logfile %s, which might have needed to be rotated",
+                         name);
     }
     *full_name = strdup(logfile);
     return 0;

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog

<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-changelog] [xen-unstable] libxl: Report error if logfile rotation fails, Xen patchbot-unstable <=