[PATCH 18/40] virfirewalltest: Shuffle the code around to remove a loop

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



We are already looping over the arguments to construct the list, so we
can add them to fwBuf right away rather than in an extra loop if we move
some of the 'fwBuf' parts earlier and merge the two loops.

Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx>
---
 tests/virfirewalltest.c | 23 ++++++++++-------------
 1 file changed, 10 insertions(+), 13 deletions(-)

diff --git a/tests/virfirewalltest.c b/tests/virfirewalltest.c
index 9f95520859..e14a34d7d2 100644
--- a/tests/virfirewalltest.c
+++ b/tests/virfirewalltest.c
@@ -108,12 +108,20 @@ VIR_MOCK_WRAP_RET_ARGS(g_dbus_connection_call_sync,
         char *item = NULL;
         bool isAdd = false;
         bool doError = false;
-        size_t i;

         g_variant_get(params, "(&sas)", &type, &iter);

         nargs = g_variant_iter_n_children(iter);

+        if (fwBuf) {
+            if (STREQ(type, "ipv4"))
+                virBufferAddLit(fwBuf, IPTABLES_PATH);
+            else if (STREQ(type, "ipv6"))
+                virBufferAddLit(fwBuf, IP6TABLES_PATH);
+            else
+                virBufferAddLit(fwBuf, EBTABLES_PATH);
+        }
+
         while (g_variant_iter_loop(iter, "s", &item)) {
             /* Fake failure on the command with this IP addr */
             if (STREQ(item, "-A")) {
@@ -123,21 +131,10 @@ VIR_MOCK_WRAP_RET_ARGS(g_dbus_connection_call_sync,
             }

             virStringListAdd(&args, item);
-        }
-
-        if (fwBuf) {
-            if (STREQ(type, "ipv4"))
-                virBufferAddLit(fwBuf, IPTABLES_PATH);
-            else if (STREQ(type, "ipv6"))
-                virBufferAddLit(fwBuf, IP6TABLES_PATH);
-            else
-                virBufferAddLit(fwBuf, EBTABLES_PATH);
-        }

-        for (i = 0; i < nargs; i++) {
             if (fwBuf) {
                 virBufferAddLit(fwBuf, " ");
-                virBufferEscapeShell(fwBuf, args[i]);
+                virBufferEscapeShell(fwBuf, item);
             }
         }

-- 
2.29.2




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux