Repository navigation
fix(startup): a top-level exit in the user rc terminates the invocation (#402) - #403
Merged
Merged
Conversation
…on (#402) A top-level `exit` (or errexit unwind) executed while the startup rc is sourced was flattened into an ordinary command status: the command line still ran and the shell exited 0, where GNU ends the shell with that status (jump_to_top_level EXITPROG unwinds reader_loop). `source_startup_file` / `run_startup_files` now report the engine's `ExitCode` unwind, and the invokers (`-i -c`, `-i script`, the piped `-i` driver, `-C`, and the REPL) terminate with that status before running the rest. The synthetic `. <path>` source bypasses the grouped readers, which otherwise swallow the unwind before the caller can observe it. Verified against WSL GNU Bash 5.3.0 (file-based rc, `-i -c 'echo AFTER'`): rc "echo RAN; exit 3" -> RAN, rc 3, no AFTER rc "echo RAN; exit 0" -> RAN, rc 0, no AFTER rc "echo RAN" -> RAN, AFTER, rc 0 rc "false" -> AFTER, rc 0 (maybe_execute_file: warn + keep going) rc "set -e; false" -> rc 1, no AFTER The `set -e` case was previously swallowed too; the engine classifies exit and errexit with the same `ExitCode` unwind (GNU EXITPROG/ERREXIT), so it now matches GNU. Regression tests added in tests/startup_files.rs. Closes #402.
caomengxuan666
added a commit
that referenced
this pull request
Oct 18, 2026
… 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).
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
Closes #402. A top-level
exit(or an errexit unwind) executed while the startup rc is sourced was flattened into an ordinary command status, so the caller's command line still ran and the process exited 0. GNU ends the shell with the rc's status (jump_to_top_level EXITPROGunwindsreader_loop) and never runs the command line.Change
source_startup_filerecords the engine'sExitCodeunwind (execute_script_innersetsscript_exit_jump) and returns the status;run_startup_files/run_startup_rc/run_interactive_startup_rcpropagate it.-i -c,-i script, the piped--iengine driver,-C, and the REPL (which ends the session before the first prompt, mirroring the existingPROMPT_COMMANDjump path).. <path>source bypasses the grouped readers (allow_grouped_readers=false); those read history/alias-bearing script text and swallow the unwind before the caller can observe it. The. <path>command is a single simple command, so the tokenize+parse+execute_ast route is equivalent.Verification (WSL GNU Bash 5.3.0, file-based rc,
-i -c 'echo AFTER')echo RAN+exit 3echo RAN+exit 0echo RANfalseset -e+falseThe
set -erow was previously swallowed too; the engine classifiesexitand errexit with the sameExitCodeunwind (GNUEXITPROG/ERREXIT), so both now match GNU.Tests
tests/startup_files.rs:issue402_exit_in_rcfile_terminates_before_command_line,issue402_exit_in_default_rc_terminates_repl_command,issue402_startup_rc_guards(no-exit /exit 0/ plain failing rc).startup_files29/29,repl_command11/11,issue359_startup_pty2/2,niubash-runtime --lib538/538;cargo fmt --checkclean.