Skip to content

Commit 63821e6

Browse files
author
Ryan Moeller
committed
ZTS: Use ksh and current environment for user_run
The current user_run often does not work as expected. Commands are run in a different shell, with a different environment, and all output is discarded. Simplify user_run to retain the current environment, eliminate eval, and feed the command string into ksh. Enhance the logging for user_run so we can see out and err. Reviewed-by: John Kennedy <[email protected]> Reviewed-by: Brian Behlendorf <[email protected]> Signed-off-by: Ryan Moeller <[email protected]> Closes openzfs#11185
1 parent ca2e104 commit 63821e6

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

tests/zfs-tests/include/commands.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export SYSTEM_FILES_COMMON='arp
3333
du
3434
echo
3535
egrep
36+
env
3637
expr
3738
false
3839
file
@@ -117,7 +118,6 @@ export SYSTEM_FILES_FREEBSD='chflags
117118
compress
118119
diskinfo
119120
dumpon
120-
env
121121
fsck
122122
getextattr
123123
gpart

tests/zfs-tests/include/libtest.shlib

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
# PATH may have been modified by sudo's secure_path behavior.
4242
#
4343
if [ -n "$STF_PATH" ]; then
44-
PATH="$STF_PATH"
44+
export PATH="$STF_PATH"
4545
fi
4646

4747
#
@@ -2766,10 +2766,6 @@ function add_user #<group_name> <user_name> <basedir>
27662766
;;
27672767
esac
27682768

2769-
echo "export PATH=\"$STF_PATH\"" >>$basedir/$user/.profile
2770-
echo "export PATH=\"$STF_PATH\"" >>$basedir/$user/.bash_profile
2771-
echo "export PATH=\"$STF_PATH\"" >>$basedir/$user/.login
2772-
27732769
return 0
27742770
}
27752771

@@ -3393,8 +3389,17 @@ function user_run
33933389
typeset user=$1
33943390
shift
33953391

3396-
log_note "user:$user $@"
3397-
eval su - \$user -c \"$@\" > $TEST_BASE_DIR/out 2>$TEST_BASE_DIR/err
3392+
log_note "user: $user"
3393+
log_note "cmd: $*"
3394+
3395+
typeset out=$TEST_BASE_DIR/out
3396+
typeset err=$TEST_BASE_DIR/err
3397+
3398+
sudo -Eu $user env PATH="$PATH" ksh <<<"$*" >$out 2>$err
3399+
typeset res=$?
3400+
log_note "out: $(<$out)"
3401+
log_note "err: $(<$err)"
3402+
return $res
33983403
}
33993404

34003405
#

0 commit comments

Comments
 (0)