]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
libvirt-guest.sh.in: Fix logical error in guest_is_on()
authorMichal Privoznik <mprivozn@redhat.com>
Mon, 19 Jan 2026 10:42:14 +0000 (11:42 +0100)
committerMichal Privoznik <mprivozn@redhat.com>
Mon, 19 Jan 2026 13:22:05 +0000 (14:22 +0100)
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 <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
tools/libvirt-guests.sh.in

index e05bfdba61ea9edbc714f5540551e0bfe9eb19b2..66a39b91782072705ffd0161e701ea1a6e63fdbb 100644 (file)
@@ -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