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 <john.kennedy@delphix.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Ryan Moeller <ryan@iXsystems.com>
Closes #11185
This commit is contained in:
Ryan Moeller 2021-03-11 15:01:58 -05:00 committed by Tony Hutter
parent 5a397fda09
commit acb4e7b0e1
2 changed files with 13 additions and 8 deletions

View File

@ -33,6 +33,7 @@ export SYSTEM_FILES_COMMON='arp
du du
echo echo
egrep egrep
env
expr expr
false false
file file
@ -117,7 +118,6 @@ export SYSTEM_FILES_FREEBSD='chflags
compress compress
diskinfo diskinfo
dumpon dumpon
env
fsck fsck
getextattr getextattr
gpart gpart

View File

@ -41,7 +41,7 @@
# PATH may have been modified by sudo's secure_path behavior. # PATH may have been modified by sudo's secure_path behavior.
# #
if [ -n "$STF_PATH" ]; then if [ -n "$STF_PATH" ]; then
PATH="$STF_PATH" export PATH="$STF_PATH"
fi fi
# #
@ -2766,10 +2766,6 @@ function add_user #<group_name> <user_name> <basedir>
;; ;;
esac 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 return 0
} }
@ -3393,8 +3389,17 @@ function user_run
typeset user=$1 typeset user=$1
shift shift
log_note "user:$user $@" log_note "user: $user"
eval su - \$user -c \"$@\" > $TEST_BASE_DIR/out 2>$TEST_BASE_DIR/err 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
} }
# #