mirror of
git://git.code.sf.net/p/cdesktopenv/code
synced 2025-03-09 15:50:02 +00:00
Fix comsub hang on subshell fork (re: 090b65e7)
The referenced commit introduced a bug that caused command substitutions to hang, writing infinite zero bytes, when redirecting standard output on a built-in comand that forks the command substitution subshell. The bug was caused by removing the fork when redirecting standard output in a non-permanent manner. However, simply reintroducing the fork causes multiple regressions that we had fixed in the meantime. Thankfully, it looks like this forking workaround is only necessary when redirecting the output of built-ins. It appears that moving workaround from io.c to the built-ins handling code in sh_exec() in xec.c, right before calling sh_redirect(), allows reintroducing the forking workaround for non-permanent redirections without causing other regressions. It would be better if the underlying cause of the hang were fixed so the workaround becomes unnecessary, but I don't think that is going to happen any time soon (AT&T didn't manage, either). src/cmd/ksh93/sh/io.c: sh_redirect(): - Remove forking workaround for redirecting stdout in a comsub. src/cmd/ksh93/sh/xec.c: sh_exec(): TCOM: built-ins handling code: - Reimplement the workaround here. Resolves: https://github.com/ksh93/ksh/issues/416
This commit is contained in:
parent
f711da9081
commit
2d4a787564
3 changed files with 33 additions and 12 deletions
|
|
@ -905,5 +905,19 @@ then for cmd in echo print printf
|
|||
done
|
||||
fi
|
||||
|
||||
# ======
|
||||
# Command substitution hangs, writing infinite zero bytes, when redirecting standard output on a built-in that forks
|
||||
# https://github.com/ksh93/ksh/issues/416
|
||||
exp='line'
|
||||
"$SHELL" -c 'echo "$(ulimit -t unlimited >/dev/null 2>&1; echo "ok $$")"' >out 2>&1 &
|
||||
pid=$!
|
||||
(sleep 1; kill -9 "$pid") 2>/dev/null &
|
||||
if wait "$pid" 2>/dev/null
|
||||
then kill "$!" # the sleep process
|
||||
[[ $(<out) == "ok $pid" ]] || err_exit "comsub fails after fork with stdout redirection" \
|
||||
"(expected 'ok $pid', got $(printf %q "$(<out)"))"
|
||||
else err_exit "comsub hangs after fork with stdout redirection"
|
||||
fi
|
||||
|
||||
# ======
|
||||
exit $((Errors<125?Errors:125))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue