Skip to content

WIP: procsub + locale mopup — #1690 compound procsub assignment, #1691 temp-file leak, #1692 setlocale warning - #1793

Merged
caomengxuan666 merged 4 commits into
masterfrom
fix8/procsub
Oct 26, 2026
Merged

caomengxuan666 merged 4 commits into
masterfrom
fix8/procsub

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Mopup cluster (find-hunt r6, double-run verified): three fixes, one commit each, all gates green locally. Opened as draft per the visibility rule; verification/merge goes through the integration pipeline — do not merge directly.

Commits

  • 1918a40e Fixes [bug] Compound array assignment with process substitution collapses to one parenthesized element #1690 — compound array assignment with process substitution collapsed to one parenthesized scalar element. The raw-procsub branch of expand_assignment_value_with_raw dropped the cooked value's COMPOUND_ASSIGNMENT_MARKER; it is now carried onto the materialized text (GNU arrayfunc.c:557 expand_compound_array_assignment splits the body into element words first, so compoundness is a property of the assignment, not of the expansion route). Pair/mix/triple/>(...)/append/declare -a/local -a shapes verified byte-identical to GNU bash 5.3.20. Note: procsub fd words are dead by the next command in GNU for scalar and array alike, so the test asserts element shape/count, not later readability.
  • 1333efaa Fixes [bug] Process-substitution temp files leak in TMPDIR for external-command redirects and assignments #1691 — rubash-process-subst-*.tmp carriers leaked in $TMPDIR past shell exit on two routes: (1) both assignment materializers discarded the temp path — now collected in a new Executor field and drained at the per-command assignment finish; (2) open_input_redirect's consume branch (and open_fd_read_endpoint's text/procsub arm) wrote a fresh carrier for external children and dropped the path — now parked in ShellState::procsub_adhoc_carriers and removed by finish_process_substitutions; ShellState clones start empty so a fork child only drains its own. Verified by actually diffing $TMPDIR contents after exit: leak matrix (11 cases) + route matrix (10 cases) all zero with GNU-identical stdout. Windows note: if a pipeline child still holds the file open, remove fails silently there (same shape as the existing dispatch-carrier cleanup); Linux unlink-after-open is unaffected.
  • 6537b06c Fixes [bug] Missing setlocale warning for invalid LC_ALL (startup env and assignment) #1692 — invalid LC_ALL/category assignments (and startup env) now emit GNU's setlocale warning. src/locale.rs mirrors sv_locale (variables.c:6272 → locale.c:185) with real libc::setlocale attempts: strerror suffix only on the first failing (category, name) attempt per process, LC_ALL/category/LANG/reset semantics, startup priming + argv[0]-prefixed warning. Executor wiring fires at every true bind (assignment store, tempenv shadow, declare, export/readonly gated on a value operand, tempenv + function-frame restores, for-loop bind); simple-command tempenv defers until the command class is known (GNU binds only for builtin/function). LC_COLLATE: plain (unexported) assignment does not re-collate glob order or [[ < ]] (#1512 follow-up) #1531 LC_COLLATE watcher and matcher: glob ? matches a character instead of one byte in C/POSIX locale (pattern removal over multibyte values) #1533 C-locale byte-semantics pins untouched.

Regression tests (expectations per GNU)

  • tests/issue1690_compound_procsub_assignment.rs — 1 test
  • tests/issue1691_procsub_temp_leak.rs — 3 tests (fresh TMPDIR per case, asserts empty after exit)
  • tests/issue1692_setlocale_warning.rs — 5 tests

Gates (final tree, purified env, build-slot)

  • Targeted: all pass (1+3+5)
  • lib: 771 passed / 1 failed / 1 ignored — the one failure is the known baseline ownership_unary_operators_check_existing_file, same set as master
  • diffcorpus 306: 305 pass, failure set = {ms10} only
  • rustfmt clean on this cluster's hunks; LF only

