util: virFirewallDGetPolicies: gracefully handle older firewalld

If the running firewalld doesn't support getPolicies() then we fallback
to the "libvirt" zone. Throwing an error log is excessive since we
gracefully fallback.

Avoids these logs:

error : virGDBusCallMethod:242 : error from service: \
GDBus.Error:org.freedesktop.DBus.Error.UnknownMethod

Fixes: ab56f84976 ("util: add virFirewallDGetPolicies()")
Signed-off-by: Eric Garver <eric@garver.life>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Eric Garver 2022-11-10 11:31:45 -05:00 committed by Michal Privoznik
parent 7594532ae2
commit d5ae0cd178
1 changed files with 10 additions and 1 deletions

View File

@ -240,6 +240,7 @@ virFirewallDGetPolicies(char ***policies, size_t *npolicies)
GDBusConnection *sysbus = virGDBusGetSystemBus();
g_autoptr(GVariant) reply = NULL;
g_autoptr(GVariant) array = NULL;
g_autoptr(virError) error = NULL;
*npolicies = 0;
*policies = NULL;
@ -247,10 +248,12 @@ virFirewallDGetPolicies(char ***policies, size_t *npolicies)
if (!sysbus)
return -1;
error = g_new0(virError, 1);
if (virGDBusCallMethod(sysbus,
&reply,
G_VARIANT_TYPE("(as)"),
NULL,
error,
VIR_FIREWALL_FIREWALLD_SERVICE,
"/org/fedoraproject/FirewallD1",
"org.fedoraproject.FirewallD1.policy",
@ -258,6 +261,12 @@ virFirewallDGetPolicies(char ***policies, size_t *npolicies)
NULL) < 0)
return -1;
if (error->level == VIR_ERR_ERROR) {
if (!virGDBusErrorIsUnknownMethod(error))
virReportErrorObject(error);
return -1;
}
g_variant_get(reply, "(@as)", &array);
*policies = g_variant_dup_strv(array, npolicies);