---
tools/virsh-domain.c | 24 ++++++++++++++++++------
1 file changed, 18 insertions(+), 6 deletions(-)
diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index f41a74b..a201316 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -2627,18 +2627,30 @@ cmdSuspend(vshControl *ctl, const vshCmd *cmd)
{
virDomainPtr dom;
const char *name;
- bool ret = true;
+ bool ret = false;
+ int state;
if (!(dom = vshCommandOptDomain(ctl, cmd, &name)))
- return false;
+ goto cleanup;
- if (virDomainSuspend(dom) == 0) {
- vshPrint(ctl, _("Domain %s suspended\n"), name);
+ if ((state = vshDomainState(ctl, dom, NULL)) < 0) {
+ vshPrint(ctl, _("Unable to get domain status"));
+ goto cleanup;
+ }
+ if (state == VIR_DOMAIN_RUNNING ||
+ state == VIR_DOMAIN_NOSTATE ||
+ state == VIR_DOMAIN_BLOCKED) {
+ if (virDomainSuspend(dom) == 0) {
+ vshPrint(ctl, _("Domain %s suspended\n"), name);
+ ret = true;
+ } else {
+ vshError(ctl, _("Failed to suspend domain %s"), name);
+ }
} else {
- vshError(ctl, _("Failed to suspend domain %s"), name);
- ret = false;
+ vshPrint(ctl, _("Domain %s is not running"), name);
}
+cleanup:
virDomainFree(dom);
return ret;
}
--
1.8.1.4