libvirt-guest.sh.in: Fix logical error in guest_is_on()

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: 08071ec0f1
Resolves: https://gitlab.com/libvirt/libvirt/-/issues/839
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Michal Privoznik
2026-01-19 14:22:05 +01:00
parent 8f0cf96b66
commit 2442030856
+2 -1
View 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