Skip to content

Commit

Permalink
ZTS: zfs-tests: set TMPDIR to FILEDIR
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reviewed-by: Tony Hutter <[email protected]>
Reviewed-by: Tino Reichardt <[email protected]>
Reviewed-by: Igor Kozhukhov <[email protected]>
  • Loading branch information
robn authored and tonyhutter committed Feb 27, 2025
1 parent 2c897e0 commit 6003190
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
7 changes: 7 additions & 0 deletions scripts/zfs-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -718,13 +718,20 @@ 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"
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"
Expand Down
10 changes: 9 additions & 1 deletion tests/test-runner/bin/test-runner.py.in
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 6003190

Please sign in to comment.