From 4445b8cc78703949c6d357359906089e310c1e69 Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Wed, 23 Jun 2021 11:49:16 -0400 Subject: [PATCH] Fix name resolution for suse hosts/containers Suse uses a strategy with symlinks, adapt the resolv.conf target based on findings from symlink chasing. --- imgutil/imgutil | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/imgutil/imgutil b/imgutil/imgutil index 2d4aa611..30185752 100644 --- a/imgutil/imgutil +++ b/imgutil/imgutil @@ -253,8 +253,17 @@ def exec_root_backend(optargs): installroot = args[0] imgname = os.path.basename(installroot) _mount_constrained_fs(opts, installroot) - _mount('/etc/resolv.conf', os.path.join(installroot, 'etc/resolv.conf'), flags=MS_BIND|MS_RDONLY) - _mount('none', os.path.join(installroot, 'etc/resolv.conf'), flags=MS_RDONLY|MS_REMOUNT|MS_BIND) + sourceresolv = '/etc/resolv.conf' + if os.path.islink(sourceresolv): + sourceresolv = os.readlink(sourceresolv) + dstresolv = os.path.join(installroot, 'etc/resolv.conf') + if os.path.islink(dstresolv): + dstresolv = os.path.join(installroot, os.readlink(dstresolv)[1:]) + if not os.path.exists(dstresolv): + mkdirp(os.path.dirname(dstresolv)) + open(dstresolv, 'w').close() + _mount(sourceresolv, dstresolv, flags=MS_BIND|MS_RDONLY) + _mount('none', dstresolv, flags=MS_RDONLY|MS_REMOUNT|MS_BIND) os.chroot(installroot) os.chdir('/') os.environ['PS1'] = '[\x1b[1m\x1b[4mIMGUTIL EXEC {0}\x1b[0m \W]$ '.format(imgname)