Known non-parity (documented in cluster REPORT.md)

  • After a failed readonly rebind of a locale variable, GNU re-warns with the OLD value; not implemented (deep corner, staging mechanism absent in rubash's standalone assignment path).
  • Function-pop restore diagnostics report the function body line in rubash vs the call line in GNU — pre-existing platform divergence shared by all restore hooks (BASH_COMPAT restore on the baseline binary shows the same), not introduced here.
  • One cosmetic follow-up already in the tree: an unused import removed from the 1691 test after its gate run; a confirmation re-run of that single test is queued in the build slot.

Full cluster report: ~/workspace/rubash-fix8/clusters/procsub/REPORT.md (local workspace).

…ion (rubash#1690)

The raw process-substitution branch of expand_assignment_value_with_raw
re-derived the value from the raw RHS and fed it to
expand_assignment_value without the cooked value's
COMPOUND_ASSIGNMENT_MARKER, so the inner expansion treated a compound
RHS as a plain scalar: a=(<(echo one) <(echo two)) stored ONE element
whose text was the whole parenthesized string.

GNU arrayfunc.c:557 expand_compound_array_assignment splits the body
into element words first (parse_string_to_word_list, arrayfunc.c:581)
and expands each; compoundness is a property of the assignment, not of
the expansion route. Mirror that by carrying the marker onto the
materialized text, next to the existing quoted-marker arm.

Regression: tests/issue1690_compound_procsub_assignment.rs (script-file
matrix, expected output is literal GNU bash 5.3.20 output; fd numbers
normalized).
…ubash#1691)

rubash-process-subst-*.tmp carriers leaked in $TMPDIR past shell exit
on two routes (GNU leaks none):

1. Assignment contexts. Both assignment materializers
   (materialize_assignment_process_substitutions_from_raw and
   materialize_assignment_process_substitutions) discarded the path
   returned by write_process_substitution_temp_bytes. The paths now
   land in the new Executor field
   assignment_input_process_substitution_files and are removed at the
   top of finish_assignment_output_process_substitutions_for_command,
   before its output-queue early return. That finish runs at every
   simple-command end, which is the lifetime GNU gives the
   substitution: its fd word is dead by the next command (verified
   oracle for scalar and array alike), and in-shell readers keep
   working through the in-memory stream registry.

2. External redirect consumers. open_input_redirect's consume branch
   (and open_fd_read_endpoint's text/procsub arm) served a registered
   stream's remaining bytes by writing a FRESH temp file, opening it
   for the child, and dropping the path. Those paths now park in
   ShellState::procsub_adhoc_carriers and are removed by
   finish_process_substitutions, the per-command finish every consumer
   route reaches after its child/read completes. A ShellState clone
   starts with an empty list, so a fork child can only drain carriers
   it wrote itself.

src/executor/{mod,init,command_substitution}.rs also gain the
Executor fields for the rubash#1692 locale-warning deferral; they are
wired up by the following commit.

Regression: tests/issue1691_procsub_temp_leak.rs — per-case fresh
TMPDIR, asserts the directory is empty after exit AND stdout is the
GNU output, across assignment, redirect-consumer and previously-clean
contexts.
…ts (rubash#1692)

GNU binds LANG and every LC_* variable to sv_locale (variables.c:5800
special_vars -> variables.c:6272 sv_locale -> locale.c:185
set_locale_var): a bind performs a real setlocale attempt and a failed
one warns 'setlocale: <name>: cannot change locale (<value>)' with a
strerror suffix only on the first failing attempt of a (category, name)
pair per process. rubash never warned at all: check_setlocale_warning
was a deliberate no-op.

src/locale.rs now mirrors the C flow for real: attempt_setlocale
clears errno, calls libc::setlocale and reports strerror(errno) only
when the call left it set (glibc's caching yields the suffix rule);
locale_assignment_warning reproduces set_locale_var/set_lang —
LC_ALL non-empty attempts once and warns; LC_ALL empty takes the
silent reset path; a category is attempted only while LC_ALL is
empty, with the get_locale_var precedence value (LC_ALL > own > LANG
> "", locale.c:343), so LANG=bad followed by LC_CTYPE= warns about
LC_CTYPE carrying LANG's value; LANG never warns. init_locale primes
with setlocale(LC_ALL, "") like set_default_locale (locale.c:85),
then warns for a bad environment LC_ALL with the argv[0] prefix, no
line number and no suffix — startup LANG/LC_* stay silent, as in GNU.

Executor wiring: note_locale_assignment fires GNU's watcher at every
true bind — the assignment store tail, the tempenv shadow store,
declare's two bind paths, export/readonly gated on an actual value
operand (a name-only export merely marks the attribute in GNU and
must not warn), tempenv teardown restores, function-frame pops, the
dispatch merge restore and the for-loop variable bind. A simple
command's tempenv is deferred in execute_materialized_command until
its class is known: GNU binds tempenv only for builtin/function
commands (a disk command's assignments become child-env entries), so
deferred binds flush for the binding classes and drop for disk
commands. The stale post-hoc stub call in the export builtin is gone
(its sync_process_locale stays).

No interplay with the rubash#1531 LC_COLLATE watcher or the
rubash#1533 C-locale byte-semantics pins: locale readers stay
env-driven, and the process locale now actually follows binds the
way GNU's does.

Regression: tests/issue1692_setlocale_warning.rs — assignment form
(suffix on first failure only), category form, silent cases, startup
LC_ALL-only warning, tempenv external-silent vs builtin-warns.
Expected text is literal GNU bash 5.3.20 output.
…nings

attempt_setlocale cleared and re-read errno via libc::__errno_location(),
a glibc-only spelling: the libc crate exposes it neither on Darwin
(__error) nor on Android's bionic (__errno), so the lib failed to compile
on macOS and in the darwin/android cross-target checks (E0425 in the
macOS, cross-darwin and cross-android CI jobs on PR #1793). Route both
accesses through a cfg-dispatched errno_location() helper instead:
glibc/musl keep __errno_location, Darwin and FreeBSD use __error, and
Android uses __errno.

The clear-before / read-after protocol mirroring GNU locale.c:191
set_locale_var is unchanged, so observable behavior on Linux/glibc is
identical (the strerror suffix still appears only on the first failing
bind of a locale name): issue1692_setlocale_warning passes 5/5 and the
lib suite holds its baseline of 771 passed / 1 failed
(ownership_unary_operators_check_existing_file, pre-existing) / 1
ignored. Cross-target compilation itself is adjudicated by CI; this
machine has neither a Darwin-capable C toolchain nor an Android NDK
for the dependencies' cc-rs build scripts.
@caomengxuan666

Copy link
Copy Markdown
Member Author

errno 可移植性修复已推送(0030f2c4)

CI 四红中的三红同根,已定性并修复:

  • 定性:Rust tests (macOS)、Cross-target (linux/android)、Cross-target (darwin) 全部是 error[E0425]: cannot find function '__errno_location' in crate 'libc'(lib 与 lib test 各一份)。出处是本 PR 的 [bug] Missing setlocale warning for invalid LC_ALL (startup env and assignment) #1692 commit 6537b06c:src/locale.rs 的 attempt_setlocale 无条件调用 glibc 专属的 libc::__errno_location()——Darwin 的拼写是 __error(),Android bionic 是 __errno(),libc crate 在这两个目标上不暴露 __errno_location。
  • 修法(commit 0030f2c,只动 src/locale.rs,+46/−2):新增 cfg 分派的 errno_location() helper——glibc/musl 走 __errno_location、Darwin/FreeBSD 走 __error、Android 走 __errno——attempt_setlocale 的清零与读回两处改走 helper。清零→setlocale→读回的协议(镜像 GNU locale.c:191 set_locale_var)不变,glibc 上可观察行为逐字不变:strerror 后缀仍只在每个 locale 名字的首次失败绑定时出现。
  • 本地验证(修复树,经构建槽):issue1692_setlocale_warning 5/5 全过(同跑 issue1690 1/1、issue1691 3/3 亦全过);lib 全套 771 passed / 1 failed / 1 ignored,唯一失败 ownership_unary_operators_check_existing_file 与本树基线失败集全等。
  • 跨目标本地 check(如实):本机装有 darwin/android 的 rustup 目标,但两个目标的本地 cargo check 都倒在依赖的 cc-rs 构建脚本上(本机 gcc 不认 -arch x86_64 且无 macOS SDK;无 Android NDK clang),到不了 Rust 代码——跨目标编译以本轮 CI 结果为准。
  • goldens:upstream_suite_slice_snapshots 与 master 尖同红,属共享项,本 commit 不碰快照。

@caomengxuan666
caomengxuan666 marked this pull request as ready for review October 26, 2026 19:37
@caomengxuan666
caomengxuan666 merged commit 41fdf7a into master Oct 26, 2026
8 of 9 checks passed
@caomengxuan666
caomengxuan666 deleted the fix8/procsub branch October 30, 2026 01:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant