Skip to content

test(io): process_run's late stdin reader keeps its stdin under dash - #2225

Merged
Lorenzobattistela merged 1 commit into
bendlang:mainfrom
rbmr:test/process-run-dash
Nov 23, 2026
Merged

Lorenzobattistela merged 1 commit into
bendlang:mainfrom
rbmr:test/process-run-dash

Conversation

@rbmr

@rbmr rbmr commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

On Linux with dash as /bin/sh (Debian, Ubuntu and their derivatives), tests/io/process_run.bend prints late stdin reader: False on every lane: C, JS and the interpreter.

The case runs /bin/sh -c "(sleep 0.05; cat) <&0 & exit 0". POSIX gives an asynchronous list a standard input like /dev/null before its explicit redirections, so under dash <&0 duplicates /dev/null and cat reads nothing. bash, which is macOS's /bin/sh, keeps the real stdin when the list redirects it. Without Bend:

$ head -c 128000 /dev/zero | tr '\0' z | dash -c "(sleep 0.05; cat) <&0 & exit 0" | wc -c
0
$ head -c 128000 /dev/zero | tr '\0' z | bash -c "(sleep 0.05; cat) <&0 & exit 0" | wc -c
128000

This saves stdin in fd 3 before the list starts, and the late reader reads fd 3:

-      Process.run("/bin/sh", ["-c", "(sleep 0.05; cat) <&0 & exit 0"],
+      Process.run("/bin/sh", ["-c", "exec 3<&0; (sleep 0.05; cat <&3) & exit 0"],

The descendant still holds the stdin pipe after the shell exits, so the case tests the same thing. Both shells print 128000 for the new command. On Linux x86_64 (dash 0.5.12) the test passes on C, JS and the interpreter, 3 runs each, where before it failed every run. I have no Mac to run it on. The new command is plain POSIX sh, and it gives 128000 under bash here as well.

Under dash as /bin/sh, an asynchronous list's stdin is /dev/null before
its redirections, so `(sleep 0.05; cat) <&0 &` read nothing and the case
printed False on every lane. Save stdin in fd 3 before the list starts.

Co-authored-by: Claude Opus 5.5 <[email protected]>
@Lorenzobattistela
Lorenzobattistela merged commit e9f88bc into bendlang:main Nov 23, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants