diff --git a/generator/actions_properties.ml b/generator/actions_properties.ml index 61fca197a..c6474763f 100644 --- a/generator/actions_properties.ml +++ b/generator/actions_properties.ml @@ -59,8 +59,12 @@ the qemu binary at the same time as the handle is created.|} }; longdesc = "\ Return the current hypervisor binary. -This is always non-NULL. If it wasn't set already, then this will -return the default qemu binary name." }; +If it wasn't set already, then this will return the default +qemu binary name. + +For some backends this may return an error if called before +launch since it may not be possible to get the default hypervisor +before the appliance is launched." }; { defaults with name = "set_path"; added = (0, 0, 3); diff --git a/lib/handle.c b/lib/handle.c index 12fbf800e..ab0e1289e 100644 --- a/lib/handle.c +++ b/lib/handle.c @@ -575,7 +575,21 @@ guestfs_impl_set_hv (guestfs_h *g, const char *hv) char * guestfs_impl_get_hv (guestfs_h *g) { - return safe_strdup (g, g->hv); + if (g->hv) + return safe_strdup (g, g->hv); + else { + /* Try to return the default hypervisor. */ + const char *default_hv; + + if (g->backend_ops && g->backend_data && + (default_hv = g->backend_ops->get_default_hv (g, g->backend_data)) + != NULL) + return safe_strdup (g, default_hv); + else { + error (g, _("cannot get default hypervisor")); + return NULL; + } + } } int