tools/libxl: libxl_device_generic_add: handle NULL fents or bents
authorStefano Stabellini <stefano.stabellini@eu.citrix.com>
Fri, 13 Aug 2010 19:34:09 +0000 (20:34 +0100)
committerStefano Stabellini <stefano.stabellini@eu.citrix.com>
Fri, 13 Aug 2010 19:34:09 +0000 (20:34 +0100)
This is going to be used by libxl_console_add in the next patch to
avoid creating the device/console path on xenstore for console 0.

Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Signed-off-by: Ian Jackson <ian.jackson@eu.citrix.com>
tools/libxl/libxl_device.c
tools/libxl/libxl_xshelp.c

index 905fe58c05b135851993a85cc6d3e3cd3c9b38ae..58cff09fc9a1fbe9626192eeb42d18981c24c80f 100644 (file)
@@ -76,21 +76,21 @@ retry_transaction:
     t = xs_transaction_start(ctx->xsh);
     /* FIXME: read frontend_path and check state before removing stuff */
 
-    xs_rm(ctx->xsh, t, frontend_path);
-    xs_rm(ctx->xsh, t, backend_path);
-
-    xs_mkdir(ctx->xsh, t, frontend_path);
-    xs_set_permissions(ctx->xsh, t, frontend_path, frontend_perms, ARRAY_SIZE(frontend_perms));
-
-    xs_mkdir(ctx->xsh, t, backend_path);
-    xs_set_permissions(ctx->xsh, t, backend_path, backend_perms, ARRAY_SIZE(backend_perms));
-
-    xs_write(ctx->xsh, t, libxl_sprintf(&gc, "%s/backend", frontend_path), backend_path, strlen(backend_path));
-    xs_write(ctx->xsh, t, libxl_sprintf(&gc, "%s/frontend", backend_path), frontend_path, strlen(frontend_path));
+    if (fents) {
+        xs_rm(ctx->xsh, t, frontend_path);
+        xs_mkdir(ctx->xsh, t, frontend_path);
+        xs_set_permissions(ctx->xsh, t, frontend_path, frontend_perms, ARRAY_SIZE(frontend_perms));
+        xs_write(ctx->xsh, t, libxl_sprintf(&gc, "%s/backend", frontend_path), backend_path, strlen(backend_path));
+        libxl_xs_writev(&gc, t, frontend_path, fents);
+    }
 
-    /* and write frontend kvs and backend kvs */
-    libxl_xs_writev(&gc, t, backend_path, bents);
-    libxl_xs_writev(&gc, t, frontend_path, fents);
+    if (bents) {
+        xs_rm(ctx->xsh, t, backend_path);
+        xs_mkdir(ctx->xsh, t, backend_path);
+        xs_set_permissions(ctx->xsh, t, backend_path, backend_perms, ARRAY_SIZE(backend_perms));
+        xs_write(ctx->xsh, t, libxl_sprintf(&gc, "%s/frontend", backend_path), frontend_path, strlen(frontend_path));
+        libxl_xs_writev(&gc, t, backend_path, bents);
+    }
 
     if (!xs_transaction_end(ctx->xsh, t, 0)) {
         if (errno == EAGAIN)
index 3098f343c282a538357c6ebb6ec0908f7a867b43..90acd5d045fb1720eda3d231620caee85be5ae32 100644 (file)
@@ -49,6 +49,9 @@ char **libxl_xs_kvs_of_flexarray(libxl_gc *gc, flexarray_t *array, int length)
     char **kvs;
     int i;
 
+    if (!length)
+        return NULL;
+
     kvs = libxl_calloc(gc, length + 2, sizeof(char *));
     if (kvs) {
         for (i = 0; i < length; i += 2) {