Repository navigation
feat: keep descriptors above the standard streams - #76
Merged
Merged
Conversation
When standard input, output, or error starts closed, the next open or pipe takes slot 0, 1, or 2. Later child setup or standard-stream writes can clobber that descriptor. Both places in proc moved low descriptors by hand, childExec with F_DUPFD and run's exec-failure pipe with F_DUPFD_CLOEXEC, and front ends holding flock files need the same step. Add sys.keepAboveStdio to duplicate a descriptor below 3 to 3 or above with F_DUPFD_CLOEXEC, retrying EINTR, and close the low slot. A descriptor already at 3 or above returns unchanged, and a failed call leaves the original descriptor open. Both sites in proc call keepAboveStdio, and childExec updates shared slots when standard input and standard error share /dev/null. Tests cover moving slots 0, 1, and 2 with FD_CLOEXEC set, leaving high descriptors unchanged, reporting EBADF on closed slots, and running a child with all three standard streams closed.
HaoZeke
added a commit
to stackhands/eb-local
that referenced
this pull request
Nov 21, 2026
Update the zig-common dependency in build.zig.zon from v0.12.0 to 3c3b1720de00577612f834a23c246c34fbf990a0 on main. That commit merges stackhands/zig-common#76, which adds sys.keepAboveStdio and switches proc onto it.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
When standard input, standard output, or standard error starts closed,
the next
openatorpipe2call takes descriptor slot0,1, or2. Subsequent child setup or standard-stream writes can clobber thatdescriptor. Both places in
procmoved low descriptors by hand,childExecwithF_DUPFDandrunwithF_DUPFD_CLOEXECon itsexec-failure pipe, while front ends holding
flockdescriptors needthe same primitive.
Add
sys.keepAboveStdioto duplicate any open descriptor below3to3or above withF_DUPFD_CLOEXEC, retrying interrupted calls, andclose the original low slot. Descriptors already at
3or above returnunchanged, and failed calls leave the original descriptor open. Switch
both sites in
src/proc.zigontosys.keepAboveStdio, updating sharedslots in
childExecwhen standard input and standard error share/dev/null.