Skip to content

fix(shell): source --rcfile once in interactive shells (#312) - #712

Merged
caomengxuan666 merged 1 commit into
masterfrom
fix/rcfile-double-source
Oct 17, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
fix/rcfile-double-source

Conversation

@caomengxuan666

@caomengxuan666 caomengxuan666 commented Oct 17, 2026 •

Copy link
Copy Markdown
Member

fix(shell): source --rcfile once in interactive shells (#312)

What

rubash --rcfile gate.sh -i < /dev/null ran gate.sh TWICE (append
probe: 2 lines); GNU sources once. run_startup_files sourced the
override, then each driver's direct run_init_file call sourced it
again. (The non-interactive --rcfile x -c sourcing is a deliberate
rubash extension — GNU ignores it there — and is preserved.)

Fix

run_startup_files records the sourced override in
__RUBASH_SOURCED_RC; all four drivers' direct calls skip it then
(via init_file_needs_direct_run). Leftover shapes keep the direct
call: empty-HOME early return, non-interactive extension, login.
#297 exit-in-rc semantics unchanged (verified A, rc 7, no XC).

GNU: shell.c:722 run_startup_files.

Verification

  • Append probe: 1 line; issue312 file 6/9 → 9/9.
  • issue297_300 10/10; lib 596/596.
  • Full serial failure-set gate vs master: per-target results match
    except the fixed file itself (9/0 vs 6/3). Zero NEW tests; the 2
    DISAPPEARED are fixed tests. (The tool's cli_tests/issue297_300
    NEW-target rows are the known parse artifact — per-target rows are
    byte-identical.) No regression.
  • niubash product A/B (niubash pinned 6295367, only rubash [patch]
    switched): 9 vs 8, the single extra is the known
    epochrealtime load flake (extensively proven both directions).

run_startup_files sourced --rcfile, then each driver's direct
run_init_file call sourced it again: --rcfile gate.sh -i ran the file
twice. run_startup_files records the sourced override in
__RUBASH_SOURCED_RC; the four direct calls skip it then, keeping the
leftover shapes (empty HOME, non-interactive extension). #297 exit
semantics unchanged.

issue312 file 9/9 (was 6/9); 297 file 10/10; lib 596/596.
@caomengxuan666

Copy link
Copy Markdown
Member Author

Self-review pass (no approval):

Verified from the diff. One file (src/main.rs), +24/−4, all checks green. The change is a handshake: run_startup_files records the rc override it sourced in __RUBASH_SOURCED_RC, and the drivers' direct run_init_file call now skips exactly that file via init_file_needs_direct_run (non-runnable shapes — empty HOME, non-interactive extension, login — still get the direct call). That reads correctly and the issue312 gate test is the right pin.

Two observations, both non-blocking:

  1. Merge-order: fix(invocation): accept clustered short options (#382) #697 shares this file. PR fix(invocation): accept clustered short options (#382) #697 (fix/382-option-cluster) also edits src/main.rs (the invalid-short-option check now consults usage::SHORT_OPTIONS). Different hunks, low conflict probability, but land fix(invocation): accept clustered short options (#382) #697 first and rebase here if the merge complains.
  2. Design note for the [design] are S3/S6/S9 + the dual-store one anti-pattern (state mirrored across N sites, synced by hand)? if so the boundary is the lever #717 typed-state discussion. __RUBASH_SOURCED_RC is another env-var-as-state handshake — mechanically consistent with the repo's existing __RUBASH_* family (and the marker is read back only inside this process's startup path), so fine for this fix. Worth one line in the commit or PR body saying the marker must never be inherited by a child shell, or the child's own startup would skip sourcing; if anyone ever exports it, that is a silent bug. (Same family rubash#717 is analysing — not a request to redesign this PR.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant