debuggers.hg

changeset 22038:1fffba3a48ff

tools/libxl: libxl_device_generic_add: handle NULL fents or bents

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>
author Stefano Stabellini <stefano.stabellini@eu.citrix.com>
date Fri Aug 13 20:34:09 2010 +0100 (2010-08-13)
parents 5decc6971f2a
children a55625b65336
files tools/libxl/libxl_device.c tools/libxl/libxl_xshelp.c
line diff
     1.1 --- a/tools/libxl/libxl_device.c	Fri Aug 13 16:56:42 2010 +0100
     1.2 +++ b/tools/libxl/libxl_device.c	Fri Aug 13 20:34:09 2010 +0100
     1.3 @@ -76,21 +76,21 @@ retry_transaction:
     1.4      t = xs_transaction_start(ctx->xsh);
     1.5      /* FIXME: read frontend_path and check state before removing stuff */
     1.6  
     1.7 -    xs_rm(ctx->xsh, t, frontend_path);
     1.8 -    xs_rm(ctx->xsh, t, backend_path);
     1.9 -
    1.10 -    xs_mkdir(ctx->xsh, t, frontend_path);
    1.11 -    xs_set_permissions(ctx->xsh, t, frontend_path, frontend_perms, ARRAY_SIZE(frontend_perms));
    1.12 +    if (fents) {
    1.13 +        xs_rm(ctx->xsh, t, frontend_path);
    1.14 +        xs_mkdir(ctx->xsh, t, frontend_path);
    1.15 +        xs_set_permissions(ctx->xsh, t, frontend_path, frontend_perms, ARRAY_SIZE(frontend_perms));
    1.16 +        xs_write(ctx->xsh, t, libxl_sprintf(&gc, "%s/backend", frontend_path), backend_path, strlen(backend_path));
    1.17 +        libxl_xs_writev(&gc, t, frontend_path, fents);
    1.18 +    }
    1.19  
    1.20 -    xs_mkdir(ctx->xsh, t, backend_path);
    1.21 -    xs_set_permissions(ctx->xsh, t, backend_path, backend_perms, ARRAY_SIZE(backend_perms));
    1.22 -
    1.23 -    xs_write(ctx->xsh, t, libxl_sprintf(&gc, "%s/backend", frontend_path), backend_path, strlen(backend_path));
    1.24 -    xs_write(ctx->xsh, t, libxl_sprintf(&gc, "%s/frontend", backend_path), frontend_path, strlen(frontend_path));
    1.25 -
    1.26 -    /* and write frontend kvs and backend kvs */
    1.27 -    libxl_xs_writev(&gc, t, backend_path, bents);
    1.28 -    libxl_xs_writev(&gc, t, frontend_path, fents);
    1.29 +    if (bents) {
    1.30 +        xs_rm(ctx->xsh, t, backend_path);
    1.31 +        xs_mkdir(ctx->xsh, t, backend_path);
    1.32 +        xs_set_permissions(ctx->xsh, t, backend_path, backend_perms, ARRAY_SIZE(backend_perms));
    1.33 +        xs_write(ctx->xsh, t, libxl_sprintf(&gc, "%s/frontend", backend_path), frontend_path, strlen(frontend_path));
    1.34 +        libxl_xs_writev(&gc, t, backend_path, bents);
    1.35 +    }
    1.36  
    1.37      if (!xs_transaction_end(ctx->xsh, t, 0)) {
    1.38          if (errno == EAGAIN)
     2.1 --- a/tools/libxl/libxl_xshelp.c	Fri Aug 13 16:56:42 2010 +0100
     2.2 +++ b/tools/libxl/libxl_xshelp.c	Fri Aug 13 20:34:09 2010 +0100
     2.3 @@ -49,6 +49,9 @@ char **libxl_xs_kvs_of_flexarray(libxl_g
     2.4      char **kvs;
     2.5      int i;
     2.6  
     2.7 +    if (!length)
     2.8 +        return NULL;
     2.9 +
    2.10      kvs = libxl_calloc(gc, length + 2, sizeof(char *));
    2.11      if (kvs) {
    2.12          for (i = 0; i < length; i += 2) {