diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c index a493715..da09106 100644 --- a/tools/libxl/libxl.c +++ b/tools/libxl/libxl.c @@ -728,33 +728,21 @@ static char ** libxl_build_device_model_args(struct libxl_ctx *ctx, void dm_xenstore_record_pid(struct libxl_ctx *ctx, void *for_spawn, pid_t innerchild) { struct libxl_device_model_starting *starting = for_spawn; - struct libxl_ctx clone; char *kvs[3]; - int rc, cloned; - - if (libxl_clone_context_xs(ctx, &clone)) { - XL_LOG(ctx, XL_LOG_ERROR, "Out of memory when cloning context"); - /* Throw a prayer fallback */ - clone = *ctx; - clone.xsh = xs_daemon_open(); - cloned = 0; - } else { - cloned = 1; - } + int rc; + struct xs_handle *xsh; + + xsh = xs_daemon_open(); /* we mustn't use the parent's handle in the child */ kvs[0] = "image/device-model-pid"; - kvs[1] = libxl_sprintf(&clone, "%d", innerchild); + asprintf(&kvs[1], "%d", innerchild); kvs[2] = NULL; - rc = libxl_xs_writev(&clone, XBT_NULL, starting->dom_path, kvs); - if (rc) XL_LOG_ERRNO(&clone, XL_LOG_ERROR, - "Couldn't record device model pid %ld at %s/%s", - (unsigned long)innerchild, starting->dom_path, kvs); - if (cloned) { - libxl_discard_cloned_context_xs(&clone); - } else { - xs_daemon_close(clone.xsh); - } + + rc = xs_writev(xsh, XBT_NULL, starting->dom_path, kvs); + if (rc) + return; + xs_daemon_close(xsh); } static int libxl_vfb_and_vkb_from_device_model_info(struct libxl_ctx *ctx, diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h index 8b64965..1f7e64a 100644 --- a/tools/libxl/libxl_internal.h +++ b/tools/libxl/libxl_internal.h @@ -93,6 +93,8 @@ typedef struct { (u)[0], (u)[1], (u)[2], (u)[3], (u)[4], (u)[5], (u)[6], (u)[7], \ (u)[8], (u)[9], (u)[10], (u)[11], (u)[12], (u)[13], (u)[14], (u)[15]) +int xs_writev(struct xs_handle *xsh, xs_transaction_t t, char *dir, char *kvs[]); + /* memory allocation tracking/helpers */ int libxl_clone_context(struct libxl_ctx *from, struct libxl_ctx *to); static inline int libxl_clone_context_xs( diff --git a/tools/libxl/libxl_xshelp.c b/tools/libxl/libxl_xshelp.c index 87c494a..3c065a0 100644 --- a/tools/libxl/libxl_xshelp.c +++ b/tools/libxl/libxl_xshelp.c @@ -23,6 +23,25 @@ #include "libxl.h" #include "libxl_internal.h" +int xs_writev(struct xs_handle *xsh, xs_transaction_t t, char *dir, char *kvs[]) +{ + char *path; + int i; + + if (!kvs) + return 0; + + for (i = 0; kvs[i] != NULL; i += 2) { + asprintf(&path, "%s/%s", dir, kvs[i]); + if (path) { + int length = strlen(kvs[i + 1]); + xs_write(xsh, t, path, kvs[i + 1], length); + free(path); + } + } + return 0; +} + char **libxl_xs_kvs_of_flexarray(struct libxl_ctx *ctx, flexarray_t *array, int length) { char **kvs;