core: force emission of DNS_CONFIG_CHANGED signal on SIGUSR1

If the configuration contains dns=none and resolv.conf is updated
through a dispatcher script, currently there is no way to tell NM that
the content of resolv.conf changed, so that it can restart a hostname
resolution.

Use SIGUSR1 (and SIGHUP) for that.
This commit is contained in:
Beniamino Galvani 2021-04-29 10:40:27 +02:00
parent caea7514cb
commit fa1f628bce
2 changed files with 18 additions and 10 deletions

View file

@ -224,9 +224,17 @@
<varlistentry>
<term><varname>SIGUSR1</varname></term>
<listitem><para>
The signal forces a rewrite of DNS configuration. Contrary to
SIGHUP, this does not restart the DNS plugin and will not interrupt
name resolution.
The signal forces a rewrite of DNS configuration. Contrary
to SIGHUP, this does not restart the DNS plugin and will not
interrupt name resolution.
When NetworkManager is not managing DNS, the signal forces
a restart of operations that depend on the DNS
configuration (like the resolution of the system hostname
via reverse DNS, or the resolution of WireGuard peers);
therefore, it can be used to tell NetworkManager that the
content of resolv.conf was changed externally.
In the future, further actions may be added. A SIGUSR1
means to write out data like resolv.conf, or refresh a cache.
It is a subset of what is done for SIGHUP without reloading

View file

@ -1624,7 +1624,7 @@ _mgr_configs_data_clear(NMDnsManager *self)
/*****************************************************************************/
static gboolean
update_dns(NMDnsManager *self, gboolean no_caching, GError **error)
update_dns(NMDnsManager *self, gboolean no_caching, gboolean force_emit, GError **error)
{
NMDnsManagerPrivate *priv = NM_DNS_MANAGER_GET_PRIVATE(self);
const char * nis_domain = NULL;
@ -1816,7 +1816,7 @@ plugin_skip:;
}
/* signal that DNS resolution configs were changed */
if ((do_update || caching) && result == SR_SUCCESS)
if ((do_update || caching || force_emit) && result == SR_SUCCESS)
g_signal_emit(self, signals[CONFIG_CHANGED], 0);
nm_clear_pointer(&priv->config_variant, g_variant_unref);
@ -1924,7 +1924,7 @@ changed:
if (!priv->updates_queue) {
gs_free_error GError *error = NULL;
if (!update_dns(self, FALSE, &error))
if (!update_dns(self, FALSE, FALSE, &error))
_LOGW("could not commit DNS changes: %s", error->message);
}
@ -1965,7 +1965,7 @@ nm_dns_manager_set_hostname(NMDnsManager *self, const char *hostname, gboolean s
if (!priv->updates_queue) {
gs_free_error GError *error = NULL;
if (!update_dns(self, FALSE, &error))
if (!update_dns(self, FALSE, FALSE, &error))
_LOGW("could not commit DNS changes: %s", error->message);
}
}
@ -2012,7 +2012,7 @@ nm_dns_manager_end_updates(NMDnsManager *self, const char *func)
/* Commit all the outstanding changes */
_LOGD("(%s): committing DNS changes (%d)", func, priv->updates_queue);
if (!update_dns(self, FALSE, &error))
if (!update_dns(self, FALSE, FALSE, &error))
_LOGW("could not commit DNS changes: %s", error->message);
memset(priv->prev_hash, 0, sizeof(priv->prev_hash));
@ -2038,7 +2038,7 @@ nm_dns_manager_stop(NMDnsManager *self)
if (priv->dns_touched && priv->plugin && NM_IS_DNS_DNSMASQ(priv->plugin)) {
gs_free_error GError *error = NULL;
if (!update_dns(self, TRUE, &error))
if (!update_dns(self, TRUE, FALSE, &error))
_LOGW("could not commit DNS changes on shutdown: %s", error->message);
priv->dns_touched = FALSE;
@ -2363,7 +2363,7 @@ config_changed_cb(NMConfig * config,
| NM_CONFIG_CHANGE_GLOBAL_DNS_CONFIG)) {
gs_free_error GError *error = NULL;
if (!update_dns(self, FALSE, &error))
if (!update_dns(self, FALSE, TRUE, &error))
_LOGW("could not commit DNS changes: %s", error->message);
}
}