[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [PATCH v1 2/2] 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>
---
 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 12b2b30..e5000cf 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 be empty */
 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 912a1f2..930b458 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)
-- 
2.1.4


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.