Repository navigation
executor: virtualize ulimit inside in-process fork regions (run-vredir) - #3688
Merged
Merged
Conversation
rubash#3605 / run-vredir: `ulimit -n 6` inside a `( )`/`$( )` layer, a
pipeline element, or an in-process `${THIS_SH}`/script child lowered
the SHARED process's real RLIMIT_NOFILE, so every later `{fd}`
allocation saw F_DUPFD EINVAL (base 10 >= limit 6) and the suite
cascaded through vredir6/7/8. GNU runs all of those bodies in real
children whose setrlimit results die with the process
(execute_cmd.c:1576 execute_in_subshell -> builtins/ulimit.def:632
set_limit -> setrlimit); rubash's save/restore cannot help because a
hard drop is irreversible without CAP_SYS_RESOURCE.
Model the GNU boundary instead: new Executor::ulimit_virtualized()
(`!owns_process_image || subshell_depth>0 || emulated_child_depth>0`)
gates a virtualized plat::set that applies only the SOFT side to the
kernel (always restorable, keeps kernel EMFILE enforcement honest)
and records the effective pair in `__RUBASH_ULIMIT_*` env cells — the
same contract the Windows platform layer already runs under.
`emulated_child_depth` is bumped at the pipeline-stage bracket
(pipeline_exec.rs), the in-process script-child run
(external_finish.rs); fork-copy comsubs are covered by
!owns_process_image. Cells are restored per-region
(emulated_cells_snapshot/restore) so nested regions keep their own
values; the script child's env restore drops them wholesale.
Also split the REDIR_VARASSIGN alloc failure into GNU's two
reporters: the `sys_error` line now goes to fd 2 immediately with the
script-name-only prolog (error.c error_prolog(0), no line segment —
`./vredir6.sub: redirection error: ...`), while only the file_error
line returns for the caller's `line N:` prefix.
Pins: tests/issue3605_ulimit_region_virtualization.rs — subshell /
pipeline-element hard drops die with the region, the region still
sees its own effective pair, and a plain function body's ulimit still
reaches the shell (GNU parity — functions are not forked).
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This was referenced Nov 15, 2026
Member
Author
|
【WIN-AGENT-AUDIT】PR #3688 第1轮 — 建议:PASS(已合并 squash 7a01b9d) head(合并时): 264f048 base(merge-base): 96802ca 文件: 9 个 +333/-63 机制核查:
腿(逐项):
F 点:无。 续作记录:
未跑/VOID 的腿:无(unix fail-first 已以 WSL testu 补齐,非 VOID)。 |
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.
Summary
ulimit -n 6inside a( )/$( )layer, a pipeline element, or an in-process${THIS_SH}/script child lowered the SHARED process's realRLIMIT_NOFILE— after the region returned, every{fd}allocation failedF_DUPFDEINVAL (base 10 >= limit 6), which is the whole run-vredir cascade on the macOS gate. GNU runs those bodies in real children whosesetrlimitresults die with the process (execute_cmd.c:1576 execute_in_subshell->builtins/ulimit.def:632 set_limit). The existingsnapshot/apply_process_rlimitssave-restore cannot fix this: an unprivileged hard-limit drop is irreversible.This changes the model to virtualization instead of restore:
Executor::ulimit_virtualized()—!owns_process_image || subshell_depth > 0 || emulated_child_depth > 0(newCellbumped at the pipeline-stage bracket inpipeline_exec.rsand the in-process script-child run inexternal_finish.rs; fork-copy comsubs are covered by!owns_process_image).plat::setrecords the effective pair in__RUBASH_ULIMIT_<OPT>env cells and applies only the SOFT side to the realsetrlimit— always restorable by the region's rlimit restore, and the kernel still enforces the soft side so an EMFILE consumer sees the same errno as under GNU. Virtualizedplat::getreads cell-or-real. This is the same contract the Windows emulation already runs under.emulated_cells_snapshot/restore(pipeline stage, shared-executor comsub interior), so a nested region keeps an enclosing region's cells instead of leaking them; the script child's wholesale env restore drops them for free.sys_errorline goes to fd 2 immediately with the script-name-only prolog (error.cerror_prolog(0)—./vredir6.sub: redirection error: ..., noline N:), and only thefile_errorline returns for the caller's line-stamped prefix.run-vredir on the niubash gate drops to a single residual line —
./vredir8.sub: line 30: /dev/tty:— which is environment-bound: the shippedvredir.rightgolden was generated with a controlling terminal; the gate environment has none, and GNU bash on the same box fails that open too (with the Darwin ENXIO wording).Pins:
tests/issue3605_ulimit_region_virtualization.rs—( )and pipeline-element hard drops die with the region, the region still sees its own effective pair, and a plain function body'sulimitstill reaches the shell (GNU parity: functions are not forked).Refs #3605