[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-changelog] [xen master] libxl: re-implement libxl__xs_printf()
commit a2552ad1b6f0487d96623c85702373d8b410a5ac Author: Paul Durrant <paul.durrant@xxxxxxxxxx> AuthorDate: Tue Dec 1 13:55:25 2015 +0000 Commit: Ian Campbell <ian.campbell@xxxxxxxxxx> CommitDate: Tue Dec 15 12:05:19 2015 +0000 libxl: re-implement libxl__xs_printf() This patch adds a new libxl__xs_vprintf() which actually checks the success of the underlying call to xs_write() (logging if it fails) and then re-implements libxl__xs_printf() using this (and replacing the call to vasprintf() with a call to libxl__vsprintf()). libxl__xs_vprintf() is added to the 'checked' section of libxl_internal.h and, since it now underpins libxl__xs_printf(), that declaration is moved into the same section. Looking at call sites of libxl__xs_printf() it seems as though several of them expected a failure if the underlying xs_write() failed, so this patch should actually fulfil the semantic that was intended all along. Signed-off-by: Paul Durrant <paul.durrant@xxxxxxxxxx> Cc: Ian Jackson <ian.jackson@xxxxxxxxxxxxx> Cc: Stefano Stabellini <stefano.stabellini@xxxxxxxxxxxxx> Cc: Ian Campbell <ian.campbell@xxxxxxxxxx> Cc: Wei Liu <wei.liu2@xxxxxxxxxx> Acked-by: Ian Campbell <ian.campbell@xxxxxxxxxx> --- tools/libxl/libxl_internal.h | 8 +++++--- tools/libxl/libxl_xshelp.c | 32 ++++++++++++++++++++++---------- 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h index 908a6fe..f116779 100644 --- a/tools/libxl/libxl_internal.h +++ b/tools/libxl/libxl_internal.h @@ -666,9 +666,6 @@ _hidden int libxl__xs_writev_perms(libxl__gc *gc, xs_transaction_t t, /* _atonce creates a transaction and writes all keys at once */ _hidden int libxl__xs_writev_atonce(libxl__gc *gc, const char *dir, char **kvs); - -_hidden int libxl__xs_printf(libxl__gc *gc, xs_transaction_t t, - const char *path, const char *fmt, ...) PRINTF_ATTRIBUTE(4, 5); /* Each fn returns 0 on success. * On error: returns -1, sets errno (no logging) */ @@ -688,6 +685,11 @@ _hidden char *libxl__xs_libxl_path(libxl__gc *gc, uint32_t domid); * fails it logs and returns ERROR_FAIL. */ +int libxl__xs_vprintf(libxl__gc *gc, xs_transaction_t t, + const char *path, const char *fmt, va_list ap); +int libxl__xs_printf(libxl__gc *gc, xs_transaction_t t, + const char *path, const char *fmt, ...) PRINTF_ATTRIBUTE(4, 5); + /* On success, path will exist and will have an empty value */ int libxl__xs_mknod(libxl__gc *gc, xs_transaction_t t, const char *path, struct xs_permissions *perms, diff --git a/tools/libxl/libxl_xshelp.c b/tools/libxl/libxl_xshelp.c index 8798cba..e1412a6 100644 --- a/tools/libxl/libxl_xshelp.c +++ b/tools/libxl/libxl_xshelp.c @@ -96,23 +96,35 @@ out: } -int libxl__xs_printf(libxl__gc *gc, xs_transaction_t t, - const char *path, const char *fmt, ...) +int libxl__xs_vprintf(libxl__gc *gc, xs_transaction_t t, + const char *path, const char *fmt, va_list ap) { libxl_ctx *ctx = libxl__gc_owner(gc); char *s; + bool ok; + + s = libxl__vsprintf(gc, fmt, ap); + + ok = xs_write(ctx->xsh, t, path, s, strlen(s)); + if (!ok) { + LOGE(ERROR, "xenstore write failed: `%s' = `%s'", path, s); + return ERROR_FAIL; + } + + return 0; +} + +int libxl__xs_printf(libxl__gc *gc, xs_transaction_t t, + const char *path, const char *fmt, ...) +{ va_list ap; - int ret; + int rc; + va_start(ap, fmt); - ret = vasprintf(&s, fmt, ap); + rc = libxl__xs_vprintf(gc, t, path, fmt, ap); va_end(ap); - if (ret == -1) { - return -1; - } - xs_write(ctx->xsh, t, path, s, ret); - free(s); - return 0; + return rc; } char * libxl__xs_read(libxl__gc *gc, xs_transaction_t t, const char *path) -- generated by git-patchbot for /home/xen/git/xen.git#master _______________________________________________ Xen-changelog mailing list Xen-changelog@xxxxxxxxxxxxx http://lists.xensource.com/xen-changelog
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |