]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
tools: Use automatic mutex management
authorTim Wiederhake <twiederh@redhat.com>
Tue, 8 Feb 2022 13:59:30 +0000 (14:59 +0100)
committerTim Wiederhake <twiederh@redhat.com>
Fri, 11 Feb 2022 15:03:29 +0000 (16:03 +0100)
Signed-off-by: Tim Wiederhake <twiederh@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
src/util/virfirewall.c
tools/virsh.c
tools/virt-admin.c
tools/vsh.c

index 70092f2ef6aa53645622192908d414f63344c221..31a8352d4e914da828a7279591e1622af1d09fcd 100644 (file)
@@ -613,9 +613,7 @@ int
 virFirewallApply(virFirewall *firewall)
 {
     size_t i, j;
-    int ret = -1;
-
-    virMutexLock(&ruleLock);
+    VIR_LOCK_GUARD lock = virLockGuardLock(&ruleLock);
 
     if (!firewall || firewall->err) {
         int err = EINVAL;
@@ -624,7 +622,7 @@ virFirewallApply(virFirewall *firewall)
             err = firewall->err;
 
         virReportSystemError(err, "%s", _("Unable to create rule"));
-        goto cleanup;
+        return -1;
     }
 
     VIR_DEBUG("Applying groups for %p", firewall);
@@ -657,13 +655,10 @@ virFirewallApply(virFirewall *firewall)
 
             virErrorRestore(&saved_error);
             VIR_DEBUG("Done rolling back groups for %p", firewall);
-            goto cleanup;
+            return -1;
         }
     }
     VIR_DEBUG("Done applying groups for %p", firewall);
 
-    ret = 0;
- cleanup:
-    virMutexUnlock(&ruleLock);
-    return ret;
+    return 0;
 }
index 1c75a66fcba051d3513095bbc49452f338e58c0a..64e0700fcd07302660ed4a978e362c31237d5f5d 100644 (file)
@@ -412,13 +412,13 @@ virshDeinit(vshControl *ctl)
     virResetLastError();
 
     if (ctl->eventLoopStarted) {
-        int timer;
+        int timer = -1;
 
-        virMutexLock(&ctl->lock);
-        ctl->quit = true;
-        /* HACK: Add a dummy timeout to break event loop */
-        timer = virEventAddTimeout(0, virshDeinitTimer, NULL, NULL);
-        virMutexUnlock(&ctl->lock);
+        VIR_WITH_MUTEX_LOCK_GUARD(&ctl->lock) {
+            ctl->quit = true;
+            /* HACK: Add a dummy timeout to break event loop */
+            timer = virEventAddTimeout(0, virshDeinitTimer, NULL, NULL);
+        }
 
         virThreadJoin(&ctl->eventLoop);
 
index c0818e850a1050beba7f9d509bd39c5c88bd7eaa..e010763e211c4c945c9a00db04d36f049ca8b7ef 100644 (file)
@@ -1189,13 +1189,13 @@ vshAdmDeinit(vshControl *ctl)
     virResetLastError();
 
     if (ctl->eventLoopStarted) {
-        int timer;
+        int timer = -1;
 
-        virMutexLock(&ctl->lock);
-        ctl->quit = true;
-        /* HACK: Add a dummy timeout to break event loop */
-        timer = virEventAddTimeout(0, vshAdmDeinitTimer, NULL, NULL);
-        virMutexUnlock(&ctl->lock);
+        VIR_WITH_MUTEX_LOCK_GUARD(&ctl->lock) {
+            ctl->quit = true;
+            /* HACK: Add a dummy timeout to break event loop */
+            timer = virEventAddTimeout(0, vshAdmDeinitTimer, NULL, NULL);
+        }
 
         virThreadJoin(&ctl->eventLoop);
 
index 5056d7e19d69760e4448be84317746c3458e9332..4ec5e54b5d2ecf18b284d3955ea852b7cf6487e6 100644 (file)
@@ -2018,10 +2018,10 @@ vshEventLoop(void *opaque)
     vshControl *ctl = opaque;
 
     while (1) {
-        bool quit;
-        virMutexLock(&ctl->lock);
-        quit = ctl->quit;
-        virMutexUnlock(&ctl->lock);
+        bool quit = false;
+        VIR_WITH_MUTEX_LOCK_GUARD(&ctl->lock) {
+            quit = ctl->quit;
+        }
 
         if (quit)
             break;