dns: ratelimit warnings about failure to send updates to NMDnsSystemdResolved

As we frequently send updates to systemd-resolved and for each update
send multiple messages, it can happen that we log a large number of
warnings if they all fail.

Rate limit the warnings to only warn once (until the failure is
recovered).

Currently, if systemd-resolved is not installed (or disabled) we already
fail once to create the D-Bus proxy (and never retry). That should be
fixed, to create the proxy with G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START_AT_CONSTRUCTION.
If we allow creating the proxy we would repeatedly try to send messages
and they would all fail. This is one example, where we need to ratelimit
the warning.
This commit is contained in:
Thomas Haller 2019-04-07 10:23:50 +02:00
parent 6f663b8f8e
commit 308e9e69fa

View file

@ -66,6 +66,7 @@ typedef struct {
GCancellable *init_cancellable;
GCancellable *update_cancellable;
CList request_queue_lst_head;
bool send_updates_warn_ratelimited:1;
} NMDnsSystemdResolvedPrivate;
struct _NMDnsSystemdResolved {
@ -124,13 +125,23 @@ call_done (GObject *source, GAsyncResult *r, gpointer user_data)
gs_unref_variant GVariant *v = NULL;
gs_free_error GError *error = NULL;
NMDnsSystemdResolved *self = (NMDnsSystemdResolved *) user_data;
NMDnsSystemdResolvedPrivate *priv;
v = g_dbus_proxy_call_finish (G_DBUS_PROXY (source), r, &error);
if ( !v
&& g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
return;
priv = NM_DNS_SYSTEMD_RESOLVED_GET_PRIVATE (self);
if (!v) {
if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
return;
_LOGW ("send-updates failed: %s", error->message);
}
if (!priv->send_updates_warn_ratelimited) {
priv->send_updates_warn_ratelimited = TRUE;
_LOGW ("send-updates failed to update systemd-resolved: %s", error->message);
} else
_LOGD ("send-updates failed: %s", error->message);
} else
priv->send_updates_warn_ratelimited = FALSE;
}
static void