Skip to content

Commit

Permalink
ZTS: Use ksh and current environment for user_run
Browse files Browse the repository at this point in the history
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 openzfs#11185
  • Loading branch information
Ryan Moeller authored and adamdmoss committed Apr 10, 2021
1 parent 024ba45 commit 59241f2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
2 changes: 1 addition & 1 deletion tests/zfs-tests/include/commands.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export SYSTEM_FILES_COMMON='arp
du
echo
egrep
env
expr
false
file
Expand Down Expand Up @@ -117,7 +118,6 @@ export SYSTEM_FILES_FREEBSD='chflags
compress
diskinfo
dumpon
env
fsck
getextattr
gpart
Expand Down
19 changes: 12 additions & 7 deletions tests/zfs-tests/include/libtest.shlib
Original file line number Diff line number Diff line change
Expand Up @@ -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

#
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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
}

#
Expand Down

0 comments on commit 59241f2

Please sign in to comment.