From 20b43802e88ac06d7dd2b5cc82fc43a4fe829fb8 Mon Sep 17 00:00:00 2001 From: Dan Winship Date: Thu, 19 Dec 2013 09:54:42 -0500 Subject: [PATCH] dns-manager: Don't try to manage immutable /etc/resolv.conf If /etc/resolv.conf has the immutable flag set, then behave as though "dns=none" was specified (rather than repeatedly trying and failing to update it). --- src/dns-manager/nm-dns-manager.c | 33 +++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/src/dns-manager/nm-dns-manager.c b/src/dns-manager/nm-dns-manager.c index 6e83935d0..af5f95b58 100644 --- a/src/dns-manager/nm-dns-manager.c +++ b/src/dns-manager/nm-dns-manager.c @@ -24,8 +24,13 @@ #include "config.h" #include +#include #include #include +#include +#include + +#include #include #include @@ -1056,13 +1061,24 @@ nm_dns_manager_error_quark (void) } static void -nm_dns_manager_init (NMDnsManager *self) +init_resolv_conf_mode (NMDnsManager *self) { NMDnsManagerPrivate *priv = NM_DNS_MANAGER_GET_PRIVATE (self); const char *mode; + int fd, flags; - /* Set the initial hash */ - compute_hash (self, NM_DNS_MANAGER_GET_PRIVATE (self)->hash); + fd = open (_PATH_RESCONF, O_RDONLY); + if (fd != -1) { + if (ioctl (fd, FS_IOC_GETFLAGS, &flags) == -1) + flags = 0; + close (fd); + + if (flags & FS_IMMUTABLE_FL) { + nm_log_info (LOGD_DNS, "DNS: " _PATH_RESCONF " is immutable; not managing"); + priv->resolv_conf_mode = NM_DNS_MANAGER_RESOLV_CONF_UNMANAGED; + return; + } + } mode = nm_config_get_dns_mode (nm_config_get ()); if (!g_strcmp0 (mode, "none")) { @@ -1076,6 +1092,17 @@ nm_dns_manager_init (NMDnsManager *self) if (mode && g_strcmp0 (mode, "default") != 0) nm_log_warn (LOGD_DNS, "Unknown DNS mode '%s'", mode); } +} + +static void +nm_dns_manager_init (NMDnsManager *self) +{ + NMDnsManagerPrivate *priv = NM_DNS_MANAGER_GET_PRIVATE (self); + + /* Set the initial hash */ + compute_hash (self, NM_DNS_MANAGER_GET_PRIVATE (self)->hash); + + init_resolv_conf_mode (self); if (priv->plugin) { nm_log_info (LOGD_DNS, "DNS: loaded plugin %s", nm_dns_plugin_get_name (priv->plugin));