Repository navigation
fix(startup): login profiles source the GNU chain; every startup file's exit ends the invocation (#399) - #412
Conversation
… startup file's exit ends the invocation (#399) #402/#403 wired the top-level-exit jump for the rc file faces; the remaining #399 surface is the login path and the two env-file branches GNU ends the shell on as well. - A login shell (-l/--login or a leading-dash argv[0]) now sources /etc/profile (resolved through the shell root) and the FIRST EXISTING of ~/.bash_profile, ~/.bash_login, ~/.profile - the engine's login_profile_files order - instead of falling through to the rc or BASH_ENV branches (shell.c:1833), interactive or not, with --rcfile never consulted. --noprofile skips the files but keeps the branch. - The chain rides the #402 exit-jump plumbing: an exit in a profile ends the invocation with that status before the prompt, command string, or script runs, on every face (REPL, piped -i, -i -c, -l -c, -l script, stdin). - A BASH_ENV/NIU_ENV exit and a posix $ENV exit propagate the same way (GNU oracles: rc 6 and rc 5, the command never runs). - repl.rs: bind run_startup_rc()'s Option before the 'if let' - the scrutinee's borrow_mut temporary (edition 2021) made every rc or profile exit in the REPL panic 'RefCell already borrowed' and exit 1 instead of carrying the status. Verified against WSL GNU Bash 5.3.0 (scratch HOME, stdin method): a profile exit 9 under -l -c prints the marker and exits 9 with no BODY; -l -i -c sources /etc/profile plus the profile and never ~/.bashrc or BASH_ENV; --noprofile sources nothing; -l script with a profile exit runs no script. Regressions in tests/interactive.rs (the driver gains spawn_shared_home_with_args).
d8ec672 to
52de574
Compare
caomengxuan666
left a comment
There was a problem hiding this comment.
CR verdict: approve (no blocking findings) — core claims independently verified
I re-derived this on top of 7c42373 with my own probes (WSL GNU Bash 5.3.0, plus a built base-vs-branch comparison on this host).
Verified:
- Root cause: on 7c42373,
-l/--loginis parsed (legacy-c -lshape, help text) but no startup path sources any profile —run_startup_filesonly knows the posix-ENVand rc branches andsource_non_interactive_envgoes straight to BASH_ENV/NIU_ENV. Confirmed at source level and at runtime. - The claimed RefCell latent bug is real and is exactly as described: on a pristine 7c42373 build, a plain REPL session whose rc ends with
exit 5panicsRefCell already borrowedat repl.rs:1974 (theif letscrutinee temporary holds the borrow while the EXIT-trap path re-borrows) and exits 1. On this branch the same session exits 5, no panic, no prompt rendered. The fix (bind the Option before theif let) is minimal and correct, and the paste area is untouched (repl.rs diff is exactly the 3-line bind; no PasteChunkEditMode/translate_event changes). - GNU order: /etc/profile → FIRST EXISTING of .bash_profile/.bash_login/.profile, never the rc — matches my WSL probes (.bash_login beats .profile once .bash_profile is removed; -l -i sources no rc).
-l --noprofilemisparse pinned correctly: GNU 5.3 here also fails withbash: --: invalid option; the working order--noprofile -lskips the chain while keeping the login branch (no rc fall-through — probe-confirmed). - Exit-jump plumbing on every remaining face (profile, BASH_ENV, posix $ENV, REPL login) mirrors the #402 discipline; the completion-probe call correctly discards the Option (synthetic surface, never login).
- Tests: the 10
issue399_*cases pass 4/4 runs at--test-threads=1. Fullinteractivetarget: only the base-confirmed environment failures fail — I reproducedcontinuation_single_quote,continuation_subshell_paren,gitbash_factory_promptidentically on a pristine 7c42373 build (ctrl_c/ctrl_d passed in my run — flaky-env, consistent with your list).startup_files/completion_probe/repl_command/issue404_406_invocation_surface/smokegreen;host_contract rubash_setopt...andniubash-runtime test_get_builtin_commandsfail identically on base (pre-existing env). - Diff surface: files match the PR description exactly; no GPL fragments or translation-style wording.
Non-blocking findings
-
GNU parity overclaimed on three additive/posix faces — shells.rs:1260-1261 ("never BASH_ENV"), :1137 (login branch before posix), :1291. My WSL 5.3 probes: (a)
bash -l -cwith BASH_ENV staged sources profile AND BASH_ENV — BASH_ENV is not gated on login-ness for non-interactive shells; (b)bash --posix -l -csources nothing (posix suppresses the login chain; no ENV non-interactively); (c)sh -l -i -csources profiles and $ENV. This PR makes login strictly exclusive, so niu diverges on those rows while its comments cite shell.c as the authority. The oracle table only covers-l -i -c+ BASH_ENV (where interactivity already suppresses BASH_ENV), so the exclusivity was never GNU-checked. Minor in practice (BASH_ENV+login and --posix+login are rare), and internal consistency with the rubash engine's own (equally exclusive) dispatch is preserved — but the comment wording presents GNU-verified behavior that isn't. Either soften the wording or follow the additive model. -
The RefCell fix ships with no regression test. None of the 10 new cases covers the plain (non-login) REPL rc-exit face — the exact path the 3-line repl.rs fix repairs (and no pre-existing test covers it either, which is how the panic survived #402). I verified it manually both ways; please add one
spawn_customcase (rc endsexit 5→ session status 5, no prompt).
Merge-order note
Whichever of #412/#413 merges second needs a trivial EOF conflict resolution in tests/interactive.rs (both append their block at the same anchor); driver.rs and shell.rs auto-merge.
…orm; login env gates stay independent (review round) CR round on #413 and #412. #413 blocking - activation timing: the rbash face armed the restricted option inside Shell::new, before any startup file runs, while the -r/--restricted flag form activates in the engine's ShellInvocation::finish_startup (invocation.rs: 'after the host finishes startup files' - the deliberate GNU order). The divergence was runtime-visible: 'rbash.exe -c' refused a BASH_ENV file with '.: <path>: restricted' and 'rbash -l -c' refused the whole profile chain, where the flag form and GNU load both fine. Shell::new now only records the face mark (one line keyed off unmarked_name, dropping the redundant .exe strip and '-' strip); the option write moved into Shell::finish_startup, right beside the flag write. Startup-file equivalence is pinned by a test: argv0 face and flag form load BASH_ENV and the profile chain identically and go restricted for the command line. CR's two blocking repros both pass. #412 follow-ups: three comments over-claimed GNU exclusivity and the behavior followed them - the login profile chain replaces only the interactive-RC branch, while the env-file gates are independent of login state: 'bash -l -c' sources the chain AND BASH_ENV (shell.c 1214-1220 keys on interactivity/posix), and 'sh -l -i -c' sources the chain AND $ENV (shell.c 1238-1246 keys on posix+interactive). Both re-measured against the WSL 5.3.0 oracle and implemented. Also adds the missing regression for the run_repl RefCell fix: a plain REPL with 'exit 5' in the rc ends with status 5 and no panic.
…orm; login env gates stay independent (review round) CR round on #413 and #412. #413 blocking - activation timing: the rbash face armed the restricted option inside Shell::new, before any startup file runs, while the -r/--restricted flag form activates in the engine's ShellInvocation::finish_startup (invocation.rs: 'after the host finishes startup files' - the deliberate GNU order). The divergence was runtime-visible: 'rbash.exe -c' refused a BASH_ENV file with '.: <path>: restricted' and 'rbash -l -c' refused the whole profile chain, where the flag form and GNU load both fine. Shell::new now only records the face mark (one line keyed off unmarked_name, dropping the redundant .exe strip and '-' strip); the option write moved into Shell::finish_startup, right beside the flag write. Startup-file equivalence is pinned by a test: argv0 face and flag form load BASH_ENV and the profile chain identically and go restricted for the command line. CR's two blocking repros both pass. #412 follow-ups: three comments over-claimed GNU exclusivity and the behavior followed them - the login profile chain replaces only the interactive-RC branch, while the env-file gates are independent of login state: 'bash -l -c' sources the chain AND BASH_ENV (shell.c 1214-1220 keys on interactivity/posix), and 'sh -l -i -c' sources the chain AND $ENV (shell.c 1238-1246 keys on posix+interactive). Both re-measured against the WSL 5.3.0 oracle and implemented. Also adds the missing regression for the run_repl RefCell fix: a plain REPL with 'exit 5' in the rc ends with status 5 and no panic.
Root cause
-l/login invocations parsed the flag but never sourced any login file:run_startup_filesonly knew the interactive-rc branch and the non-interactive callers went straight to BASH_ENV, soniu -l -c 'cmd'ran the command with no profile at all (master-verified in the issue: none of.bash_profile/.bash_login/.profile/.niubashrcwas read). With no profile sourced, the ticket's exit face had nothing to fire through. Two smaller faces of the same item were also unwired: the BASH_ENV/NIU_ENV sourcing and the posix `` sourcing discarded the #402 exit-jump thatsource_startup_filealready returned, and the REPL's #402 wiring borrowed the shell twice inside an `if let` scrutinee (edition-2021 temporaries), so any rc/profile `exit` in the REPL panicked `RefCell already borrowed` and exited 1 instead of carrying the status.What this PR does
invocation::login_profile_filesorder): a login shell —-l/--loginor a leading-dashargv[0]— sources/etc/profile(resolved through the shell root, so a winuxcmdetc/profileanswers when one ships) and the FIRST EXISTING of~/.bash_profile→~/.bash_login→~/.profile, instead of the rc / BASH_ENV branches, interactive or not.--rcfileis never consulted on the login face;--noprofileskips the files but keeps the branch.exitin a profile, in the BASH_ENV/NIU_ENV file, or in a posix `` file ends the invocation with that status before the prompt/command/script runs — REPL, piped-i, `-i -c`, `-l -c`, `-l script`, and the piped stdin route.run_startup_rc()'sOptionbefore theif letso the EXIT-trap borrow is legal. This is the only repl.rs touch, outside the paste-input editing area (PasteChunkEditMode / translate_event are untouched).GNU oracle (WSL GNU Bash 5.3.0, stdin method, scratch HOME)
.bash_profile=echo m; exit 9,-l -c 'echo BODY'm, rc 9, no BODYBODY, rc 0m, rc 9, no BODY-l -c.bash_profile).profilestaged,-l -c--noprofile -l -c(working flag order; GNU 5.3 misparses-l --noprofileas--)-l -i -cwith rc + BASH_ENV staged-l scriptwith profileexit 9BASH_ENV=exit 6,-cENV=exit 5,--posix -i -c--rcfile F -i -c+exit 7(already fixed by #403)Tests
10 new cases in
tests/interactive.rs(issue399_*, execution-level markers + exit statuses,--test-threads=1); driver gainsspawn_shared_home_with_argsso a test can stage profile files before the process exists. Full interactive target: all tests pass except 5 pre-existing environment failures (continuation_single_quote/paren,ctrl_c_interrupts_external_command,ctrl_d_after_background_job,gitbash_factory_prompt) that fail identically on a pristineorigin/masterbuild on this host.startup_files,host_contract,niubash-runtimelib tests, and the invocation-surface targets all pass.Closes #399 (items 2/3 of the ticket body — the
-i -coption set (himBHc) — are a separate surface and untouched here; item 1 is this PR plus the already-merged #403).