From mboxrd@z Thu Jan 1 00:00:00 1970 From: Ian Jackson Subject: [PATCH 01/11] libxl: Make logging functions preserve errno Date: Thu, 25 Mar 2010 19:04:04 +0000 Message-ID: <1269543854-7780-2-git-send-email-ian.jackson@eu.citrix.com> References: <1269543854-7780-1-git-send-email-ian.jackson@eu.citrix.com> Mime-Version: 1.0 Content-Type: text/plain Return-path: In-Reply-To: <1269543854-7780-1-git-send-email-ian.jackson@eu.citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: xen-devel@lists.xensource.com Cc: Ian Jackson , Ian Jackson List-Id: xen-devel@lists.xenproject.org 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 --- tools/libxl/libxl_internal.c | 5 ++++- tools/libxl/libxl_internal.h | 2 ++ 2 files changed, 6 insertions(+), 1 deletions(-) diff --git a/tools/libxl/libxl_internal.c b/tools/libxl/libxl_internal.c index f48e9eb..4dcdabe 100644 --- a/tools/libxl/libxl_internal.c +++ b/tools/libxl/libxl_internal.c @@ -156,11 +156,13 @@ void xl_logv(struct libxl_ctx *ctx, int loglevel, int errnoval, { char *enomem = "[out of memory formatting log message]"; char *s; - int rc; + int rc, esave; if (!ctx->log_callback) return; + esave = errno; + rc = vasprintf(&s, fmt, ap); if (rc<0) { s = enomem; goto x; } @@ -180,6 +182,7 @@ void xl_logv(struct libxl_ctx *ctx, int loglevel, int errnoval, ctx->log_callback(ctx->log_userdata, loglevel, file, line, func, s); if (s != enomem) free(s); + errno = esave; } void xl_log(struct libxl_ctx *ctx, int loglevel, int errnoval, diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h index 300c108..10e72e5 100644 --- a/tools/libxl/libxl_internal.h +++ b/tools/libxl/libxl_internal.h @@ -47,6 +47,7 @@ #define XL_LOG_ERRNO(ctx, loglevel, _f, _a...) #define XL_LOG_ERRNOVAL(ctx, loglevel, errnoval, _f, _a...) #endif + /* all of these macros preserve errno (saving and restoring) */ #define XL_LOG_DEBUG 3 #define XL_LOG_INFO 2 @@ -56,6 +57,7 @@ /* logging */ void xl_logv(struct libxl_ctx *ctx, int errnoval, int loglevel, const char *file, int line, const char *func, char *fmt, va_list al); void xl_log(struct libxl_ctx *ctx, int errnoval, int loglevel, const char *file, int line, const char *func, char *fmt, ...); + /* these functions preserve errno (saving and restoring) */ typedef enum { -- 1.5.6.5