From df3ad26f58d84d5c42989cffa53a27e6039a8fbb Mon Sep 17 00:00:00 2001 From: Ian Wienand Date: Wed, 22 Apr 2020 06:27:03 +1000 Subject: [PATCH] yum-minimal: strip env vars in chroot calls This showed up with dnf in containers when TMPDIR was set; dnf started trying to write to this directory while in the chroot. We already do stripping like this in run_in_target -- but this is a bit of a unique place because it's actually setting up the initial chroot so the target doesn't actually exist yet; so we just hard-code it in place here. Change-Id: If7310cb820846da903bf60daa4486c8bf7cb0136 --- .../elements/yum-minimal/root.d/08-yum-chroot | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/diskimage_builder/elements/yum-minimal/root.d/08-yum-chroot b/diskimage_builder/elements/yum-minimal/root.d/08-yum-chroot index 687760c8..a6a28217 100755 --- a/diskimage_builder/elements/yum-minimal/root.d/08-yum-chroot +++ b/diskimage_builder/elements/yum-minimal/root.d/08-yum-chroot @@ -281,11 +281,19 @@ else _install_pkg_manager yum fi +# sort of like run_in_target; but we're not in a phase where that +# works yet. strip unnecessary external env vars that can cause +# problems. +function _run_chroot { + local cmd="$@" + sudo -E chroot $TARGET_ROOT env -u TMPDIR sh -c "$cmd" +} + # we just installed yum/dnf with "outside" tools (yum/rpm) which # might have created /var/lib/[yum|rpm] (etc) that are slighlty # incompatible. Refresh everything with the in-chroot tools -sudo -E chroot $TARGET_ROOT rpm --rebuilddb -sudo -E chroot $TARGET_ROOT ${YUM} clean all +_run_chroot rpm --rebuilddb +_run_chroot ${YUM} clean all # populate the lang reduction macro in the chroot echo "%_install_langs C:en_US:en_US.UTF-8" | \ @@ -301,8 +309,8 @@ _base_packages+="systemd-udev " # bootstrap the environment within the chroot; bring in new # metadata with an update and install some base packages we need. -sudo -E chroot $TARGET_ROOT ${YUM} -y update -sudo -E chroot $TARGET_ROOT ${YUM} -y \ +_run_chroot ${YUM} -y update +_run_chroot ${YUM} -y \ --setopt=cachedir=/tmp/yum/$ARCH/$DIB_RELEASE \ install ${_base_packages} @@ -319,7 +327,7 @@ echo -e "# This file intentionally left blank\n" | \ echo -e 'LANG="en_US.UTF-8"' | \ sudo tee $TARGET_ROOT/etc/locale.conf # default to UTC -sudo -E chroot $TARGET_ROOT ln -sf /usr/share/zoneinfo/UTC \ +_run_chroot ln -sf /usr/share/zoneinfo/UTC \ /etc/localtime # cleanup