debuggers.hg

changeset 21181:37e4d8e11554

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@eu.citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Mon Apr 12 17:38:42 2010 +0100 (2010-04-12)
parents 5993c6b9f4e5
children df34011884a3
files tools/libxl/libxl_utils.c
line diff
     1.1 --- a/tools/libxl/libxl_utils.c	Mon Apr 12 17:38:17 2010 +0100
     1.2 +++ b/tools/libxl/libxl_utils.c	Mon Apr 12 17:38:42 2010 +0100
     1.3 @@ -101,11 +101,25 @@ int libxl_is_stubdom(struct libxl_ctx *c
     1.4      return 1;
     1.5  }
     1.6  
     1.7 +static int logrename(struct libxl_ctx *ctx, const char *old, const char *new) {
     1.8 +    int r;
     1.9 +
    1.10 +    r = rename(old, new);
    1.11 +    if (r) {
    1.12 +        if (errno == ENOENT) return 0; /* ok */
    1.13 +
    1.14 +        XL_LOG_ERRNO(ctx, XL_LOG_ERROR, "failed to rotate logfile - could not"
    1.15 +                     " rename %s to %s", old, new);
    1.16 +        return ERROR_FAIL;
    1.17 +    }
    1.18 +    return 0;
    1.19 +}
    1.20 +
    1.21  int libxl_create_logfile(struct libxl_ctx *ctx, char *name, char **full_name)
    1.22  {
    1.23      struct stat stat_buf;
    1.24      char *logfile, *logfile_new;
    1.25 -    int i;
    1.26 +    int i, rc;
    1.27  
    1.28      logfile = libxl_sprintf(ctx, "/var/log/xen/%s.log", name);
    1.29      if (stat(logfile, &stat_buf) == 0) {
    1.30 @@ -115,11 +129,19 @@ int libxl_create_logfile(struct libxl_ct
    1.31          for (i = 9; i > 0; i--) {
    1.32              logfile = libxl_sprintf(ctx, "/var/log/xen/%s.log.%d", name, i);
    1.33              logfile_new = libxl_sprintf(ctx, "/var/log/xen/%s.log.%d", name, i + 1);
    1.34 -            rename(logfile, logfile_new);
    1.35 +            rc = logrename(ctx, logfile, logfile_new);
    1.36 +            if (rc) return rc;
    1.37          }
    1.38          logfile = libxl_sprintf(ctx, "/var/log/xen/%s.log", name);
    1.39          logfile_new = libxl_sprintf(ctx, "/var/log/xen/%s.log.1", name);
    1.40 -        rename(logfile, logfile_new);
    1.41 +
    1.42 +        rc = logrename(ctx, logfile, logfile_new);
    1.43 +        if (rc) return rc;
    1.44 +    } else {
    1.45 +        if (errno != ENOENT)
    1.46 +            XL_LOG_ERRNO(ctx, XL_LOG_WARNING, "problem checking existence of"
    1.47 +                         " logfile %s, which might have needed to be rotated",
    1.48 +                         name);
    1.49      }
    1.50      *full_name = strdup(logfile);
    1.51      return 0;