The branch main has been updated by sjg:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=203027b2d5dc89fec3a0a7eee195a11cb394587f

commit 203027b2d5dc89fec3a0a7eee195a11cb394587f
Author:     Simon J. Gerraty <s...@freebsd.org>
AuthorDate: 2024-12-31 18:47:06 +0000
Commit:     Simon J. Gerraty <s...@freebsd.org>
CommitDate: 2024-12-31 18:47:06 +0000

    Update libexec/rc/debug.sh and hooks.sh
    
    Use local_works() to test if 'local' actually works for
    current shell.
---
 libexec/rc/debug.sh | 46 ++++++++++++++++++++++++++++++++--------------
 libexec/rc/hooks.sh | 37 +++++++++++++++++++------------------
 2 files changed, 51 insertions(+), 32 deletions(-)

diff --git a/libexec/rc/debug.sh b/libexec/rc/debug.sh
index db9ed8c94b6c..b379297a4183 100755
--- a/libexec/rc/debug.sh
+++ b/libexec/rc/debug.sh
@@ -83,7 +83,7 @@
 #      Simon J. Gerraty <s...@crufty.net>
 
 # RCSid:
-#      $Id: debug.sh,v 1.42 2024/10/30 18:23:19 sjg Exp $
+#      $Id: debug.sh,v 1.46 2024/12/13 03:55:52 sjg Exp $
 #
 #      @(#) Copyright (c) 1994-2024 Simon J. Gerraty
 #
@@ -107,27 +107,45 @@ DEBUG_DO=:
 DEBUG_SKIP=
 export DEBUGGING DEBUG_DO DEBUG_SKIP
 
-case "$isPOSIX_SHELL,$local" in
-:,:|:,local|false,:) ;;                # sane
-*)     # this is the bulk of isposix-shell.sh
+# have is handy
+if test -z "$_HAVE_SH"; then
+       _HAVE_SH=:
+
+       ##
+       # have that does not rely on return code of type
+       #
+       have() {
+               case `(type "$1") 2>&1` in
+               *" found") return 1;;
+               esac
+               return 0
+       }
+fi
+
+# does local *actually* work?
+local_works() {
+    local _fu
+}
+
+if local_works > /dev/null 2>&1; then
+    _local=local
+else
+    _local=:
+fi
+# for backwards compatability
+local=$_local
+
+if test -z "$isPOSIX_SHELL"; then
        if (echo ${PATH%:*}) > /dev/null 2>&1; then
                # true should be a builtin, : certainly is
                isPOSIX_SHELL=:
-               # you need to eval $local var
-               local=local
-               : KSH_VERSION=$KSH_VERSION
-               case "$KSH_VERSION" in
-               Version*) local=: ;; # broken
-               esac
        else
                isPOSIX_SHELL=false
-               local=:
                false() {
                        return 1
                }
        fi
-       ;;
-esac
+fi
 
 is_posix_shell() {
        $isPOSIX_SHELL
@@ -142,7 +160,7 @@ is_posix_shell() {
 # a suffix of :debug_add:tag we will add tag to DEBUG_SH
 #
 _debugAdd() {
-       eval $local tag
+       eval $_local tag
 
        for tag in `IFS=,; echo $DEBUG_SH`
        do
diff --git a/libexec/rc/hooks.sh b/libexec/rc/hooks.sh
index 3b0c50f10191..7c478fbeda15 100755
--- a/libexec/rc/hooks.sh
+++ b/libexec/rc/hooks.sh
@@ -50,7 +50,7 @@
 #
 
 # RCSid:
-#      $Id: hooks.sh,v 1.21 2024/09/06 16:53:45 sjg Exp $
+#      $Id: hooks.sh,v 1.24 2024/12/13 03:55:52 sjg Exp $
 #
 #      @(#)Copyright (c) 2000-2024 Simon J. Gerraty
 #
@@ -64,18 +64,19 @@
 # avoid multiple inclusion
 _HOOKS_SH=:
 
-# We want to use local if we can
-# if isposix-shell.sh has been sourced isPOSIX_SHELL will be set
-# as will local
-case "$local" in
-local|:) ;;
-*)  if (echo ${PATH%:*}) > /dev/null 2>&1; then
-        local=local
-    else
-        local=:
-    fi
-    ;;
-esac
+# does local *actually* work?
+local_works() {
+    local _fu
+}
+
+if local_works > /dev/null 2>&1; then
+    _local=local
+else
+    _local=:
+fi
+# for backwards compatability
+local=$_local
+
 
 ##
 # hooks_add_all list func ...
@@ -83,7 +84,7 @@ esac
 # add "func"s to "list" regardless
 #
 hooks_add_all() {
-    eval $local __h
+    eval $_local __h
     __h=$1; shift
     case "$1" in
     --first)
@@ -100,7 +101,7 @@ hooks_add_all() {
 # add "func"s to "list" if not already there
 #
 hooks_add_once() {
-    eval $local __h __hh __first
+    eval $_local __h __hh __first
     __h=$1; shift
     case "$1" in
     --first) shift; __first=:;;
@@ -154,7 +155,7 @@ hooks_add() {
 # return $list
 #
 hooks_get() {
-    eval $local __h __h2 e __l
+    eval $_local __h __h2 e __l
     case "$1" in
     --lifo) __l=LIFO; shift;;
     esac
@@ -178,7 +179,7 @@ hooks_get() {
 # is func in $list ?
 #
 hooks_has() {
-    eval $local __h
+    eval $_local __h
     eval "__h=\$$1"
     case " $__h " in
     *" $1 "*) return 0;;
@@ -193,7 +194,7 @@ hooks_has() {
 # Without '--all'; if any return non-zero return that immediately
 #
 hooks_run() {
-    eval $local __a e __h __hl __h2 __l
+    eval $_local __a e __h __hl __h2 __l
     __a=return
     __l=
 

Reply via email to