The 'virsh console' command did not check if the domain was
already running before attempting to fetch the XML and extract
the console PTY path. This caused a slightly unhelpful / misleading
error message for the user. The explicit check ensures the user
gets an explicit 'domain is not running' message.
* tools/virsh.c: Validate that state != VIR_DOMAIN_SHUTOFF in
virsh console command
char *doc;
char *thatHost = NULL;
char *thisHost = NULL;
+ virDomainInfo dominfo;
if (!(thisHost = virGetHostname(ctl->conn))) {
vshError(ctl, "%s", _("Failed to get local hostname"));
goto cleanup;
}
+ if (virDomainGetInfo(dom, &dominfo) < 0) {
+ vshError(ctl, "%s", _("Unable to get domain status"));
+ goto cleanup;
+ }
+
+ if (dominfo.state == VIR_DOMAIN_SHUTOFF) {
+ vshError(ctl, "%s", _("The domain is not running"));
+ goto cleanup;
+ }
+
doc = virDomainGetXMLDesc(dom, 0);
if (!doc)
goto cleanup;