ZTS: zfs-tests: set TMPDIR to FILEDIR

Many tests use mktemp to create temporary files and dirs, which will
usually put them in /tmp unless instructed otherwise. This had led to
many tests trying to give mktemp a useful temp path in ad-hoc ways, and
others just using it directly without knowing they're potentially
leaving stuff lying around.

So we set TMPDIR to FILEDIR, which makes the simplest uses of mktemp put
things in the wanted work dir.

Included here is a hack to get TMPDIR into the test. If a test has to be
run as a different user (most of them), it is run through sudo. ld.so
from glibc will not pass TMPDIR to a setuid program, so instead we
re-set TMPDIR after sudo before running the target command.

Sponsored-by: https://despairlabs.com/sponsor/
Signed-off-by: Rob Norris <robn@despairlabs.com>
Reviewed-by: Tony Hutter <hutter2@llnl.gov>
Reviewed-by: Tino Reichardt <milky-zfs@mcmilk.de>
Reviewed-by: Igor Kozhukhov <igor@dilos.org>
This commit is contained in:
Rob Norris 2025-02-15 14:32:10 +11:00 committed by Tony Hutter
parent 2c897e0666
commit 60031906b4
2 changed files with 16 additions and 1 deletions

View File

@ -718,6 +718,12 @@ if [ -e /sys/module/zfs/parameters/zfs_dbgmsg_enable ]; then
sudo sh -c "echo 0 >/proc/spl/kstat/zfs/dbgmsg"
fi
#
# Set TMPDIR. Some tests run mktemp, and we want those files contained to
# the work dir the same as any other.
#
export TMPDIR="$FILEDIR"
msg
msg "--- Configuration ---"
msg "Runfiles: $RUNFILES"
@ -725,6 +731,7 @@ msg "STF_TOOLS: $STF_TOOLS"
msg "STF_SUITE: $STF_SUITE"
msg "STF_PATH: $STF_PATH"
msg "FILEDIR: $FILEDIR"
msg "TMPDIR: $TMPDIR"
msg "FILES: $FILES"
msg "LOOPBACKS: $LOOPBACKS"
msg "DISKS: $DISKS"

View File

@ -238,7 +238,15 @@ User: %s
if os.path.isfile(cmd+'.sh') and os.access(cmd+'.sh', os.X_OK):
cmd += '.sh'
ret = '%s -E -u %s %s' % (SUDO, user, cmd)
# glibc (at least) will not pass TMPDIR through to setuid programs.
# if set, arrange for it to be reset before running the target cmd
tmpdir = os.getenv('TMPDIR')
if tmpdir:
tmpdirarg = 'env TMPDIR=%s' % tmpdir
else:
tmpdirarg = ''
ret = '%s -E -u %s %s %s' % (SUDO, user, tmpdirarg, cmd)
return ret.split(' ')
def collect_output(self, proc, debug=False):