diff options
author | Ryan Moeller <[email protected]> | 2021-03-11 15:01:58 -0500 |
---|---|---|
committer | Brian Behlendorf <[email protected]> | 2021-03-12 16:17:01 -0800 |
commit | e0b53a5dbbfdf8f7cb85bfa7f3c4f9650bc590ec (patch) | |
tree | 7fdfa4faa65ce70028166be16dd4f9dcbed032e2 /tests | |
parent | e464f7c7cc1efb6a0bcae70f77bec13fc531cd20 (diff) |
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 #11185
Diffstat (limited to 'tests')
-rw-r--r-- | tests/zfs-tests/include/commands.cfg | 2 | ||||
-rw-r--r-- | tests/zfs-tests/include/libtest.shlib | 19 |
2 files changed, 13 insertions, 8 deletions
diff --git a/tests/zfs-tests/include/commands.cfg b/tests/zfs-tests/include/commands.cfg index a43ddd016..0db9724ee 100644 --- a/tests/zfs-tests/include/commands.cfg +++ b/tests/zfs-tests/include/commands.cfg @@ -33,6 +33,7 @@ export SYSTEM_FILES_COMMON='arp du echo egrep + env expr false file @@ -117,7 +118,6 @@ export SYSTEM_FILES_FREEBSD='chflags compress diskinfo dumpon - env fsck getextattr gpart diff --git a/tests/zfs-tests/include/libtest.shlib b/tests/zfs-tests/include/libtest.shlib index d494eda55..bd77bae7d 100644 --- a/tests/zfs-tests/include/libtest.shlib +++ b/tests/zfs-tests/include/libtest.shlib @@ -41,7 +41,7 @@ # PATH may have been modified by sudo's secure_path behavior. # if [ -n "$STF_PATH" ]; then - PATH="$STF_PATH" + export PATH="$STF_PATH" fi # @@ -2766,10 +2766,6 @@ function add_user #<group_name> <user_name> <basedir> ;; esac - echo "export PATH=\"$STF_PATH\"" >>$basedir/$user/.profile - echo "export PATH=\"$STF_PATH\"" >>$basedir/$user/.bash_profile - echo "export PATH=\"$STF_PATH\"" >>$basedir/$user/.login - return 0 } @@ -3393,8 +3389,17 @@ function user_run typeset user=$1 shift - log_note "user:$user $@" - eval su - \$user -c \"$@\" > $TEST_BASE_DIR/out 2>$TEST_BASE_DIR/err + log_note "user: $user" + log_note "cmd: $*" + + typeset out=$TEST_BASE_DIR/out + typeset err=$TEST_BASE_DIR/err + + sudo -Eu $user env PATH="$PATH" ksh <<<"$*" >$out 2>$err + typeset res=$? + log_note "out: $(<$out)" + log_note "err: $(<$err)" + return $res } # |