diff --git a/tools/virsh.c b/tools/virsh.c index 0d0ebca89ba46d39b029f543bafb9a07509473d3..9faac350eba561ed41f4001910cdd936b143106d 100644 --- a/tools/virsh.c +++ b/tools/virsh.c @@ -523,6 +523,7 @@ cmdRunConsole(vshControl *ctl, virDomainPtr dom) char *doc; char *thatHost = NULL; char *thisHost = NULL; + virDomainInfo dominfo; if (!(thisHost = virGetHostname(ctl->conn))) { vshError(ctl, "%s", _("Failed to get local hostname")); @@ -539,6 +540,16 @@ cmdRunConsole(vshControl *ctl, virDomainPtr dom) 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;