WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-changelog

[Xen-changelog] Fix transaction EAGAIN handling in xenstore client progr

To: xen-changelog@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-changelog] Fix transaction EAGAIN handling in xenstore client programs.
From: Xen patchbot -unstable <patchbot-unstable@xxxxxxxxxxxxxxxxxxx>
Date: Wed, 19 Oct 2005 12:08:16 +0000
Delivery-date: Wed, 19 Oct 2005 12:06:26 +0000
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-changelog-request@lists.xensource.com?subject=help>
List-id: BK change log <xen-changelog.lists.xensource.com>
List-post: <mailto:xen-changelog@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=unsubscribe>
Reply-to: xen-devel@xxxxxxxxxxxxxxxxxxx
Sender: xen-changelog-bounces@xxxxxxxxxxxxxxxxxxx
# HG changeset patch
# User cl349@xxxxxxxxxxxxxxxxxxxx
# Node ID 2b95dde7285337e782db44aa28dfc0edddc70f6d
# Parent  1d88f303c39c6a476ea83c8810b790713615bfb7
Fix transaction EAGAIN handling in xenstore client programs.
Redirect all output to a buffer and only print the buffer once the
transaction succeeds, discarding output from previous attempts.
In particular, fixes failures when the (block) backend driver would
not configure because reads from the hotplug script did get double
output when a transaction had to be redone.
Signed-off-by: Christian Limpach <Christian.Limpach@xxxxxxxxxxxx>

diff -r 1d88f303c39c -r 2b95dde72853 tools/xenstore/xenstore_client.c
--- a/tools/xenstore/xenstore_client.c  Mon Oct 17 19:34:10 2005
+++ b/tools/xenstore/xenstore_client.c  Tue Oct 18 01:08:26 2005
@@ -9,13 +9,45 @@
  */
 
 #include <err.h>
+#include <errno.h>
 #include <fcntl.h>
 #include <getopt.h>
+#include <stdarg.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <xs.h>
-#include <errno.h>
+
+static char *output_buf = NULL;
+static int output_pos = 0;
+
+#if defined(CLIENT_read) || defined(CLIENT_list)
+static int output_size = 0;
+
+static void
+output(const char *fmt, ...) {
+    va_list ap;
+    int len;
+    char buf[1];
+
+    va_start(ap, fmt);
+    len = vsnprintf(buf, 1, fmt, ap);
+    if (len < 0)
+       err(1, "output");
+    va_end(ap);
+    if (len + 1 + output_pos > output_size) {
+       output_size += len + 1024;
+       output_buf = realloc(output_buf, output_size);
+       if (output_buf == NULL)
+           err(1, "malloc");
+    }
+    va_start(ap, fmt);
+    if (vsnprintf(&output_buf[output_pos], len + 1, fmt, ap) != len)
+       err(1, "output");
+    va_end(ap);
+    output_pos += len;
+}
+#endif
 
 static void
 usage(const char *progname)
@@ -34,7 +66,7 @@
 
 #if defined(CLIENT_rm)
 static int
-do_rm(char * path, struct xs_handle *xsh, struct xs_transaction_handle *xth)
+do_rm(char *path, struct xs_handle *xsh, struct xs_transaction_handle *xth)
 {
     if (xs_rm(xsh, xth, path)) {
         return 0;
@@ -59,8 +91,8 @@
            return 1;
        }
        if (prefix)
-           printf("%s: ", argv[optind]);
-       printf("%s\n", val);
+           output("%s: ", argv[optind]);
+       output("%s\n", val);
        free(val);
        optind++;
 #elif defined(CLIENT_write)
@@ -131,8 +163,8 @@
        }
        for (i = 0; i < num; i++) {
            if (prefix)
-               printf("%s/", argv[optind]);
-           printf("%s\n", list[i]);
+               output("%s/", argv[optind]);
+           output("%s\n", list[i]);
        }
        free(list);
        optind++;
@@ -217,9 +249,15 @@
     ret = perform(optind, argc, argv, xsh, xth, prefix, tidy);
 
     if (!xs_transaction_end(xsh, xth, ret)) {
-       if (ret == 0 && errno == EAGAIN)
+       if (ret == 0 && errno == EAGAIN) {
+           output_pos = 0;
            goto again;
+       }
        errx(1, "couldn't end transaction");
     }
+
+    if (output_pos)
+       printf("%s", output_buf);
+
     return ret;
 }

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog

<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-changelog] Fix transaction EAGAIN handling in xenstore client programs., Xen patchbot -unstable <=