summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKerin Millar <kfm@plushkava.net>2024-08-08 02:27:52 +0100
committerSam James <sam@gentoo.org>2024-08-11 11:10:58 +0100
commit5a34ca0e2001d70bc2037fc2226ad510e26a3349 (patch)
tree2cd215db128657d7c3f8e91c39a6159c7e1df12b /functions
parenttest-functions: test for simple commands persisting environmental changes (diff)
downloadgentoo-functions-5a34ca0e2001d70bc2037fc2226ad510e26a3349.tar.gz
gentoo-functions-5a34ca0e2001d70bc2037fc2226ad510e26a3349.tar.bz2
gentoo-functions-5a34ca0e2001d70bc2037fc2226ad510e26a3349.zip
Avoid unspecified behaviour around simple commands in general
As mentioned by the previous commit, the Shell Command Language leaves it unspecified as to whether variable assignments affecting the execution environment of a simple command charged with executing a function (that is not the implementation of a standard utility) shall persist after the completion of the function. It transpires that modifying gentoo-functions so as to steer clear of this pitfall isn't particularly difficult so this commit does exactly that. Most of the changes are in test-functions but functions/rc.sh also required some minor changes regarding the use of the GENFUN_CALLER variable. With this, loksh very nearly passes the test suite. There is one individual test that continues to fail, although it looks as though that may be caused by a genuine bug on the part of the shell. That will require investigating in its own right. Signed-off-by: Kerin Millar <kfm@plushkava.net> Signed-off-by: Sam James <sam@gentoo.org>
Diffstat (limited to 'functions')
-rw-r--r--functions/rc.sh16
1 files changed, 11 insertions, 5 deletions
diff --git a/functions/rc.sh b/functions/rc.sh
index 12444d1..0c14035 100644
--- a/functions/rc.sh
+++ b/functions/rc.sh
@@ -49,7 +49,8 @@ ebegin()
#
eend()
{
- GENFUN_CALLER=${GENFUN_CALLER:-eend} _eend eerror "$@"
+ : "${genfun_caller:=eend}"
+ _eend eerror "$@"
}
#
@@ -161,7 +162,8 @@ ewarnn()
#
ewend()
{
- GENFUN_CALLER=${GENFUN_CALLER:-ewend} _eend ewarn "$@"
+ : "${genfun_caller:=ewend}"
+ _eend ewarn "$@"
}
#
@@ -240,7 +242,8 @@ done
veend()
{
if yesno "${EINFO_VERBOSE}"; then
- GENFUN_CALLER=veend eend "$@"
+ genfun_caller=veend
+ eend "$@"
elif [ "$#" -gt 0 ] && { ! is_int "$1" || [ "$1" -lt 0 ]; }; then
_warn_for_args veend "$1"
false
@@ -252,7 +255,8 @@ veend()
vewend()
{
if yesno "${EINFO_VERBOSE}"; then
- GENFUN_CALLER=vewend ewend "$@"
+ genfun_caller=vewend
+ ewend "$@"
elif [ "$#" -gt 0 ] && { ! is_int "$1" || [ "$1" -lt 0 ]; }; then
_warn_for_args vewend "$1"
false
@@ -311,7 +315,7 @@ _eend()
if [ "$#" -eq 0 ]; then
retval=0
elif ! is_int "$1" || [ "$1" -lt 0 ]; then
- _warn_for_args "${GENFUN_CALLER}" "$1"
+ _warn_for_args "${genfun_caller}" "$1"
retval=1
msg=
else
@@ -320,6 +324,8 @@ _eend()
msg=$*
fi
+ genfun_caller=
+
if [ "${retval}" -ne 0 ]; then
# If a message was given, print it with the specified function.
if _is_visible "${msg}"; then