Colin Walters a1b71b
From 7824f773110be8a0cecb89f650e13db03b58d1e1 Mon Sep 17 00:00:00 2001
Colin Walters a1b71b
From: Colin Walters <walters@verbum.org>
Colin Walters a1b71b
Date: Mon, 7 Jul 2014 08:27:43 -0400
Colin Walters a1b71b
Subject: [PATCH] resolved: Move symlink creation from tmpfiles to daemon
Colin Walters a1b71b
 runtime
Colin Walters a1b71b
Colin Walters a1b71b
At least Fedora right now doesn't by default use resolved; the service
Colin Walters a1b71b
is disabled by default in the 90-default.preset file.
Colin Walters a1b71b
Colin Walters a1b71b
The change to unconditionally create the resolv.conf symlink broke
Colin Walters a1b71b
Anaconda and related tools (lorax) which expect it to be a regular
Colin Walters a1b71b
file.  In particular, Anaconda expects to be able to persist
Colin Walters a1b71b
networking state from the installation environment to the target
Colin Walters a1b71b
system.
Colin Walters a1b71b
Colin Walters a1b71b
A simple fix is to just have resolved itself create it at runtime.
Colin Walters a1b71b
---
Colin Walters a1b71b
 src/resolve/resolved-manager.c | 12 +++++++++++-
Colin Walters a1b71b
 tmpfiles.d/etc.conf            |  1 -
Colin Walters a1b71b
 2 files changed, 11 insertions(+), 2 deletions(-)
Colin Walters a1b71b
Colin Walters a1b71b
diff --git a/src/resolve/resolved-manager.c b/src/resolve/resolved-manager.c
Colin Walters a1b71b
index 3ed0603..1a6b3ac 100644
Colin Walters a1b71b
--- a/src/resolve/resolved-manager.c
Colin Walters a1b71b
+++ b/src/resolve/resolved-manager.c
Colin Walters a1b71b
@@ -192,9 +192,11 @@ static void append_dns(FILE *f, void *dns, unsigned char family, unsigned *count
Colin Walters a1b71b
 
Colin Walters a1b71b
 int manager_update_resolv_conf(Manager *m) {
Colin Walters a1b71b
         const char *path = "/run/systemd/resolve/resolv.conf";
Colin Walters a1b71b
+        const char *etcresolv_path = "/etc/resolv.conf";
Colin Walters a1b71b
         _cleanup_free_ char *temp_path = NULL;
Colin Walters a1b71b
         _cleanup_fclose_ FILE *f = NULL;
Colin Walters a1b71b
-         _cleanup_free_ unsigned *indices = NULL;
Colin Walters a1b71b
+        _cleanup_free_ unsigned *indices = NULL;
Colin Walters a1b71b
+        struct stat st;
Colin Walters a1b71b
         Address *address;
Colin Walters a1b71b
         unsigned count = 0;
Colin Walters a1b71b
         int n, r, i;
Colin Walters a1b71b
@@ -270,6 +272,14 @@ int manager_update_resolv_conf(Manager *m) {
Colin Walters a1b71b
                 return r;
Colin Walters a1b71b
         }
Colin Walters a1b71b
 
Colin Walters a1b71b
+        /* Create /etc/resolv.conf as a link only if it doesn't exist */
Colin Walters a1b71b
+        if (lstat(etcresolv_path, &st) < 0) {
Colin Walters a1b71b
+                r = symlink(path, etcresolv_path);
Colin Walters a1b71b
+                if (r < 0 && errno != EEXIST) {
Colin Walters a1b71b
+                        return r;
Colin Walters a1b71b
+                }
Colin Walters a1b71b
+        }
Colin Walters a1b71b
+
Colin Walters a1b71b
         return 0;
Colin Walters a1b71b
 }
Colin Walters a1b71b
 
Colin Walters a1b71b
diff --git a/tmpfiles.d/etc.conf b/tmpfiles.d/etc.conf
Colin Walters a1b71b
index e809dff..4937719 100644
Colin Walters a1b71b
--- a/tmpfiles.d/etc.conf
Colin Walters a1b71b
+++ b/tmpfiles.d/etc.conf
Colin Walters a1b71b
@@ -10,4 +10,3 @@
Colin Walters a1b71b
 L /etc/os-release - - - - ../usr/lib/os-release
Colin Walters a1b71b
 L /etc/localtime - - - - ../usr/share/zoneinfo/UTC
Colin Walters a1b71b
 L+ /etc/mtab - - - - ../proc/self/mounts
Colin Walters a1b71b
-L /etc/resolv.conf - - - - ../run/systemd/resolve/resolv.conf
Colin Walters a1b71b
-- 
Colin Walters a1b71b
1.8.3.1
Colin Walters a1b71b