Repository navigation
spawn: hand children blocking stdio and IPC fds, keep dup2 sources clear of stdio slots #41751
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
Closed
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
95c1f13
spawn: hand children blocking stdio and IPC fds, keep dup2 sources cl…
robobun 5d40ad7
probe fixture: prefer /proc, fall back to fcntl through ffi
robobun 8d5e513
Merge branch 'main' into robobun/a68fc818/spawn-blocking-stdio
Jarred-Sumner d0c8bb3
spawn_process: condense the new comments to one line each
robobun 713d146
spawn: probe closed inherit slots before creating fds, return EMFILE …
robobun e609a73
Merge remote-tracking branch 'origin/main' into robobun/a68fc818/spaw…
robobun File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| // Prints "<fd>:blocking" or "<fd>:nonblocking" for each fd number in argv. | ||
|
robobun marked this conversation as resolved.
Resolved
|
||
| // The flag is read before anything writes, so this process cannot change it. | ||
| // Must not touch process.stdout/process.stderr/process.send: those set | ||
| // O_NONBLOCK on their own fds. | ||
| import { dlopen } from "bun:ffi"; | ||
| import { existsSync, readFileSync } from "node:fs"; | ||
|
|
||
| let isNonblocking; | ||
| if (existsSync("/proc/self/fdinfo")) { | ||
| isNonblocking = fd => { | ||
| const flags = readFileSync(`/proc/self/fdinfo/${fd}`, "utf8").match(/^flags:\s*([0-7]+)/m)[1]; | ||
| return (parseInt(flags, 8) & 0o4000) !== 0; | ||
| }; | ||
| } else { | ||
| // F_GETFL is 3 on every platform here. O_NONBLOCK is 0o4000 on Linux and 4 on macOS and the BSDs. | ||
| const libc = { darwin: "libSystem.B.dylib", freebsd: "libc.so.7" }[process.platform] ?? "libc.so.6"; | ||
| const O_NONBLOCK = process.platform === "linux" ? 0o4000 : 4; | ||
| const { fcntl } = dlopen(libc, { | ||
| fcntl: { args: ["i32", "i32", "i32"], returns: "i32" }, | ||
| }).symbols; | ||
| isNonblocking = fd => (fcntl(fd, 3, 0) & O_NONBLOCK) !== 0; | ||
| } | ||
|
|
||
| const out = process.argv | ||
| .slice(2) | ||
| .map(arg => `${arg}:${isNonblocking(Number(arg)) ? "nonblocking" : "blocking"}`) | ||
| .join(" "); | ||
| console.log(out); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.