debuggers.hg

changeset 22285:606b0eb2caa7

libxl: remove xs_writev function

It isn't actually being used to write a vector at the only callsite
and can easily be implemented using xs_write.

Furthermore the old implementation used to leak both the key and value
strings.

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
committer: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
author Ian Campbell <ian.campbell@citrix.com>
date Wed Oct 13 11:54:04 2010 +0100 (2010-10-13)
parents 6eaab8297681
children 38ad3633ecaf
files tools/libxl/libxl.c tools/libxl/libxl_internal.h tools/libxl/libxl_xshelp.c
line diff
     1.1 --- a/tools/libxl/libxl.c	Wed Oct 13 11:45:26 2010 +0100
     1.2 +++ b/tools/libxl/libxl.c	Wed Oct 13 11:54:04 2010 +0100
     1.3 @@ -1409,22 +1409,26 @@ static char ** libxl_build_device_model_
     1.4  static void dm_xenstore_record_pid(void *for_spawn, pid_t innerchild)
     1.5  {
     1.6      libxl_device_model_starting *starting = for_spawn;
     1.7 -    char *kvs[3];
     1.8 -    int rc;
     1.9      struct xs_handle *xsh;
    1.10 -
    1.11 -    xsh = xs_daemon_open();
    1.12 +    char *path = NULL, *pid = NULL;
    1.13 +    int len;
    1.14 +
    1.15 +    if (asprintf(&path, "%s/%s", starting->dom_path, "image/device-model-pid") < 0)
    1.16 +        goto out;
    1.17 +
    1.18 +    len = asprintf(&pid, "%d", innerchild);
    1.19 +    if (len < 0)
    1.20 +        goto out;
    1.21 +
    1.22      /* we mustn't use the parent's handle in the child */
    1.23 -
    1.24 -    kvs[0] = "image/device-model-pid";
    1.25 -    if (asprintf(&kvs[1], "%d", innerchild) < 0)
    1.26 -        return;
    1.27 -    kvs[2] = NULL;
    1.28 -
    1.29 -    rc = xs_writev(xsh, XBT_NULL, starting->dom_path, kvs);
    1.30 -    if (rc)
    1.31 -        return;
    1.32 +    xsh = xs_daemon_open();
    1.33 +
    1.34 +    xs_write(xsh, XBT_NULL, path, pid, len);
    1.35 +
    1.36      xs_daemon_close(xsh);
    1.37 +out:
    1.38 +    free(path);
    1.39 +    free(pid);
    1.40  }
    1.41  
    1.42  static int libxl_vfb_and_vkb_from_device_model_info(libxl_ctx *ctx,
     2.1 --- a/tools/libxl/libxl_internal.h	Wed Oct 13 11:45:26 2010 +0100
     2.2 +++ b/tools/libxl/libxl_internal.h	Wed Oct 13 11:54:04 2010 +0100
     2.3 @@ -109,8 +109,6 @@ typedef struct {
     2.4  
     2.5  #define PRINTF_ATTRIBUTE(x, y) __attribute__((format(printf, x, y)))
     2.6  
     2.7 -_hidden int xs_writev(struct xs_handle *xsh, xs_transaction_t t, char *dir, char *kvs[]);
     2.8 -
     2.9  typedef struct {
    2.10      /* mini-GC */
    2.11      int alloc_maxsize;
     3.1 --- a/tools/libxl/libxl_xshelp.c	Wed Oct 13 11:45:26 2010 +0100
     3.2 +++ b/tools/libxl/libxl_xshelp.c	Wed Oct 13 11:54:04 2010 +0100
     3.3 @@ -24,26 +24,6 @@
     3.4  #include "libxl.h"
     3.5  #include "libxl_internal.h"
     3.6  
     3.7 -int xs_writev(struct xs_handle *xsh, xs_transaction_t t, char *dir, char *kvs[])
     3.8 -{
     3.9 -    char *path;
    3.10 -    int i;
    3.11 -
    3.12 -    if (!kvs)
    3.13 -        return 0;
    3.14 -
    3.15 -    for (i = 0; kvs[i] != NULL; i += 2) {
    3.16 -        if (asprintf(&path, "%s/%s", dir, kvs[i]) < 0)
    3.17 -            return -1;
    3.18 -        if (path && kvs[i + 1]) {
    3.19 -            int length = strlen(kvs[i + 1]);
    3.20 -            xs_write(xsh, t, path, kvs[i + 1], length);
    3.21 -        }
    3.22 -        free(path);
    3.23 -    }
    3.24 -    return 0;
    3.25 -}
    3.26 -
    3.27  char **libxl__xs_kvs_of_flexarray(libxl__gc *gc, flexarray_t *array, int length)
    3.28  {
    3.29      char **kvs;