All of lore.kernel.org
 help / color / mirror / Atom feed
From: Paul Durrant <paul.durrant@citrix.com>
To: xen-devel@lists.xenproject.org
Cc: Paul Durrant <paul.durrant@citrix.com>
Subject: [PATCH v2 2/3] libxl: check for underlying xenstore operation failure...
Date: Mon, 16 Nov 2015 14:00:22 +0000	[thread overview]
Message-ID: <1447682423-1638-3-git-send-email-paul.durrant@citrix.com> (raw)
In-Reply-To: <1447682423-1638-1-git-send-email-paul.durrant@citrix.com>

...in libxl__xs_writev_perms() and libxl__xs_printf()

ERROR_FAIL is returned when any underlying operation fails. This is a
semantic change in the case of a vasprintf() failure in libxl__xs_printf(),
but appears to be better than returning a hardcoded -1.

Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
---
 tools/libxl/libxl_xshelp.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/tools/libxl/libxl_xshelp.c b/tools/libxl/libxl_xshelp.c
index 3cac4f2..a178039 100644
--- a/tools/libxl/libxl_xshelp.c
+++ b/tools/libxl/libxl_xshelp.c
@@ -57,9 +57,11 @@ int libxl__xs_writev_perms(libxl__gc *gc, xs_transaction_t t,
         path = libxl__sprintf(gc, "%s/%s", dir, kvs[i]);
         if (path && kvs[i + 1]) {
             int length = strlen(kvs[i + 1]);
-            xs_write(ctx->xsh, t, path, kvs[i + 1], length);
-            if (perms)
-                xs_set_permissions(ctx->xsh, t, path, perms, num_perms);
+            if (!xs_write(ctx->xsh, t, path, kvs[i + 1], length))
+                return ERROR_FAIL;
+            if (perms &&
+                !xs_set_permissions(ctx->xsh, t, path, perms, num_perms))
+                return ERROR_FAIL;
         }
     }
     return 0;
@@ -108,11 +110,10 @@ int libxl__xs_printf(libxl__gc *gc, xs_transaction_t t,
     va_end(ap);
 
     if (ret == -1) {
-        return -1;
+        return ERROR_FAIL;
     }
-    xs_write(ctx->xsh, t, path, s, ret);
-    free(s);
-    return 0;
+    libxl__ptr_add(gc, s);
+    return xs_write(ctx->xsh, t, path, s, ret) ? 0 : ERROR_FAIL;
 }
 
 char * libxl__xs_read(libxl__gc *gc, xs_transaction_t t, const char *path)
-- 
2.1.4

  parent reply	other threads:[~2015-11-16 14:02 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-16 14:00 [PATCH v2 0/3] libxl: xenstore related cleanup Paul Durrant
2015-11-16 14:00 ` [PATCH v2 1/3] libxl: re-name libxl__xs_write() to libxl__xs_printf() Paul Durrant
2015-11-16 17:15   ` Ian Jackson
2015-11-24 16:22     ` Ian Campbell
2015-11-25 11:27       ` Paul Durrant
2015-11-16 14:00 ` Paul Durrant [this message]
2015-11-24 16:48   ` [PATCH v2 2/3] libxl: check for underlying xenstore operation failure Ian Jackson
2015-11-24 17:24     ` Paul Durrant
2015-11-16 14:00 ` [PATCH v2 3/3] libxl: stop using libxl__xs_mkdir() for ~/control/shutdown Paul Durrant

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1447682423-1638-3-git-send-email-paul.durrant@citrix.com \
    --to=paul.durrant@citrix.com \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.