Skip to content

Commit 9c97439

Browse files
committed
Revert buggy exec optimisation (re: d6c9821)
As of 2022-06-18, ksh 93u+m is not capable of being used as /bin/sh while building GNU binutils. The execution of some of its build system's dot scripts is incorrectly aborted as an external 'sed' command is execve(2)'d without forking. This means that incorrect exec optimization was happening. Unfortunately I have not been able to derive a minimal reproducer of the problem yet because the GNU binutils build scripts are very complex. Pending further research, the optimisation is reverted. Even if a way to make it work is found, it will not be reintroduced to the 1.0 branch. Thanks to @atheik for finding the problem and identifying the commit that introduced it. Resolves: #507
1 parent c848433 commit 9c97439

File tree

5 files changed

+24
-17
lines changed

5 files changed

+24
-17
lines changed

NEWS

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@ This documents significant changes in the 1.0 branch of ksh 93u+m.
22
For full details, see the git log at: https://github.com/ksh93/ksh/tree/1.0
33
Uppercase BUG_* IDs are shell bug IDs as used by the Modernish shell library.
44

5+
2022-08-05:
6+
7+
- Reverted a buggy exec optimisation introduced on 2022-06-18. It is known
8+
to make the build scripts of GNU binutils produce corrupted results.
9+
10+
- Release 1.0.1.
11+
512
2022-08-01:
613
_ _ ___ _____ ___ ___ ___
714
| | _____| |__ / _ \___ / _ _ _ _ __ ___ / / | / _ \ / _ \

src/cmd/ksh93/include/version.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
#include <releaseflags.h>
1818

1919
#define SH_RELEASE_FORK "93u+m" /* only change if you develop a new ksh93 fork */
20-
#define SH_RELEASE_SVER "1.0.0" /* semantic version number: https://semver.org */
21-
#define SH_RELEASE_DATE "2022-08-01" /* must be in this format for $((.sh.version)) */
20+
#define SH_RELEASE_SVER "1.0.1" /* semantic version number: https://semver.org */
21+
#define SH_RELEASE_DATE "2022-08-05" /* must be in this format for $((.sh.version)) */
2222
#define SH_RELEASE_CPYR "(c) 2020-2022 Contributors to ksh " SH_RELEASE_FORK
2323

2424
/* Scripts sometimes field-split ${.sh.version}, so don't change amount of whitespace. */

src/cmd/ksh93/sh/xec.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1927,11 +1927,7 @@ int sh_exec(register const Shnode_t *t, int flags)
19271927
t = t->lst.lstrit;
19281928
}
19291929
while(t->tre.tretyp == TLST);
1930-
/*
1931-
* if sh_state(SH_FORKED) was turned on in the meantime, mix it in to the flags to allow a last-command
1932-
* no_fork optimization via execflg2 -- this happens when a subshell forks mid-execution (sh_subfork())
1933-
*/
1934-
sh_exec(t,flags|sh_isstate(SH_FORKED));
1930+
sh_exec(t,flags);
19351931
break;
19361932
}
19371933

src/cmd/ksh93/tests/basic.sh

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -927,15 +927,6 @@ esac
927927
# ======
928928
# Test exec optimization of last command in script or subshell
929929
930-
(
931-
ulimit -t unlimited 2>/dev/null # fork subshell
932-
print "${.sh.pid:-$("$SHELL" -c 'echo "$PPID"')}" # fallback for pre-93u+m ksh without ${.sh.pid}
933-
"$SHELL" -c 'print "$$"'
934-
) >out
935-
pid1= pid2=
936-
{ read pid1 && read pid2; } <out && let "pid1 == pid2" \
937-
|| err_exit "last command in forked subshell not exec-optimized ($pid1 != $pid2)"
938-
939930
got=$(
940931
ulimit -t unlimited 2>/dev/null # fork subshell
941932
print "${.sh.pid:-$("$SHELL" -c 'echo "$PPID"')}" # fallback for pre-93u+m ksh without ${.sh.pid}

src/cmd/ksh93/tests/functions.sh

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1034,9 +1034,22 @@ function foo
10341034
typeset pid
10351035
$tmp1 > $tmp2 & pid=$!
10361036
wait $!
1037-
[[ $(< $tmp2) == $pid ]] || err_exit 'wrong PID for & job in function'
1037+
got=$(< $tmp2)
1038+
[[ $got == "$pid" ]] || err_exit 'wrong PID for & job in function' \
1039+
"(expected $(printf %q "$pid"), got $(printf %q "$got"))"
10381040
}
10391041
foo
1042+
foo()
1043+
{
1044+
$tmp1 > $tmp2 & pid=$!
1045+
wait $!
1046+
got=$(< $tmp2)
1047+
[[ $got == "$pid" ]] || err_exit 'wrong PID for & job in POSIX function' \
1048+
"(expected $(printf %q "$pid"), got $(printf %q "$got"))"
1049+
}
1050+
foo
1051+
unset pid
1052+
unset -f foo
10401053
# make sure compiled functions work
10411054
[[ $(tmp=$tmp $SHELL <<- \++++
10421055
cat > $tmp/functions <<- \EOF

0 commit comments

Comments
 (0)