From 60031906b48a619fc8cdbe07ea11cee78a5dd355 Mon Sep 17 00:00:00 2001 From: Rob Norris Date: Sat, 15 Feb 2025 14:32:10 +1100 Subject: [PATCH] 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 Reviewed-by: Tony Hutter Reviewed-by: Tino Reichardt Reviewed-by: Igor Kozhukhov --- scripts/zfs-tests.sh | 7 +++++++ tests/test-runner/bin/test-runner.py.in | 10 +++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/scripts/zfs-tests.sh b/scripts/zfs-tests.sh index ae62f8f2ae83..4a874119e85a 100755 --- a/scripts/zfs-tests.sh +++ b/scripts/zfs-tests.sh @@ -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" diff --git a/tests/test-runner/bin/test-runner.py.in b/tests/test-runner/bin/test-runner.py.in index 2538f99caa9e..abe27d17d755 100755 --- a/tests/test-runner/bin/test-runner.py.in +++ b/tests/test-runner/bin/test-runner.py.in @@ -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):