qemuNamespacePrepareOneItem: Restructure code to avoid temporary variables

The value of 'next' is copied into 'item.file' so we can move the update
to the 'next' pointer earlier and move the VIR_APPEND_ELEMENT call to
where we figure out that we need to append the value.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Peter Krempa 2021-08-05 17:00:45 +02:00
parent 1f2ceda397
commit 0fcf40dc8b

View File

@ -1197,7 +1197,6 @@ qemuNamespacePrepareOneItem(qemuNamespaceMknodData *data,
while (1) {
g_auto(qemuNamespaceMknodItem) item = { 0 };
bool isLink;
bool addToData = false;
int rc;
rc = qemuNamespaceMknodItemInit(&item, cfg, vm, next);
@ -1210,25 +1209,21 @@ qemuNamespacePrepareOneItem(qemuNamespaceMknodData *data,
}
isLink = S_ISLNK(item.sb.st_mode);
g_free(next);
next = g_strdup(item.target);
if (STRPREFIX(next, QEMU_DEVPREFIX)) {
if (STRPREFIX(item.file, QEMU_DEVPREFIX)) {
for (i = 0; i < ndevMountsPath; i++) {
if (STREQ(devMountsPath[i], "/dev"))
continue;
if (STRPREFIX(next, devMountsPath[i]))
if (STRPREFIX(item.file, devMountsPath[i]))
break;
}
if (i == ndevMountsPath)
addToData = true;
VIR_APPEND_ELEMENT(data->items, data->nitems, item);
}
g_free(next);
next = g_strdup(item.target);
if (addToData)
VIR_APPEND_ELEMENT(data->items, data->nitems, item);
if (!isLink)
break;