c401cc
From e864627c742bc647a36f622066744fdabe1be8c0 Mon Sep 17 00:00:00 2001
c401cc
Message-Id: <e864627c742bc647a36f622066744fdabe1be8c0.1387385061.git.jdenemar@redhat.com>
c401cc
From: Guannan Ren <gren@redhat.com>
c401cc
Date: Mon, 16 Dec 2013 09:48:44 +0100
c401cc
Subject: [PATCH] virsh: fix return value error of cpu-stats
c401cc
c401cc
virsh cpu-stats guest --start 0 --count 3
c401cc
It outputs right but the return value is 1 rather than 0
c401cc
echo $?
c401cc
1
c401cc
c401cc
Found by running libvirt-autotest
c401cc
./run -t libvirt --tests virsh_cpu_stats
c401cc
c401cc
(cherry picked from commit 9eb444364e5afca1e02448c48e0cb4ce36bf65db)
c401cc
c401cc
https://bugzilla.redhat.com/show_bug.cgi?id=1043388
c401cc
c401cc
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
c401cc
---
c401cc
 tools/virsh-domain.c | 10 +++++++---
c401cc
 1 file changed, 7 insertions(+), 3 deletions(-)
c401cc
c401cc
diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
c401cc
index b692299..9afe44a 100644
c401cc
--- a/tools/virsh-domain.c
c401cc
+++ b/tools/virsh-domain.c
c401cc
@@ -6340,7 +6340,9 @@ cmdCPUStats(vshControl *ctl, const vshCmd *cmd)
c401cc
 
c401cc
     if (!nparams) {
c401cc
         vshPrint(ctl, "%s", _("No per-CPU stats available"));
c401cc
-        goto do_show_total;
c401cc
+        if (show_total)
c401cc
+            goto do_show_total;
c401cc
+        goto cleanup;
c401cc
     }
c401cc
 
c401cc
     if (VIR_ALLOC_N(params, nparams * MIN(show_count, 128)) < 0)
c401cc
@@ -6379,10 +6381,12 @@ cmdCPUStats(vshControl *ctl, const vshCmd *cmd)
c401cc
     }
c401cc
     VIR_FREE(params);
c401cc
 
c401cc
-do_show_total:
c401cc
-    if (!show_total)
c401cc
+    if (!show_total) {
c401cc
+        ret = true;
c401cc
         goto cleanup;
c401cc
+    }
c401cc
 
c401cc
+do_show_total:
c401cc
     /* get supported num of parameter for total statistics */
c401cc
     if ((nparams = virDomainGetCPUStats(dom, NULL, 0, -1, 1, flags)) < 0)
c401cc
         goto failed_stats;
c401cc
-- 
c401cc
1.8.5.1
c401cc