[packages/mksh] rel 4; keep exit status when EXIT trap runs after a signal or from another trap

arekm arekm at pld-linux.org
Tue Sep 8 17:12:42 CEST 2026


commit e73432f8099fb86437c91c7a920207ec8c15507c
Author: Arkadiusz Miśkiewicz <arekm at maven.pl>
Date:   Tue Sep 8 16:27:43 2026 +0200

    rel 4; keep exit status when EXIT trap runs after a signal or from another trap

 mksh-exit-trap-status.patch | 56 +++++++++++++++++++++++++++++++++++++++++++++
 mksh.spec                   |  4 +++-
 2 files changed, 59 insertions(+), 1 deletion(-)
---
diff --git a/mksh.spec b/mksh.spec
index 478a102..1d1f8fa 100644
--- a/mksh.spec
+++ b/mksh.spec
@@ -10,7 +10,7 @@ Summary:	MirBSD Korn Shell
 Summary(pl.UTF-8):	Powłoka Korna z MirBSD
 Name:		mksh
 Version:	59c
-Release:	3
+Release:	4
 License:	BSD
 Group:		Applications/Shells
 Source0:	https://www.mirbsd.org/MirOS/dist/mir/mksh/%{name}-R%{version}.tgz
@@ -20,6 +20,7 @@ Source2:	get-source.sh
 Patch0:		%{name}-mkshrc_support.patch
 Patch1:		%{name}-circumflex.patch
 Patch2:         drop-builtins.patch
+Patch3:		%{name}-exit-trap-status.patch
 URL:		https://www.mirbsd.org/mksh.htm
 %if %{with tests}
 BuildRequires:	ed
@@ -87,6 +88,7 @@ W tym pakiecie jest mksh skonsolidowany statycznie.
 %patch -P0 -p1
 %patch -P1 -p1
 %patch -P2 -p1
+%patch -P3 -p1
 
 sed -i -e 's|fgrep|grep -F|g' check.t
 
diff --git a/mksh-exit-trap-status.patch b/mksh-exit-trap-status.patch
new file mode 100644
index 0000000..3cdb700
--- /dev/null
+++ b/mksh-exit-trap-status.patch
@@ -0,0 +1,56 @@
+diff -urNp mksh-59c.org/check.t mksh-59c/check.t
+--- mksh-59c.org/check.t	2020-10-31 04:53:30.000000000 +0100
++++ mksh-59c/check.t	2026-09-08 16:21:28.753672808 +0200
+@@ -8042,6 +8042,31 @@ expected-stderr:
+ 	subshell_exit
+ 	shell_exit
+ ---
++name: exit-trap-4
++description:
++	Check that the exit status is kept when the EXIT trap runs
++	because the shell was killed by an untrapped signal
++stdin:
++	trap 'echo EXtrap' EXIT
++	kill -TERM $$
++	echo not reached
++expected-stdout:
++	EXtrap
++expected-exit: 143
++---
++name: exit-trap-5
++description:
++	Check that the exit status is kept when the EXIT trap runs
++	from exit in another trap
++stdin:
++	trap 'exit 5' USR1
++	trap 'echo EXtrap' EXIT
++	kill -USR1 $$
++	echo not reached
++expected-stdout:
++	EXtrap
++expected-exit: 5
++---
+ name: exit-trap-interactive
+ description:
+ 	Check that interactive shell doesn't exit via EXIT trap on syntax error
+diff -urNp mksh-59c.org/main.c mksh-59c/main.c
+--- mksh-59c.org/main.c	2020-10-01 22:29:21.000000000 +0200
++++ mksh-59c/main.c	2026-09-08 16:21:20.628320872 +0200
+@@ -977,9 +977,17 @@ unwind(int i)
+ 	if (i == LEXIT || ((i == LERROR || i == LERREXT || i == LINTR) &&
+ 	    sigtraps[ksh_SIGEXIT].trap &&
+ 	    (!Flag(FTALKING) || Flag(FERREXIT)))) {
++		/*
++		 * $? after a trap action must be what it was before it
++		 * (POSIX); nested here (signal or another trap) runtrap()
++		 * never gets its is_last call, so restore the status here
++		 */
++		int saved_exstat = exstat;
++
+ 		++trap_nested;
+ 		runtrap(&sigtraps[ksh_SIGEXIT], trap_nested == 1);
+ 		--trap_nested;
++		exstat = saved_exstat;
+ 		i = LLEAVE;
+ 	} else if (Flag(FERREXIT) && (i == LERROR || i == LERREXT || i == LINTR)) {
+ 		++trap_nested;
================================================================

---- gitweb:

http://git.pld-linux.org/gitweb.cgi/packages/mksh.git/commitdiff/e73432f8099fb86437c91c7a920207ec8c15507c



More information about the pld-cvs-commit mailing list