diff options
author | Albert Safin <xzfcpw@gmail.com> | 2019-09-19 15:06:48 +0000 |
---|---|---|
committer | Albert Safin <xzfcpw@gmail.com> | 2019-09-20 02:45:52 +0000 |
commit | cf4e4820f629326928a6b8fd179a3aa5dd6d4773 (patch) | |
tree | ebbdfd21024e282b5711d7386ebe21f3621667d4 | |
parent | d53920a5beb19541ce61107844ab2f5e27c19b44 (diff) |
setup.sh: avoid subshells: type -t in _callImplicitHook
-rw-r--r-- | pkgs/stdenv/generic/setup.sh | 27 |
1 files changed, 12 insertions, 15 deletions
diff --git a/pkgs/stdenv/generic/setup.sh b/pkgs/stdenv/generic/setup.sh index 7e7f8739845b..e25ea735a93c 100644 --- a/pkgs/stdenv/generic/setup.sh +++ b/pkgs/stdenv/generic/setup.sh @@ -73,21 +73,18 @@ _callImplicitHook() { set -u local def="$1" local hookName="$2" - case "$(type -t "$hookName")" in - (function|alias|builtin) - set +u - "$hookName";; - (file) - set +u - source "$hookName";; - (keyword) :;; - (*) if [ -z "${!hookName:-}" ]; then - return "$def"; - else - set +u - eval "${!hookName}" - fi;; - esac + if declare -F "$hookName" > /dev/null; then + set +u + "$hookName" + elif type -p "$hookName" > /dev/null; then + set +u + source "$hookName" + elif [ -n "${!hookName:-}" ]; then + set +u + eval "${!hookName}" + else + return "$def" + fi # `_eval` expects hook to need nounset disable and leave it # disabled anyways, so Ok to to delegate. The alternative of a # return trap is no good because it would affect nested returns. |