]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemuNamespacePrepareOneItem: Restructure code to avoid temporary variables
authorPeter Krempa <pkrempa@redhat.com>
Thu, 5 Aug 2021 15:00:45 +0000 (17:00 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Mon, 9 Aug 2021 08:09:01 +0000 (10:09 +0200)
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>
src/qemu/qemu_namespace.c

index ca59b5d95bc9f7e8c28626d0f68361c17c4d5f59..01a5edc5857d261d5aa8ed31a223a22a32bd15b0 100644 (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;