From: Michal Privoznik <[email protected]>

The guest_is_on() function is documented to check whether given
domain is running and set guest_running variable accordingly. It
does so by running virsh (transitively), then setting the
variable and only after that comparing $? variable. This is
obviously wrong, because after the guest_running variable
assignment the $? variable no longer holds the exit code of
virsh. Even worse, as explained in the previous commit, it never
held that value in the first place. Fix this by firstly setting
the global variable and only after that running virsh.

Fixes: 08071ec0f113bb1fe8dcc263cb6bf87529e8b76b
Resolves: https://gitlab.com/libvirt/libvirt/-/issues/839
Signed-off-by: Michal Privoznik <[email protected]>
---
 tools/libvirt-guests.sh.in | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/tools/libvirt-guests.sh.in b/tools/libvirt-guests.sh.in
index e05bfdba61..66a39b9178 100644
--- a/tools/libvirt-guests.sh.in
+++ b/tools/libvirt-guests.sh.in
@@ -132,9 +132,10 @@ guest_name() {
 guest_is_on() {
     local uri="$1"
     local uuid="$2"
-    local id="$(run_virsh "$uri" domid "$uuid")"
+    local id
 
     guest_running="false"
+    id="$(run_virsh "$uri" domid "$uuid")"
     if [ $? -ne 0 ]; then
         RETVAL=1
         return 1
-- 
2.52.0

Reply via email to