secret: Introduce listUnlinkSecret

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>
This commit is contained in:
John Ferlan 2016-02-24 10:57:28 -05:00
parent 0250f34af1
commit 27950465b1

View 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;