diff options
author | Beniamino Galvani <bgalvani@redhat.com> | 2015-04-12 18:41:58 +0200 |
---|---|---|
committer | Beniamino Galvani <bgalvani@redhat.com> | 2015-04-12 20:41:37 +0200 |
commit | 8f54b5cfc3ac754f4425b901df667beca3068639 (patch) | |
tree | db5a23263bf4fbce806c41657b7494c96a42f1a3 | |
parent | 62f40bade074ac8e555730957149d0888a2b7715 (diff) | |
download | NetworkManager-bg/wip/resolv-conf.tar.gz |
dns: always write resolv.conf in runtime directorybg/wip/resolv-conf
-rw-r--r-- | src/dns-manager/nm-dns-manager.c | 57 |
1 files changed, 41 insertions, 16 deletions
diff --git a/src/dns-manager/nm-dns-manager.c b/src/dns-manager/nm-dns-manager.c index 490a4cd1db..b9424d3a6b 100644 --- a/src/dns-manager/nm-dns-manager.c +++ b/src/dns-manager/nm-dns-manager.c @@ -452,13 +452,33 @@ dispatch_resolvconf (char **searches, static gboolean update_resolv_conf (char **searches, char **nameservers, - GError **error) + GError **error, + gboolean create_link) { FILE *f; struct stat st; g_return_val_if_fail (error != NULL, FALSE); + /* If we are not managing /etc/resolv.conf but the link to + * MY_RESOLV_CONF already exists, don't write the new DNS + * configuration to MY_RESOLV_CONF otherwise we would overwrite + * the changes done by some external program. + */ + if (!create_link) { + char *path = g_file_read_link (_PATH_RESCONF, NULL); + gboolean ours = !g_strcmp0 (path, MY_RESOLV_CONF); + + nm_log_dbg (LOGD_DNS, _PATH_RESCONF " points to: %s", path); + g_free (path); + + /* Since we are not updating system-wide resolv.conf, there's no + * point in returning an error here + */ + if (ours) + return TRUE; + } + if ((f = fopen (MY_RESOLV_CONF_TMP, "w")) == NULL) { g_set_error (error, NM_MANAGER_ERROR, @@ -498,6 +518,9 @@ update_resolv_conf (char **searches, return FALSE; } + if (!create_link) + return TRUE; + /* Don't overwrite a symbolic link unless it points to MY_RESOLV_CONF. */ if (lstat (_PATH_RESCONF, &st) != -1) { /* Don't overwrite a symbolic link. */ @@ -654,18 +677,19 @@ update_dns (NMDnsManager *self, char **nameservers = NULL; char **nis_servers = NULL; int num, i, len; - gboolean success = FALSE, caching = FALSE; + gboolean success = FALSE, caching = FALSE, update = TRUE; g_return_val_if_fail (!error || !*error, FALSE); priv = NM_DNS_MANAGER_GET_PRIVATE (self); - if (priv->resolv_conf_mode == NM_DNS_MANAGER_RESOLV_CONF_UNMANAGED) - return TRUE; - - priv->dns_touched = TRUE; - - nm_log_dbg (LOGD_DNS, "updating resolv.conf"); + if (priv->resolv_conf_mode == NM_DNS_MANAGER_RESOLV_CONF_UNMANAGED) { + update = FALSE; + nm_log_dbg (LOGD_DNS, "not updating resolv.conf"); + } else { + priv->dns_touched = TRUE; + nm_log_dbg (LOGD_DNS, "updating resolv.conf"); + } /* Update hash with config we're applying */ compute_hash (self, priv->hash); @@ -754,7 +778,7 @@ update_dns (NMDnsManager *self, nis_domain = rc.nis_domain; /* Let any plugins do their thing first */ - if (priv->plugin) { + if (update && priv->plugin) { NMDnsPlugin *plugin = priv->plugin; const char *plugin_name = nm_dns_plugin_get_name (plugin); GSList *vpn_configs = NULL, *dev_configs = NULL, *other_configs = NULL; @@ -802,19 +826,20 @@ update_dns (NMDnsManager *self, nameservers[0] = g_strdup ("127.0.0.1"); } + if (update) { #ifdef RESOLVCONF_PATH - success = dispatch_resolvconf (searches, nameservers, error); + success = dispatch_resolvconf (searches, nameservers, error); #endif #ifdef NETCONFIG_PATH - if (success == FALSE) { - success = dispatch_netconfig (searches, nameservers, - nis_domain, nis_servers, error); - } + if (success == FALSE) { + success = dispatch_netconfig (searches, nameservers, + nis_domain, nis_servers, error); + } #endif + } - if (success == FALSE) - success = update_resolv_conf (searches, nameservers, error); + success = update_resolv_conf (searches, nameservers, error, update && !success); /* signal that resolv.conf was changed */ if (success) |