]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
util: don't use virFirewallRuleToString() to log the rule being applied
authorLaine Stump <laine@redhat.com>
Sun, 13 Mar 2022 18:21:02 +0000 (14:21 -0400)
committerLaine Stump <laine@redhat.com>
Wed, 24 Aug 2022 16:22:47 +0000 (12:22 -0400)
Instead of separately building the commandline into a string to log,
just wait a few lines until we've built the virCommand object, and
call virCommandToString, which does the same thing.

(As a bonus, we were already calling virCommandToString to put the
commandline in a string in case of a failure when running it - from
the point of view of *that* usage, we're just moving the call to
virCommandToString *up* a few lines, i.e. we now only construct the
commandline string once.)

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/util/virfirewall.c

index 247430be2ee09b38bb9ab52d9dedfd9ae9028fa7..fbb0e438b3ea246639b19c5cdeb85dbf1da22905 100644 (file)
@@ -486,6 +486,7 @@ virFirewallApplyRuleDirect(virFirewallRule *rule,
     size_t i;
     const char *bin = virFirewallLayerCommandTypeToString(rule->layer);
     g_autoptr(virCommand) cmd = NULL;
+    g_autofree char *cmdStr = NULL;
     int status;
     g_autofree char *error = NULL;
 
@@ -501,6 +502,9 @@ virFirewallApplyRuleDirect(virFirewallRule *rule,
     for (i = 0; i < rule->argsLen; i++)
         virCommandAddArg(cmd, rule->args[i]);
 
+    cmdStr = virCommandToString(cmd, false);
+    VIR_INFO("Applying rule '%s'", NULLSTR(cmdStr));
+
     virCommandSetOutputBuffer(cmd, output);
     virCommandSetErrorBuffer(cmd, &error);
 
@@ -511,10 +515,9 @@ virFirewallApplyRuleDirect(virFirewallRule *rule,
         if (ignoreErrors) {
             VIR_DEBUG("Ignoring error running command");
         } else {
-            g_autofree char *args = virCommandToString(cmd, false);
             virReportError(VIR_ERR_INTERNAL_ERROR,
                            _("Failed to apply firewall rules %s: %s"),
-                           NULLSTR(args), NULLSTR(error));
+                           NULLSTR(cmdStr), NULLSTR(error));
             VIR_FREE(*output);
             return -1;
         }
@@ -531,10 +534,6 @@ virFirewallApplyRule(virFirewall *firewall,
 {
     g_autofree char *output = NULL;
     g_auto(GStrv) lines = NULL;
-    g_autofree char *str
-        = virFirewallRuleToString(virFirewallLayerCommandTypeToString(rule->layer), rule);
-
-    VIR_INFO("Applying rule '%s'", NULLSTR(str));
 
     if (rule->ignoreErrors)
         ignoreErrors = rule->ignoreErrors;