]> xenbits.xensource.com Git - libvirt.git/commitdiff
secret: Introduce listUnlinkSecret
authorJohn Ferlan <jferlan@redhat.com>
Wed, 24 Feb 2016 15:57:28 +0000 (10:57 -0500)
committerJohn Ferlan <jferlan@redhat.com>
Tue, 1 Mar 2016 11:44:28 +0000 (06:44 -0500)
Add a temporary helper to search for a specific secret by address
on the list and remove it if it's found. The following patch will
introduce a common allocation and listInsert helper. That means
error paths of the routines calling would need a way to remove the
secret off the list.

Signed-off-by: John Ferlan <jferlan@redhat.com>
src/secret/secret_driver.c

index 2026e19531904adb07a5092ee6902bd1cefc800b..dd8062f6e339f3f21a5db65846eca39546082b8f 100644 (file)
@@ -353,6 +353,26 @@ secretLoadValue(virSecretObjPtr secret)
     return ret;
 }
 
+
+static void
+listUnlinkSecret(virSecretObjPtr *pptr,
+                 virSecretObjPtr secret)
+{
+    if (!secret)
+        return;
+
+    if (*pptr == secret) {
+        *pptr = secret->next;
+    } else {
+        virSecretObjPtr tmp = *pptr;
+        while (tmp && tmp->next != secret)
+            tmp = tmp->next;
+        if (tmp)
+            tmp->next = secret->next;
+    }
+}
+
+
 static virSecretObjPtr
 secretLoad(const char *file,
            const char *path,
@@ -980,15 +1000,7 @@ secretUndefine(virSecretPtr obj)
         secretDeleteSaved(secret) < 0)
         goto cleanup;
 
-    if (driver->secrets == secret) {
-        driver->secrets = secret->next;
-    } else {
-        virSecretObjPtr tmp = driver->secrets;
-        while (tmp && tmp->next != secret)
-            tmp = tmp->next;
-        if (tmp)
-            tmp->next = secret->next;
-    }
+    listUnlinkSecret(&driver->secrets, secret);
     secretFree(secret);
 
     ret = 0;