Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

closing stdin in a subshell leaks into the parent when posix_spawn() is enabled #1129

Open
krader1961 opened this issue Jan 22, 2019 · 1 comment
Labels

Comments

@krader1961
Copy link
Contributor

krader1961 commented Jan 22, 2019

I recently made it possible to build again with ksh using posix_spawn() (see commit be962c7). That results in the basic.sh unit test to fail. I've boiled it down to a minimal test case and can reproduce on macOS 10.14 and Fedora 28. Replace the content of src/cmd/ksh93/tests/basic.sh with this:

set -x
x=$($SHELL -c 'echo yes' <&-)

lsof -p $$
print xxx > $TEST_DIR/file
for x in 1 2
do
    tee >(sleep 1; cat > $TEST_DIR/file) <<< "hello" > /dev/null
    lsof -p $$
done

Then build and test with meson -Duse-spawn=true; ninja; meson test basic. If you inspect build/meson-logs/testlog.txt you should see that the subshell dies from a SIGSEGV when executing the builtin cat. Why this requires a for loop is unknown but removing that loop does not result in failure. The lsof -p $$ aren't required to reproduce the problem. They're only to show that the shells stdin is closed.

Also, the SIGSEGV is because after executing fp = sfstdin; the subsequent use of fp is fatal because sfstdin is NULL due to the problem described above.

@krader1961 krader1961 added the bug label Jan 22, 2019
@krader1961
Copy link
Contributor Author

And, of course, this is another example for why I wrote in issue #1117 that stdin, stdout, and stderr should never be left closed. The problem here appears to involve the non-forking optimization described in issue #480 but I don't really know at this stage.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant