From 1d42e4afcba38b1da14de40b6230e6901d62d863 Mon Sep 17 00:00:00 2001
From: Steven Armstrong <steven@icarus.ethz.ch>
Date: Mon, 4 Apr 2016 21:58:43 +0200
Subject: [PATCH] bind mount /etc/resolv.conf instead of overwriting/removing

Signed-off-by: Steven Armstrong <steven@icarus.ethz.ch>
---
 cdist/conf/type/__chroot_mount/gencode-remote  | 5 ++---
 cdist/conf/type/__chroot_umount/gencode-remote | 4 +++-
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/cdist/conf/type/__chroot_mount/gencode-remote b/cdist/conf/type/__chroot_mount/gencode-remote
index 6d855f41..14da81ee 100755
--- a/cdist/conf/type/__chroot_mount/gencode-remote
+++ b/cdist/conf/type/__chroot_mount/gencode-remote
@@ -42,7 +42,6 @@ mountpoint -q "${chroot}/dev/pts" \
 mountpoint -q "${chroot}/tmp" \
    || mount -t tmpfs -o mode=1777,strictatime,nodev,nosuid tmpfs "${chroot}/tmp"
 
-if [ ! -f "${chroot}/etc/resolv.conf" ]; then
-   cp /etc/resolv.conf "${chroot}/etc/"
-fi
+mountpoint -q "${chroot}/etc/resolv.conf" \
+   || mount --bind -o ro /etc/resolv.conf "${chroot}/etc/resolv.conf"
 DONE
diff --git a/cdist/conf/type/__chroot_umount/gencode-remote b/cdist/conf/type/__chroot_umount/gencode-remote
index caf2c40c..ad06a0a2 100755
--- a/cdist/conf/type/__chroot_umount/gencode-remote
+++ b/cdist/conf/type/__chroot_umount/gencode-remote
@@ -26,7 +26,9 @@ umount -l "${chroot}/dev/pts"
 umount -l "${chroot}/dev"
 umount -l "${chroot}/sys"
 umount -l "${chroot}/proc"
-rm -f "${chroot}/etc/resolv.conf"
+if mountpoint -q "${chroot}/etc/resolv.conf"; then
+   umount "${chroot}/etc/resolv.conf"
+fi
 if [ -d "${chroot}/etc/resolvconf/resolv.conf.d" ]; then
    # ensure /etc/resolvconf/resolv.conf.d/tail is not linked to \
    # e.g. /etc/resolvconf/resolv.conf.d/original