[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH 1/2] libxl: pass environment to device model
Prepare device-model setup functions to pass also environment variables to the spawned process. This is required for upcoming changes which will set DISPLAY and XAUTHORITY for SDL. Signed-off-by: Olaf Hering <olaf@xxxxxxxxx> Cc: Ian Jackson <ian.jackson@xxxxxxxxxxxxx> Cc: Stefano Stabellini <stefano.stabellini@xxxxxxxxxxxxx> Cc: Ian Campbell <ian.campbell@xxxxxxxxxx> Cc: Wei Liu <wei.liu2@xxxxxxxxxx> --- tools/libxl/libxl_dm.c | 76 +++++++++++++++++++++++++++++++------------------- 1 file changed, 48 insertions(+), 28 deletions(-) diff --git a/tools/libxl/libxl_dm.c b/tools/libxl/libxl_dm.c index 30c1578..3db12ba 100644 --- a/tools/libxl/libxl_dm.c +++ b/tools/libxl/libxl_dm.c @@ -122,9 +122,10 @@ static const char *dm_keymap(const libxl_domain_config *guest_config) return NULL; } -static char ** libxl__build_device_model_args_old(libxl__gc *gc, +static int libxl__build_device_model_args_old(libxl__gc *gc, const char *dm, int domid, const libxl_domain_config *guest_config, + char ***args, char ***envs, const libxl__domain_build_state *state) { const libxl_domain_create_info *c_info = &guest_config->c_info; @@ -135,8 +136,9 @@ static char ** libxl__build_device_model_args_old(libxl__gc *gc, const int num_nics = guest_config->num_nics; const char *keymap = dm_keymap(guest_config); int i; - flexarray_t *dm_args; + flexarray_t *dm_args, *dm_envs; dm_args = flexarray_make(gc, 16, 1); + dm_envs = flexarray_make(gc, 16, 1); flexarray_vappend(dm_args, dm, "-d", libxl__sprintf(gc, "%d", domid), NULL); @@ -161,7 +163,7 @@ static char ** libxl__build_device_model_args_old(libxl__gc *gc, if (strchr(vnc->listen, ':') != NULL) { if (vnc->display) { LOG(ERROR, "vncdisplay set, vnclisten contains display"); - return NULL; + return ERROR_INVAL; } vncarg = vnc->listen; } else { @@ -207,14 +209,14 @@ static char ** libxl__build_device_model_args_old(libxl__gc *gc, if (b_info->kernel) { LOG(ERROR, "HVM direct kernel boot is not supported by " "qemu-xen-traditional"); - return NULL; + return ERROR_INVAL; } if (b_info->u.hvm.serial || b_info->u.hvm.serial_list) { if ( b_info->u.hvm.serial && b_info->u.hvm.serial_list ) { LOG(ERROR, "Both serial and serial_list set"); - return NULL; + return ERROR_INVAL; } if (b_info->u.hvm.serial) { flexarray_vappend(dm_args, @@ -262,7 +264,7 @@ static char ** libxl__build_device_model_args_old(libxl__gc *gc, if ( b_info->u.hvm.usbdevice && b_info->u.hvm.usbdevice_list ) { LOG(ERROR, "Both usbdevice and usbdevice_list set"); - return NULL; + return ERROR_INVAL; } flexarray_append(dm_args, "-usb"); if (b_info->u.hvm.usbdevice) { @@ -353,7 +355,11 @@ static char ** libxl__build_device_model_args_old(libxl__gc *gc, abort(); } flexarray_append(dm_args, NULL); - return (char **) flexarray_contents(dm_args); + *args = (char **) flexarray_contents(dm_args); + flexarray_append(dm_envs, NULL); + if (envs) + *envs = (char **) flexarray_contents(dm_envs); + return 0; } static const char *qemu_disk_format_string(libxl_disk_format format) @@ -416,9 +422,10 @@ static char *dm_spice_options(libxl__gc *gc, return opt; } -static char ** libxl__build_device_model_args_new(libxl__gc *gc, +static int libxl__build_device_model_args_new(libxl__gc *gc, const char *dm, int guest_domid, const libxl_domain_config *guest_config, + char ***args, char ***envs, const libxl__domain_build_state *state, int *dm_state_fd) { @@ -433,12 +440,13 @@ static char ** libxl__build_device_model_args_new(libxl__gc *gc, const libxl_sdl_info *sdl = dm_sdl(guest_config); const char *keymap = dm_keymap(guest_config); char *machinearg; - flexarray_t *dm_args; + flexarray_t *dm_args, *dm_envs; int i, connection, devid; uint64_t ram_size; const char *path, *chardev; dm_args = flexarray_make(gc, 16, 1); + dm_envs = flexarray_make(gc, 16, 1); flexarray_vappend(dm_args, dm, "-xen-domid", @@ -479,7 +487,7 @@ static char ** libxl__build_device_model_args_new(libxl__gc *gc, /* We've forgotten to add the clause */ LOG(ERROR, "%s: unknown channel connection %d", __func__, connection); - return NULL; + return ERROR_INVAL; } flexarray_append(dm_args, "-chardev"); flexarray_append(dm_args, (void*)chardev); @@ -516,7 +524,7 @@ static char ** libxl__build_device_model_args_new(libxl__gc *gc, if (strchr(vnc->listen, ':') != NULL) { if (vnc->display) { LOG(ERROR, "vncdisplay set, vnclisten contains display"); - return NULL; + return ERROR_INVAL; } vncarg = vnc->listen; } else { @@ -575,7 +583,7 @@ static char ** libxl__build_device_model_args_new(libxl__gc *gc, if ( b_info->u.hvm.serial && b_info->u.hvm.serial_list ) { LOG(ERROR, "Both serial and serial_list set"); - return NULL; + return ERROR_INVAL; } if (b_info->u.hvm.serial) { flexarray_vappend(dm_args, @@ -600,7 +608,7 @@ static char ** libxl__build_device_model_args_new(libxl__gc *gc, const libxl_spice_info *spice = &b_info->u.hvm.spice; char *spiceoptions = dm_spice_options(gc, spice); if (!spiceoptions) - return NULL; + return ERROR_INVAL; flexarray_append(dm_args, "-spice"); flexarray_append(dm_args, spiceoptions); @@ -637,7 +645,7 @@ static char ** libxl__build_device_model_args_new(libxl__gc *gc, if ( b_info->u.hvm.usbdevice && b_info->u.hvm.usbdevice_list ) { LOG(ERROR, "Both usbdevice and usbdevice_list set"); - return NULL; + return ERROR_INVAL; } flexarray_append(dm_args, "-usb"); if (b_info->u.hvm.usbdevice) { @@ -675,7 +683,7 @@ static char ** libxl__build_device_model_args_new(libxl__gc *gc, default: LOG(ERROR, "usbversion parameter is invalid, " "must be between 1 and 3"); - return NULL; + return ERROR_INVAL; } if (b_info->u.hvm.spice.usbredirection >= 0 && b_info->u.hvm.spice.usbredirection < 5) { @@ -687,7 +695,7 @@ static char ** libxl__build_device_model_args_new(libxl__gc *gc, } else { LOG(ERROR, "usbredirection parameter is invalid, " "it must be between 1 and 4"); - return NULL; + return ERROR_INVAL; } } if (b_info->u.hvm.soundhw) { @@ -872,12 +880,17 @@ static char ** libxl__build_device_model_args_new(libxl__gc *gc, } } flexarray_append(dm_args, NULL); - return (char **) flexarray_contents(dm_args); + *args = (char **) flexarray_contents(dm_args); + flexarray_append(dm_envs, NULL); + if (envs) + *envs = (char **) flexarray_contents(dm_envs); + return 0; } -static char ** libxl__build_device_model_args(libxl__gc *gc, +static int libxl__build_device_model_args(libxl__gc *gc, const char *dm, int guest_domid, const libxl_domain_config *guest_config, + char ***args, char ***envs, const libxl__domain_build_state *state, int *dm_state_fd) /* dm_state_fd may be NULL iff caller knows we are using old stubdom @@ -889,17 +902,19 @@ static char ** libxl__build_device_model_args(libxl__gc *gc, case LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN_TRADITIONAL: return libxl__build_device_model_args_old(gc, dm, guest_domid, guest_config, + args, envs, state); case LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN: assert(dm_state_fd != NULL); assert(*dm_state_fd < 0); return libxl__build_device_model_args_new(gc, dm, guest_domid, guest_config, + args, envs, state, dm_state_fd); default: LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "unknown device model version %d", guest_config->b_info.device_model_version); - return NULL; + return ERROR_INVAL; } } @@ -1109,9 +1124,10 @@ void libxl__spawn_stub_dm(libxl__egc *egc, libxl__stub_dm_spawn_state *sdss) if (ret) goto out; - args = libxl__build_device_model_args(gc, "stubdom-dm", guest_domid, - guest_config, d_state, NULL); - if (!args) { + ret = libxl__build_device_model_args(gc, "stubdom-dm", guest_domid, + guest_config, &args, NULL, + d_state, NULL); + if (ret) { ret = ERROR_FAIL; goto out; } @@ -1393,7 +1409,7 @@ void libxl__spawn_local_dm(libxl__egc *egc, libxl__dm_spawn_state *dmss) char *path; int logfile_w, null; int rc; - char **args, **arg; + char **args, **arg, **envs; xs_transaction_t t; char *vm_path; char **pass_stuff; @@ -1415,12 +1431,11 @@ void libxl__spawn_local_dm(libxl__egc *egc, libxl__dm_spawn_state *dmss) rc = ERROR_FAIL; goto out; } - args = libxl__build_device_model_args(gc, dm, domid, guest_config, state, + rc = libxl__build_device_model_args(gc, dm, domid, guest_config, + &args, &envs, state, &dm_state_fd); - if (!args) { - rc = ERROR_FAIL; + if (rc) goto out; - } if (b_info->type == LIBXL_DOMAIN_TYPE_HVM) { path = xs_get_domain_path(ctx->xsh, domid); @@ -1487,6 +1502,11 @@ retry_transaction: LIBXL__LOG(CTX, XTL_DEBUG, "Spawning device-model %s with arguments:", dm); for (arg = args; *arg; arg++) LIBXL__LOG(CTX, XTL_DEBUG, " %s", *arg); + if (*envs) { + LOG(DEBUG, "Spawning device-model %s with additional environment:", dm); + for (arg = envs; *arg; arg += 2) + LOG(DEBUG, " %s=%s", arg[0], arg[1]); + } spawn->what = GCSPRINTF("domain %d device model", domid); spawn->xspath = GCSPRINTF("/local/domain/0/device-model/%d/state", domid); @@ -1504,7 +1524,7 @@ retry_transaction: goto out_close; if (!rc) { /* inner child */ setsid(); - libxl__exec(gc, null, logfile_w, logfile_w, dm, args, NULL); + libxl__exec(gc, null, logfile_w, logfile_w, dm, args, envs); } rc = 0; _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxx http://lists.xen.org/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |