diff -r f5d6afa46dd7 tools/libxl/libxl.c --- a/tools/libxl/libxl.c Tue Dec 07 18:10:46 2010 +0000 +++ b/tools/libxl/libxl.c Wed Dec 08 12:32:04 2010 -0800 @@ -1418,11 +1418,11 @@ goto out; /* we mustn't use the parent's handle in the child */ - xsh = xs_daemon_open(); + xsh = libxl__xs_open(); xs_write(xsh, XBT_NULL, path, pid, len); - xs_daemon_close(xsh); + libxl__xs_close(xsh); out: free(path); free(pid); diff -r f5d6afa46dd7 tools/libxl/libxl_device.c --- a/tools/libxl/libxl_device.c Tue Dec 07 18:10:46 2010 +0000 +++ b/tools/libxl/libxl_device.c Wed Dec 08 12:32:04 2010 -0800 @@ -428,7 +428,7 @@ unsigned int num; char **l = NULL; - xsh = xs_daemon_open(); + xsh = libxl__xs_open(); path = libxl__sprintf(&gc, "/local/domain/0/device-model/%d/state", domid); xs_watch(xsh, path, path); tv.tv_sec = LIBXL_DEVICE_MODEL_START_TIMEOUT; @@ -450,7 +450,7 @@ free(p); xs_unwatch(xsh, path, path); - xs_daemon_close(xsh); + libxl__xs_close(xsh); libxl__free_all(&gc); return rc; again: @@ -467,7 +467,7 @@ } } xs_unwatch(xsh, path, path); - xs_daemon_close(xsh); + libxl__xs_close(xsh); LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "Device Model not ready"); libxl__free_all(&gc); return -1; diff -r f5d6afa46dd7 tools/libxl/libxl_internal.h --- a/tools/libxl/libxl_internal.h Tue Dec 07 18:10:46 2010 +0000 +++ b/tools/libxl/libxl_internal.h Wed Dec 08 12:32:04 2010 -0800 @@ -140,6 +140,8 @@ _hidden char *libxl__xs_get_dompath(libxl__gc *gc, uint32_t domid); // logs errs _hidden char *libxl__xs_read(libxl__gc *gc, xs_transaction_t t, char *path); _hidden char **libxl__xs_directory(libxl__gc *gc, xs_transaction_t t, char *path, unsigned int *nb); +_hidden struct xs_handle *libxl__xs_open(void); +_hidden void libxl__xs_close(struct xs_handle *xsh); /* from xl_dom */ _hidden int libxl__domain_is_hvm(libxl_ctx *ctx, uint32_t domid); diff -r f5d6afa46dd7 tools/libxl/libxl_utils.c --- a/tools/libxl/libxl_utils.c Tue Dec 07 18:10:46 2010 +0000 +++ b/tools/libxl/libxl_utils.c Wed Dec 08 12:32:04 2010 -0800 @@ -399,7 +399,7 @@ int libxl_ctx_postfork(libxl_ctx *ctx) { if (ctx->xsh) xs_daemon_destroy_postfork(ctx->xsh); - ctx->xsh = xs_daemon_open(); + ctx->xsh = libxl__xs_open(); if (!ctx->xsh) return ERROR_FAIL; return 0; } diff -r f5d6afa46dd7 tools/libxl/libxl_xshelp.c --- a/tools/libxl/libxl_xshelp.c Tue Dec 07 18:10:46 2010 +0000 +++ b/tools/libxl/libxl_xshelp.c Wed Dec 08 12:32:04 2010 -0800 @@ -121,3 +121,19 @@ libxl__ptr_add(gc, ret); return ret; } + +struct xs_handle *libxl__xs_open(void) +{ + struct xs_handle* xsh = NULL; + + xsh = xs_daemon_open(); + if ( !xsh ) + xsh = xs_domain_open(); + + return xsh; +} + +void libxl__xs_close(struct xs_handle *xsh) +{ + xs_daemon_close(xsh); +}