Repository navigation
fix(redir): materialize undo-save slot saturation EMFILE diagnostics (Fixes #4043) - #4057
Conversation
…n diagnostics (rubash#4029) (#4039) Captain graft onto 54aef43: reconciled with #4025 (rubash#3543) — the raw channel names which word is cited; bad_substitution_display decides how a parser word's comsub spans print (canonicalized), runtime text stays raw. Prompt-string passes now suppress the outer parser word's raw record.
… trailing separator (Fixes #4017) (#4026) * fix(funsub): accept compound-command-terminated funsub bodies without trailing separator (Fixes #4017) * chore(funsub): reword tokstr comments to dodge the comment-blind registry scan The registry consistency test's claim_literals scan is comment-blind and extracted a shadow claim for `{` from the `== "{"` shape in five single-line comment copies (command_substitution.rs, embedded_mutations.rs, alias_stream.rs, skip.rs x2). Reworded to `is the single-char "{"` -- comment text only, zero behavior change. Captain review-4026 section 2.
…YS2_ENV_CONV_EXCL (Fixes unixwin/niubash#1001) (#4064)
|
CAPTAIN REVIEW — not mergeable in current form; the direction has since been superseded, see the decision at the end. Hard gaps in the current form:
Direction decision: the captain's debt-paydown plan has fixed the fd direction as completing real descriptor materialization and retiring the symbolic walk simulation layer. #4043 is to be redone along that line. This PR's model-layer approach — making the model's occupancy set failable and synthesizing the diagnostic — is not the direction that will be merged, independent of the open fidelity question (model saturation ≡ kernel saturation is unproven in the window where the process holds descriptors the model doesn't track). So: please either redo #4043 on the materialization direction, or align the design with the captain before investing more in this branch. If you take it on, the gates are: rebase + fresh CI with a clean name-set differential, a cloud GNU 5.3.20 oracle matrix (saturation original + the 6 pin shapes + close-shape second line + partial-table slot placement), and fail-first on pristine (expected 5 red / 1 guard green). |
…d map <> list bounds (Fixes #3939)
…cts (Refs #3969) (#4020) Captain graft on top of the original PR head (rebased to master 38fdd99): the brace-product bad-substitution verdict is latched with a discard-only class marker (ShellState.bad_substitution_discard_only), so the generic latch consumers no longer promote it to FORCE_EOF under POSIX mode. GNU returns &expand_wdesc_error for expand_word_internal's backquote case in every mode (subst.c:11568-11593) - under the argv[0] `sh` name the un-grafted head aborted the whole script (exit 1, -c exit 127) where GNU-as-sh discards the command and continues (exit 0, -c exit 1). The ${...} class keeps its FORCE_EOF semantics. Adds sh-name regression pins (script-file and -c forms) to tests/issue3969_brace_backquote_rescan_regressions.rs.
…(Refs #3994) execute_empty_words_command never routed through command_with_process_substitution_files, so a parser-recorded <(...) / >(...) redirect target on a command-less assignment reached the redirect apply layer as literal text and was probed as a filesystem path: `x=1 < <(sleep 1)` reported `<(sleep 1): No such file or directory` and failed, where GNU (execute_null_command -> do_redirections over the same list; redirection_expand, redir.c:298) silently succeeds. The wrapper admits exactly the redirects the materialization arms themselves admit (redirect_target_span_is_recorded, rubash#1931 — a quoted "<(cmd)" stays a literal filename), materializes through the same function, and finishes through the same finish_process_substitutions with the materialized paths' completion convention (inner Err governs, finish runs best-effort; on inner Ok the finish result governs). What this PR deletes: nothing. The former execute_empty_words_command body is renamed execute_empty_words_command_inner unchanged; the wrapper is the only new code. UNVERIFIED-BY-CAPTAIN
…rd position (Refs #4273) (#4277) * fix(exec): quoted "$*" joins with IFS[0] under a null IFS in every word position (Refs #4273) * fix(exec): quoted "$*" joins with IFS[0] under a null IFS in every word position (Refs #4273) Refs #4273 (not Fixes). v2: fixes the issue2827 regression introduced by v1. A fully double-quoted assignment-shaped conditional operand ([[ "k0=v0" =~ ^k0=(v[0-9]+)$ ]]) failed to match: the STORAGE-prefixed word was claimed by expand_marked_or_special_word before expand_assignment_word, leaving the lexer's 0x1C IFS_GLUE (QUOTED_WORD_VALUE_PREFIX) in the comparison value. The fix records a `marked` flag in expand_conditional_word_inner and strips the glue with markers::strip_ifs_glue for marked words after expansion (conditional words are comparison values with no field-split consumer downstream); unmarked words keep the old path. Re-verification (devin-mac): issue2827_regex_compile_cache 5/5, issue4273 pins 5/5, issues_4200_4299 33/33; oracle (bash 5.3.20) 25/27 verbatim, the 2 diffs being pre-existing residual (a) (CTLESC affix leak, same shape on base).
…r set -f (Refs #4272) Refs #4272 (not Fixes). gen_globpat_matches (pcomplete.c) hands the -G pattern straight to glob_filename; the subst.c word-expansion admission gates never apply. rubash routed compgen through pathname_expand_word, whose gates dropped two faces: a pattern without unquoted metacharacters never produced a result (glob_vector's stat fast path returns the dequoted literal when the file exists), and under `set -f` every -G pattern returned nothing (noglob is a glob_expand_word_list check, not a glob.c one). Add compgen_globpat_expand_word in glob.rs: the same machinery as pathname_expand_word with the word-expansion gates (empty word, byte whitelist, noglob, whole-word unquoted_glob_pattern_p) skipped; glob.c's per-component glob_pattern_p admission decides instead. Both compgen call sites in complete.rs (the builtin and the compspec completion attempt) use it. Ordinary expansion is untouched: `set -f` still suppresses echo fi*, nullglob/failglob keep their word-list behavior, and neither leaks into compgen. Pins: tests/issues_4200_4299/issue4272_compgen_globpat_literal_ and_noglob.rs (5 tests: literal face incl. escapes/trailing slash/absolute/nonexistent, noglob face + expansion guard, empty pattern, invalid bracket + prefix filter, nullglob/failglob neutrality). Oracle-verified against bash 5.3.20 on every case.
fix(complete): compgen -G returns literal-path matches and globs under set -f (Refs #4272)
…stderr redirects Test-only. The reported bug (arithmetic eval error diagnostics bypass the calling function's stderr redirect) does not reproduce on master 60ed70e: 32 probe scripts on macOS run byte-identical against the GNU bash 5.3.20 oracle, including the nested-caller DISCARD face. Adds 6 regression pins so the face stays covered. Refs #4254 (not Fixes).
…e chdir line
A shell born in a deleted cwd seeded its logical cwd as Some(""):
the empty adoption was stored as a live value. GNU keeps tcwd NULL
in that state, and the cd entry re-derivation gate
(get_working_directory "chdir", cd.def:529-534) is exactly
logical_cwd.is_none() -- mid-session poisoning (#3574) uses None and
prints the chdir: line, birth poisoning used Some("") and never did.
Both seeding points (Executor::new, in-process subshell seeding) now
store None for an empty adoption, sharing the single poisoned-state
representation. Healthy shells are unaffected (non-empty values are
identical). Adds 5 pins; fail-first verified on base.
Refs #4120 (not Fixes).
move_to_high_fd scanned downward from a shared ceiling for an empty slot and then dup2'd into it: probe and dup2 were not atomic. Two threads necessarily find the same first empty slot T; the second dup2 atomically closes the first thread's descriptor, the first Drop then closes the second thread's live descriptor, and the second Drop's close hits EBADF -- the std debug-build IO Safety abort of #4274. The hot trigger is file-redirect execution lazily installing the cwd anchor (probe_output_redirect_file -> output_fifo_validation_via_anchor), several moves per test pair in lock-step threads. A process-level static Mutex now covers the scan+dup2+close section (the HANDSHAKE_LOCK pattern); landing band, cloexec and failure fallback are unchanged, and every caller (capture pipes, signal relay, anchor refresh) is covered by the single mechanism. Adds a barrier-synchronized regression pin that aborts 10/10 on base and passes 20/20 with the fix. Refs #4274 (not Fixes).
…lements
In a plain compound assignment, an element concatenating a $'...'
segment with another quoted segment had its decoded blank bytes
(tab, newline) replaced by spaces: f=('a'$'x\ty') stored 'ax y'
instead of 'ax<TAB>y'. The compound walker decodes $'...' and
re-wraps it in raw quotes with the U+E401 ANSI_C_IFS_GUARD marker
intact, but split_requoted_hoisted_compound_word had no arm for the
guard, so the guarded byte fell to the bare-IFS arm, was field-split
and re-joined with a space. GNU hands the decoded span back wrapped
by sh_single_quote (parse.y:5564-5571) and never splits it. A new
guard arm glues the guard and the following byte into the current
field (+16 lines, single mechanism). The issue's title forms were
already correct on master; 14 new pins cover them plus every
corrupting and control shape. Bucket 52/52.
Refs #4200 (not Fixes).
test(issue4254): pin arithmetic-error diagnostics following function stderr redirects
fix(fd): serialize move_to_high_fd's probe-and-dup2 under a process lock
test(issue4227): pin case-syntax-error token selection
fix(exec): entry-poisoned shells store no logical cwd so cd prints the chdir line
Fix compound-assignment field split of decoded $'…' blanks in mixed-quote elements (Refs #4200)
…name-glob boundaries (Fixes #4126)
fix(glob,cond): protect full GNU glob-char class at [[ == ]] and pathname-glob boundaries (Fixes #4126)
…4288) Convergence to GNU bash 5.3.20, not a regression. Both diffs were verified byte-for-byte against the pristine 5.3.20 oracle and current rubash (see lane-master-ci-red-2026-11-30.md): - errors.snap: `ivar -3` (`${!1:-${1}}` with $1=`-3`) no longer outputs `-3`; GNU and current rubash both report bad substitution / invalid variable name with empty stdout. The old snapshot recorded the loose fallback (two lines, normal + `-o posix` runs of errors6.sub). Suspected engine change: 975af9c indirect expansion (2026-11-09) — not bisect-confirmed. - exp.snap: six `$xxx""`-style concatenations (exp.tests:82-93) now keep one empty word (`argv[1] = <>`), matching GNU: a quoted empty string keeps the word, only a bare unquoted empty expansion is dropped. The old snapshot (recorded 10-26) dropped all six. Suspected engine change: 568dce3 word-walk / quoted-result IFS protection (2026-11-03) — not bisect-confirmed. Bytes are the runner-true recording from the goldens job of master run 46312294455 (artifact regression-snapshots.zip, ID 15330985687), recorded with RUBASH_REGRESSION_RECORD=1 per the re-record protocol in tests/regression.rs; the other 11 snapshots in that artifact are byte-identical to the committed ones. The snapshot tests are #[cfg(windows)], so the recording could not be reproduced on the macOS lane host; the artifact is the protocol-prescribed source. Refs #4288 (not Fixes).
…11-30 test(regression): re-record errors/exp upstream-suite snapshots (Refs #4288)
…k (Refs #4288) Refs #4288 (not Fixes). A background death observed by an intervening foreground wait was printed at the wait builtin's own reader boundary, and the boundary emit's cleanup retired the job but also populated the #2777 retained link (completed_job_pids) -- so `kill -KILL %1; sleep 0.3; wait %1` answered 137 from the link where GNU answers 127 + `no such job`. GNU's pull-driven notify_and_cleanup (parse.y shell_getc) deletes the row in the same pass it prints the notice; no jobspec record survives for the list being read. Give the cleanup a no-link form and use it for exactly the reader-boundary pass: cleanup_dead_jobs delegates to a shared cleanup_dead_jobs_impl(retain_link); the boundary report (report_pending_signal_notices_at_line, the #2928 stamped flush) routes through a new report_pending_signal_notices_ no_link / emit_signal_notices_with_link pair. Print timing, stamps, marking, and deletion are unchanged -- only the link insert is skipped. Mid-list retirements (the `jobs` builtin's notify, a wait's own tail cleanup, the stream-end flush) keep the link: there a following wait in the same list is the reap's peer (#2777 cells). Net lines: +50/-3 (2 production files; no test files -- the pin already exists and was red on master). Nothing deleted: the link mechanism stays for its mid-list domain; the boundary pass now uses the same single cleanup impl with the record left unpopulated, so there is no second path.
fix(jobs): reader-boundary notice pass retires without a retained link (Refs #4288)
Generated with [Devin](https://devin.ai) Co-authored-by: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Bring the #4043 EMFILE undo-save work onto current master. The branch had fallen behind two redirect-walk changes on master and had four conflicting files; all four are resolved without dropping either side. Conflicts and resolution: 1. src/executor/command_dispatch.rs Master (rubash#4036) moved the reject gate AFTER the xtrace head block (GNU execute_cmd.c:4648-4649 prints the head before do_redirections) and added a redirect-target pre-expand pass. Kept master's placement and pre-pass; moved the branch's `undoable_walk` computation to master's post-xtrace gate call site instead of the old pre-apply position. 2. src/executor/command_prepare.rs Same shape: kept master's `preexpand_redirect_targets` at the pre-binding point and threaded `undoable_walk` into the post-xtrace `reject_invalid_redirects` call (the branch's old call site no longer existed). 3. src/executor/trap_exec.rs Master renamed the `compound_dup_bad_fd` verdict flag from the branch's `is_emfile` to `cannot_duplicate` (rubash#4028/#4046). Kept master's naming for the move-undo verdict and carried the branch's new EMFILE verdict as a separate fourth tuple field. 4. src/executor/command_input_scope.rs `compound_dup_bad_fd` now returns `(index, name, cannot_duplicate, is_undo_save_emfile)`. `abandon_compound_for_dup_bad_fd` keeps master's `compound_redirect_error_prefix` routing and EBADF text verbatim, and gains an EMFILE arm. The branch's ad-hoc `subshell_command.is_none() && pipe.is_none() && pipeline_command.is_none()` undoable test is dropped in favor of master's shared `move_walk_is_undoable` (rubash#4046), so every redirect walk of one command agrees. Also removes the now-dead `fd_walk_undo_save_slots` wrapper (its only caller, `fd_walk_register_saves`, now delegates to the fallible `try_fd_walk_register_saves`), keeping its documentation on the surviving function. GNU C source (third_party/bash, bash.git @9c465866, Bash-5.3 patch 20): redir.c:1296 add_undo_redirect() redir.c:1303-1310 save-slot ladder: fcntl(F_DUPFD) tries (fdbase < SHELL_FD_BASE ? SHELL_FD_BASE : fdbase+1), then SHELL_FD_BASE, then 0. redir.c:1312-1316 when every candidate fails, sys_error "redirection error: cannot duplicate fd" and the undo-save registration returns -1, failing the redirection walk (errno EMFILE here). redir.c:223 internal_error ("%s: %s", filename, strerror(error)) is redirection_error's second line, so the same failed entry reports "<target>: Too many open files" (strerror(EMFILE)), not "Bad file descriptor". Before this change rubash's `fd_walk_undo_save_slots` silently dropped a save when `fd_walk_lowest_free` returned None, so an undoable walk succeeded instead of failing EMFILE. Verification: * cargo build --tests: 0 errors. * cargo test --test issue4043_exec_walk_emfile: 6 passed, 0 failed. * Neighbor suites unchanged vs pristine master (identical pass/fail counts AND identical failing-test sets): redirect 124 passed / 0 failed (both trees) bad_fd 11 passed / 0 failed (both trees) exec_walk 15 passed / 0 failed (both trees) issue4028_move_fd10_bad_fd_diag 8 passed / 0 failed dup 26 passed / 8 failed (both trees, same 8 tests) undo_save 14 passed / 15 failed (both trees) The dup/undo_save failures are pre-existing and environmental: those tests `cd <dir.display()>` with a Windows backslash path (`cd: C:UserscmxAppDataLocalTemp...`). Pristine master fails them identically. The same script bodies replayed with a POSIX cwd produce byte-identical output across GNU bash 5.3.20, this lane and pristine master. * GNU comparison from a script file (wsl /usr/local/bin/bash /mnt/d/repo/lanes-r/pr4043-probe.sh, 5.3.20): all six #4043 cases match byte-for-byte -- two-line EMFILE diagnostics, status 1, target named as source fd / 0 / expanded path, and the RX_ACTIVE-only subshell head still succeeding. * scripts/check-rustfmt.py: ok, 226 targets (2021: 226), 2 batches. Fixes #4043
复核结论:需要返工,不可合入头 4 个自带新 pin 在本 PR 自己的 census 里失败(6 测仅 2 绿),正文称本地 Census 差分CI 除 census 外全绿(goldens、Rust tests、fmt、API ledger 均 PASS)。PR census 32 个 FAIL 名,master 同期 26 名;PR 多出 6 名:4× issue4043(自带 pin)+ 2× issue2340(已记录轮换族,本轮 master 未现)。其余 26 名与 master 逐名相同(#4291 烧掉的 24 茎在 master 上仍红,与本 PR 无关)。0 SIG。 4 个失败 pin(断言原文取自 CI 日志):
通过的 2 测: Oracle 核对:pin 的期望没错(GNU 5.3.20 同款探针,6/6 一致)
机制:exec 通、builtin/compound 不通的原因
返工清单
未回归面goldens PASS;#4032 p01–p13 矩阵与 issue3991 15 钉无失败名出现;其余 CI 腿全绿。PR 除自带 4 pin 外未引入新回归。 短板说明:旧头无 CI 可比对(分支上只有新头的 run),「merge 是否弄坏」无法用 CI 差分裁决;但测试文件新旧头逐字相同、失败签名与实现缺口一致指向实现问题而非 merge 损坏。rubash 多占 OS fd 的精确身份未完全拆清(glob 探针的 fd 3 含自身句柄),返工第 2 项不依赖此数精确。卷宗: |
Fixes #4043.
Summary
ulimit -nfd-table saturation (base -> 10 -> 0fallback) matching GNUredir.c:1296-1316(add_undo_redirect) andredir.c:123-132(REDIRECTION_ERROR->EMFILE):src/executor/trap_exec.rs: addedtry_fd_walk_undo_save_slots,try_fd_walk_register_saves,undo_save_error_target_name, and updatedexecute_stdio_only_exec_redirect_innerto emit GNU's two-lineEMFILEdiagnostic (redirection error: cannot duplicate fd: Too many open files+<target>: Too many open files,rc=1).src/executor/redirection.rs,src/executor/command_dispatch.rs,src/executor/command_prepare.rs,src/executor/pipeline_exec.rs: gated undo-saveEMFILEchecks onundoable_walkinreject_invalid_redirects.src/executor/command_input_scope.rs: updatedcompound_dup_bad_fdandabandon_compound_for_dup_bad_fdto detect undo-saveEMFILEon undoable compound walks.tests/issue4043_exec_walk_emfile.rs(6 tests).Verification
rustfmt --edition 2021 --checkpassed on all 7 modified/added files.cargo test --test issue4043_exec_walk_emfile --test issue4024_exec_walk_save_stdio_source --test issue4024_exec_walk_save_stdio_graft: 6/6 + 7/7 + 8/8 passed.