From 308e9e69fa821d2de072981c262523b292dadefc Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sun, 7 Apr 2019 10:23:50 +0200 Subject: [PATCH] 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. --- src/dns/nm-dns-systemd-resolved.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/dns/nm-dns-systemd-resolved.c b/src/dns/nm-dns-systemd-resolved.c index fddd7603f2..2da58e11e9 100644 --- a/src/dns/nm-dns-systemd-resolved.c +++ b/src/dns/nm-dns-systemd-resolved.c @@ -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