ryantimwilson / rpms / systemd

Forked from rpms/systemd a month ago
Clone
Blob Blame History Raw
From b727694500d24d19ac0d7c51c1eb67c281f2f301 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
Date: Fri, 11 Mar 2016 17:06:17 -0500
Subject: [PATCH] resolved: create /etc/resolv.conf symlink at runtime

If the symlink doesn't exists, and we are being started, let's
create it to provie name resolution.

If it exists, do nothing. In particular, if it is a broken symlink,
we cannot really know if the administator configured it to point to
a location used by some service that hasn't started yet, so we
don't touch it in that case either.

https://bugzilla.redhat.com/show_bug.cgi?id=1313085
---
 src/resolve/resolved.c | 4 ++++
 tmpfiles.d/etc.conf.m4 | 3 ---
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/src/resolve/resolved.c b/src/resolve/resolved.c
index a4cda0b5ef..68bca80777 100644
--- a/src/resolve/resolved.c
+++ b/src/resolve/resolved.c
@@ -71,6 +71,10 @@ int main(int argc, char *argv[]) {
         /* Drop privileges, but only if we have been started as root. If we are not running as root we assume all
          * privileges are already dropped. */
         if (getuid() == 0) {
+                r = symlink("../run/systemd/resolve/resolv.conf", "/etc/resolv.conf");
+                if (r < 0 && errno != EEXIST)
+                        log_warning_errno(errno,
+                                          "Could not create /etc/resolv.conf symlink: %m");
 
                 /* Drop privileges, but keep three caps. Note that we drop those too, later on (see below) */
                 r = drop_privileges(uid, gid,
diff --git a/tmpfiles.d/etc.conf.m4 b/tmpfiles.d/etc.conf.m4
index df8d42101c..928105ea8d 100644
--- a/tmpfiles.d/etc.conf.m4
+++ b/tmpfiles.d/etc.conf.m4
@@ -13,9 +13,6 @@ L+ /etc/mtab - - - - ../proc/self/mounts
 m4_ifdef(`HAVE_SMACK_RUN_LABEL',
 t /etc/mtab - - - - security.SMACK64=_
 )m4_dnl
-m4_ifdef(`ENABLE_RESOLVE',
-L! /etc/resolv.conf - - - - ../run/systemd/resolve/stub-resolv.conf
-)m4_dnl
 C /etc/nsswitch.conf - - - -
 m4_ifdef(`HAVE_PAM',
 C /etc/pam.d - - - -