mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-01-09 17:00:40 +01:00
dns: follow resolv.conf if it is a symlink for 'rc-manager=file'
Until before 1.2.0, NetworkManager would always write resolv.conf as file, but if /etc/resolv.conf was a symlink, it would follow the link instead of replacing it with a file ([1], [2]). With 1.2.0, we initially dropped that behavior and added a new 'rc-manager=none' which writes resolv.conf to /var/run/NetworkManager and symlinks resolv.conf [3]. In case resolv.conf being already a symlink to another target, it would not be replaced [4]. Later, we added 'rc-manager=file', which always writes /etc/resolv.conf as file [5]. With 1.4.0, we will rename 'rc-manager=none' to 'rc-manager=symlink' [6]. This commit now fixes 'rc-manager=file' to restores the pre-1.2 behavior and follow symlinks. [1]5761e328b8[2] https://bugs.launchpad.net/ubuntu/+source/network-manager/+bug/324233 [3]4805be2ed2[4]583568e12f[5]288799713d[6]cd6a469668https://github.com/NetworkManager/NetworkManager/pull/7 (cherry picked from commit718fd22436)
This commit is contained in:
parent
0b4ea9cbf1
commit
486fc0eade
2 changed files with 13 additions and 5 deletions
|
|
@ -324,7 +324,9 @@ no-auto-default=*
|
|||
<filename>/etc/resolv.conf</filename> to its private
|
||||
resolv.conf file in the runtime state directory.</para>
|
||||
<para><literal>file</literal>: NetworkManager will write
|
||||
<filename>/etc/resolv.conf</filename> as file.</para>
|
||||
<filename>/etc/resolv.conf</filename> as file. If it finds
|
||||
a symlink, it will follow the symlink and update the target
|
||||
instead.</para>
|
||||
<para><literal>resolvconf</literal>: NetworkManager will run
|
||||
resolvconf to update the DNS configuration.</para>
|
||||
<para><literal>netconfig</literal>: NetworkManager will run
|
||||
|
|
|
|||
|
|
@ -674,6 +674,8 @@ update_resolv_conf (NMDnsManager *self,
|
|||
gs_free char *content = NULL;
|
||||
SpawnResult write_file_result = SR_SUCCESS;
|
||||
int errsv;
|
||||
const char *rc_path = _PATH_RESCONF;
|
||||
nm_auto_free char *rc_path_real = NULL;
|
||||
|
||||
/* If we are not managing /etc/resolv.conf and it points to
|
||||
* MY_RESOLV_CONF, don't write the private DNS configuration to
|
||||
|
|
@ -697,18 +699,22 @@ update_resolv_conf (NMDnsManager *self,
|
|||
if (rc_manager == NM_DNS_MANAGER_RESOLV_CONF_MAN_FILE) {
|
||||
GError *local = NULL;
|
||||
|
||||
rc_path_real = realpath (rc_path, NULL);
|
||||
if (rc_path_real)
|
||||
rc_path = rc_path_real;
|
||||
|
||||
/* we first write to /etc/resolv.conf directly. If that fails,
|
||||
* we still continue to write to runstatedir but remember the
|
||||
* error. */
|
||||
if (!g_file_set_contents (_PATH_RESCONF, content, -1, &local)) {
|
||||
if (!g_file_set_contents (rc_path, content, -1, &local)) {
|
||||
_LOGT ("update-resolv-conf: write to %s failed (rc-manager=%s, %s)",
|
||||
_PATH_RESCONF, _rc_manager_to_string (rc_manager), local->message);
|
||||
rc_path, _rc_manager_to_string (rc_manager), local->message);
|
||||
write_file_result = SR_ERROR;
|
||||
g_propagate_error (error, local);
|
||||
error = NULL;
|
||||
} else {
|
||||
_LOGT ("update-resolv-conf: write to %s succeeded (rc-manager=%s)",
|
||||
_PATH_RESCONF, _rc_manager_to_string (rc_manager));
|
||||
rc_path, _rc_manager_to_string (rc_manager));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -766,7 +772,7 @@ update_resolv_conf (NMDnsManager *self,
|
|||
|
||||
if (rc_manager == NM_DNS_MANAGER_RESOLV_CONF_MAN_FILE) {
|
||||
_LOGT ("update-resolv-conf: write internal file %s succeeded (rc-manager=%s)",
|
||||
_PATH_RESCONF, _rc_manager_to_string (rc_manager));
|
||||
rc_path, _rc_manager_to_string (rc_manager));
|
||||
return write_file_result;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue