git: 064edc2ceb77 - main - debug.sh avoid trouble from set -e

From: Simon J. Gerraty <sjg_at_FreeBSD.org>
Date: Tue, 13 Oct 2026 23:08:29 UTC
The branch main has been updated by sjg:

URL: https://cgit.FreeBSD.org/src/commit/?id=064edc2ceb77389d17655c8aa347084e10d64add

commit 064edc2ceb77389d17655c8aa347084e10d64add
Author:     Simon J. Gerraty <sjg@FreeBSD.org>
AuthorDate: 2026-10-13 23:08:15 +0000
Commit:     Simon J. Gerraty <sjg@FreeBSD.org>
CommitDate: 2026-10-13 23:08:15 +0000

    debug.sh avoid trouble from set -e
    
    The setting of _TTY ran afoul of set -e.
    
    Also the handling of Myname blew up if debug.sh included by
    a login sheel (eg in .profile).
    
    For non-posix shell, leave false alone if it is a builtin.
---
 libexec/rc/debug.sh | 24 +++++++++++++++++-------
 1 file changed, 17 insertions(+), 7 deletions(-)

diff --git a/libexec/rc/debug.sh b/libexec/rc/debug.sh
index ea46e9a99c0c..d4274797564a 100755
--- a/libexec/rc/debug.sh
+++ b/libexec/rc/debug.sh
@@ -81,7 +81,7 @@
 #	Simon J. Gerraty <sjg@crufty.net>
 
 # RCSid:
-#	$Id: debug.sh,v 1.47 2025/08/07 21:59:54 sjg Exp $
+#	$Id: debug.sh,v 1.54 2026/10/13 23:00:48 sjg Exp $
 #
 #	@(#) Copyright (c) 1994-2024 Simon J. Gerraty
 #
@@ -93,7 +93,10 @@
 
 _DEBUG_SH=:
 
-Myname=${Myname:-`basename $0 .sh`}
+case $0 in
+-*) ;;
+*) Myname=${Myname:-`basename $0 .sh`};;
+esac
 
 DEBUGGING=
 DEBUG_DO=:
@@ -134,9 +137,14 @@ if test -z "$isPOSIX_SHELL"; then
 		isPOSIX_SHELL=:
 	else
 		isPOSIX_SHELL=false
-		false() {
-			return 1
-		}
+		case `(type false) 2>&1` in
+		*builtin*) ;;
+		*)
+			false() {
+				return 1
+			}
+			;;
+		esac
 	fi
 fi
 
@@ -231,8 +239,10 @@ _debugOn() {
 # DEBUG_DO so functions can trace if they want
 #
 _debugOff() {
-	DEBUG_OFF=$1
+	$DEBUG_DO set -x	# so we see DEBUG_OFF=something in the trace
+	DEBUG_OFF=${1:-$DEBUG_ON}
 	set +x
+	DEBUG_OFF=$1
 	case "$_HOOKS_SH,$3" in
 	,*|:,|:,*[${CASE_CLASS_NEG:-!}A-Za-z0-9_]*) ;;
 	*)	hooks_run ${3}_debugOff_hooks;;
@@ -404,7 +414,7 @@ DebugOff() {
 	return $_rc
 }
 
-_TTY=${_TTY:-`test -t 0 && tty`}; export _TTY
+_TTY=${_TTY:-`test -t 0 && tty || :`}; export _TTY
 
 # override this if you like
 _debugShell() {