return execl(p, p, domid_s, "--num", cons_num_s, (void *)NULL) == 0 ? 0 : ERROR_FAIL;
}
+int libxl_primary_console_exec(struct libxl_ctx *ctx, uint32_t domid_vm)
+{
+ uint32_t stubdomid = libxl_get_stubdom_id(ctx, domid_vm);
+ if (stubdomid)
+ return libxl_console_exec(ctx, stubdomid, 1);
+ else
+ return libxl_console_exec(ctx, domid_vm, 0);
+}
+
static char ** libxl_build_device_model_args(struct libxl_ctx *ctx,
libxl_device_model_info *info,
libxl_device_nic *vifs,
int libxl_set_memory_target(struct libxl_ctx *ctx, uint32_t domid, uint32_t target_memkb, int enforce);
int libxl_console_exec(struct libxl_ctx *ctx, uint32_t domid, int cons_num);
+/* libxl_primary_console_exec finds the domid and console number
+ * corresponding to the primary console of the given vm, then calls
+ * libxl_console_exec with the right arguments (domid might be different
+ * if the guest is using stubdoms).
+ * This function can be called after creating the device model, in
+ * case of HVM guests, and before libxl_run_bootloader in case of PV
+ * guests using pygrub. */
+int libxl_primary_console_exec(struct libxl_ctx *ctx, uint32_t domid_vm);
int libxl_domain_info(struct libxl_ctx*, struct libxl_dominfo *info_r,
uint32_t domid);
return r;
}
-int autoconnect_console(int cons_num)
+int autoconnect_console(int hvm)
{
- int status;
+ int status, options;
pid_t pid, r;
/*
return 0;
/*
- * Catch failure of the create process.
+ * In the PV case we only catch failure of the create process, in
+ * the HVM case we also wait for the creation process to be
+ * completed so that the stubdom is already up and running and we
+ * can connect to it.
*/
+ if (hvm)
+ options = 0;
+ else
+ options = WNOHANG;
sleep(1);
- r = waitpid(pid, &status, WNOHANG);
+ r = waitpid(pid, &status, options);
if (r > 0 && WIFEXITED(status) && WEXITSTATUS(status) != 0)
_exit(WEXITSTATUS(status));
- libxl_console_exec(&ctx, domid, cons_num);
+ libxl_primary_console_exec(&ctx, domid);
/* Do not return. xl continued in child process */
fprintf(stderr, "Unable to attach console\n");
_exit(1);
}
if (dom_info->console_autoconnect) {
- ret = autoconnect_console(0);
+ ret = autoconnect_console(info1.hvm);
if (ret)
goto error_out;
}
int main_console(int argc, char **argv)
{
- int opt = 0, cons_num = 0;
+ int opt = 0;
while ((opt = getopt(argc, argv, "hn:")) != -1) {
switch (opt) {
case 'h':
help("console");
exit(0);
- case 'n':
- if (optarg) {
- cons_num = strtol(optarg, NULL, 10);
- }
- break;
default:
fprintf(stderr, "option not supported\n");
break;
}
find_domain(argv[optind]);
- libxl_console_exec(&ctx, domid, 0);
+ libxl_primary_console_exec(&ctx, domid);
fprintf(stderr, "Unable to attach console\n");
return 1;
}