From c740b01dc8de65c587ac97f219975840a56f34e2 Mon Sep 17 00:00:00 2001 From: Johannes Schauer Marin Rodrigues Date: Thu, 4 Feb 2021 17:46:39 +0100 Subject: [PATCH] unset TMPDIR in hooks because there is no value that works inside as well as outside the chroot --- mmdebstrap | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/mmdebstrap b/mmdebstrap index 70c436d..59ed356 100755 --- a/mmdebstrap +++ b/mmdebstrap @@ -1212,10 +1212,16 @@ sub run_hooks { } my @env_opts = (); - # There is no need to unset TMPDIR because we already have set it ourselves - # to "$options->{root}/tmp" in run_setup(). This is to have a writable - # TMPDIR even in unshare mode. - # + # At this point TMPDIR is set to "$options->{root}/tmp". This is to have a + # writable TMPDIR even in unshare mode. But if TMPDIR is still set when + # running hooks, then every hook script calling chroot, will have to wrap + # that into an "env --unset=TMPDIR". To avoid this, we unset TMPDIR here. + # If the hook script needs a writable TMPDIR, then it can always use /tmp + # inside the chroot. This is also why we do not set a new MMDEBSTRAP_TMPDIR + # environment variable. + if (defined $ENV{TMPDIR} && $ENV{TMPDIR} ne "") { + push @env_opts, '--unset=TMPDIR'; + } # The APT_CONFIG variable, if set, will confuse any manual calls to # apt-get. If you want to use the same config used by mmdebstrap, the # original value is stored in MMDEBSTRAP_APT_CONFIG.