debuggers.hg

changeset 21180:5993c6b9f4e5

libxl: Make logging functions preserve errno

This is needed by the following patches. It makes it much more
convenient for libxl functions to return the errno value from the
failure, when they fail.

Signed-off-by: Ian Jackson <Ian.Jackson@eu.citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Mon Apr 12 17:38:17 2010 +0100 (2010-04-12)
parents 7eeb131880b2
children 37e4d8e11554
files tools/libxl/libxl_internal.c tools/libxl/libxl_internal.h
line diff
     1.1 --- a/tools/libxl/libxl_internal.c	Mon Apr 12 17:36:54 2010 +0100
     1.2 +++ b/tools/libxl/libxl_internal.c	Mon Apr 12 17:38:17 2010 +0100
     1.3 @@ -156,11 +156,13 @@ void xl_logv(struct libxl_ctx *ctx, int 
     1.4  {
     1.5      char *enomem = "[out of memory formatting log message]";
     1.6      char *s;
     1.7 -    int rc;
     1.8 +    int rc, esave;
     1.9  
    1.10      if (!ctx->log_callback)
    1.11          return;
    1.12  
    1.13 +    esave = errno;
    1.14 +    
    1.15      rc = vasprintf(&s, fmt, ap);
    1.16      if (rc<0) { s = enomem; goto x; }
    1.17  
    1.18 @@ -180,6 +182,7 @@ void xl_logv(struct libxl_ctx *ctx, int 
    1.19      ctx->log_callback(ctx->log_userdata, loglevel, file, line, func, s);
    1.20      if (s != enomem)
    1.21          free(s);
    1.22 +    errno = esave;
    1.23  }
    1.24  
    1.25  void xl_log(struct libxl_ctx *ctx, int loglevel, int errnoval,
     2.1 --- a/tools/libxl/libxl_internal.h	Mon Apr 12 17:36:54 2010 +0100
     2.2 +++ b/tools/libxl/libxl_internal.h	Mon Apr 12 17:38:17 2010 +0100
     2.3 @@ -47,6 +47,7 @@
     2.4  #define XL_LOG_ERRNO(ctx, loglevel, _f, _a...)
     2.5  #define XL_LOG_ERRNOVAL(ctx, loglevel, errnoval, _f, _a...)
     2.6  #endif
     2.7 +  /* all of these macros preserve errno (saving and restoring) */
     2.8  
     2.9  #define XL_LOG_DEBUG 3
    2.10  #define XL_LOG_INFO 2
    2.11 @@ -56,6 +57,7 @@
    2.12  /* logging */
    2.13  void xl_logv(struct libxl_ctx *ctx, int errnoval, int loglevel, const char *file, int line, const char *func, char *fmt, va_list al);
    2.14  void xl_log(struct libxl_ctx *ctx, int errnoval, int loglevel, const char *file, int line, const char *func, char *fmt, ...);
    2.15 +  /* these functions preserve errno (saving and restoring) */
    2.16  
    2.17  
    2.18  typedef enum {