1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2025-03-07 17:28:15 +00:00

util: don't use virFirewallRuleToString() to log the rule being applied

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>
This commit is contained in:
Laine Stump 2022-03-13 14:21:02 -04:00
parent 4dce6eee5c
commit 4c0310677a

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