NetBSD-Bugs archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
bin/56007: ksh unable to use ERR traps (probably since 2016/03/17 - i.e. 8.x and 9.x)
>Number: 56007
>Category: bin
>Synopsis: ksh unable to execute ERR traps (probably since 2016/03/17 - i.e. 8.x and 9.x)
>Confidential: no
>Severity: serious
>Priority: high
>Responsible: bin-bug-people
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Mon Feb 22 23:05:00 +0000 2021
>Originator: Greg A. Woods
>Release: NetBSD 9.99.64
>Organization:
Planix, Inc.; Kelowna, BC; Canada
>Environment:
System: NetBSD xentastic 9.99.64 NetBSD 9.99.64 (GENERIC) #11: Sat Jul 4 16:12:53 PDT 2020 woods@xentastic:/build/woods/xentastic/current-amd64-amd64-obj/build/src-current/sys/arch/amd64/compile/GENERIC amd64
Architecture: x86_64
Machine: amd64
>Description:
N.B.: This bug also affects pdksh-5.2.14nb7 from pkgsrc.
Quite some time ago I noticed ksh wasn't executing ERR traps my
more recent netbsd-current and releases. I notice this almost
immediately as my default login shell uses "trap ERR" to report
any non-zero exit code from all interactive commands.
Finally today I did some debugging to find out why (as I intend
to put a more recent build into production).
It seems that somehow an incomplete/broken change crept in
between the changes to try to remove and re-add the code in the
signal list generating script that's needed to properly expand
and sort the signal list array entries:
----------------------------
revision 1.11
date: 2016-03-17 06:54:31 -0700; author: christos; state: Exp; lines: +36 -4;
put back the complex sed/awk since the code can't handle unsorted or repeated
entries (Rin Okuyama)
----------------------------
revision 1.10
date: 2016-03-16 16:01:33 -0700; author: christos; state: Exp; lines: +5 -35;
We don't need all this magic to build the signals lists. Do the work at
compile time.
----------------------------
The errant changes seem to have come from the fix provided in
the following email:
https://mail-index.netbsd.org/current-users/2016/03/17/msg029042.html
As it turns out the "DUMMY" value that should be at index
"SIGNALS" is not present at all in the intermediate data. This
means all the unused entries between the last valid one and the
end of the table are missing, and thus given how the generated
list is included in the static initialisation of the whole list,
the final value used for "SIGERR_" is at the wrong index and
thus can never be found.
>How-To-Repeat:
First a working example:
$ uname -a
NetBSD more 5.2_STABLE NetBSD 5.2_STABLE (XEN3_DOMU) #0: Sat Feb 14 19:21:26 PST 2015 woods@more:/build/woods/more/netbsd-5-amd64-amd64-obj/once/rest/work/woods/m-NetBSD-5/sys/arch/amd64/compile/XEN3_DOMU amd64
$ trap
trap -- '. ${HOME}/.kshlogout ; exit $?' EXIT
trap -- 'trap 1; clearban; kill -1 6340' HUP
trap -- 'trap 2; clearban; kill -2 6340' INT
trap -- 'trap 3; clearban; kill -3 6340' QUIT
trap -- 'trap 15; clearban; kill -15 6340' TERM
trap -- '
rc=$?;
if ((ERRNO > 0)); then
EMSG="; errno: $ERRNO"
else
EMSG=""
fi;
print "${0#-}: exit code: $rc$EMSG"
' ERR
$ false
ksh: exit code: 1
$
Now the broken version (note the "ksh: exit code: 1" message is
missing after "false" is executed):
$ uname -a
NetBSD xentastic 9.99.64 NetBSD 9.99.64 (GENERIC) #11: Sat Jul 4 16:12:53 PDT 2020 woods@xentastic:/build/woods/xentastic/current-amd64-amd64-obj/build/src-current/sys/arch/amd64/compile/GENERIC amd64
$ trap
trap -- '. ${HOME}/.kshlogout ; exit $?' EXIT
trap -- '
rc=$?;
if ((ERRNO > 0)); then
EMSG="; errno: $ERRNO"
else
EMSG=""
fi;
print "${0#-}: exit code: $rc$EMSG"
' ERR
$ false
$
>Fix:
The following changes fix the problem, clean up some ugliness in
the generated output, and hopefully add a wee bit of
future-proofing for changes in CPP output.
Index: bin/ksh/siglist.sh
===================================================================
RCS file: /cvs/master/m-NetBSD/main/src/bin/ksh/siglist.sh,v
retrieving revision 1.12
diff -u -r1.12 siglist.sh
--- bin/ksh/siglist.sh 17 Mar 2016 13:59:02 -0000 1.12
+++ bin/ksh/siglist.sh 22 Feb 2021 22:20:38 -0000
@@ -21,22 +21,23 @@
# The trap here to make up for a bug in bash (1.14.3(1)) that calls the trap
(trap $trapsigs;
echo '#include "sh.h"';
- echo ' { QwErTy SIGNALS , "DUMMY" , "hook for number of signals" },';
+ echo ' { QwErTy /* dummy for sed sillies */ },';
${SED} -e '/^[ ]*#/d' -e 's/^[ ]*\([^ ][^ ]*\)[ ][ ]*\(.*[^ ]\)[ ]*$/#ifdef SIG\1\
{ QwErTy .signal = SIG\1 , .name = "\1", .mess = "\2" },\
#endif/') > $in
-# work around for gcc 5
+echo ' { QwErTy .signal = SIGNALS , .name = "DUMMY", .mess = "hook to expand array to total signals" },' >> $in
+# work around for gcc > 5
$CPP $in | grep -v '^#' | tr -d '\n' | ${SED} 's/},/},\
/g' > $out
${SED} -n 's/{ QwErTy/{/p' < $out | ${AWK} '{print NR, $0}' | sort -k 5n -k 1n |
- ${SED} 's/^[0-9]* //' |
- ${AWK} 'BEGIN { last=0; nsigs=0; }
+ ${SED} -E -e 's/^[0-9]* //' -e 's/ +/ /' |
+ ${AWK} 'BEGIN { last=0; }
{
if ($4 ~ /^[0-9][0-9]*$/ && $5 == ",") {
n = $4;
if (n > 0 && n != last) {
while (++last < n) {
- printf "\t{ .signal = %d , .name = NULL, .mess = `Signal %d` } ,\n", last, last;
+ printf " { .signal = %d , .name = NULL, .mess = `Signal %d` } ,\n", last, last;
}
print;
}
Home |
Main Index |
Thread Index |
Old Index