Repository navigation
fix(cli): CLI entry semantics — posix -c fatal exit 127, invocation-face $0, -s in $- (closes #589 #590 #591) - #598
Merged
Conversation
… and -s in $- (closes #589 #590 #591) #589 -c fatal exit mapping: a POSIX special-builtin/assignment violation terminated with 1 in every entry shape. GNU jumps FORCE_EOF with last_command_exit_value = EXECUTION_FAILURE and re-maps it per entry: shell.c:1471-1472 run_one_command ('case FORCE_EOF: return last_command_exit_value = 127') for -c, eval.c:104-109 reader_loop keeps last_command_exit_value (1) for script/stdin, execute_cmd.c:1811 contains the jump at 1 inside subshell children. Producers: subst.c:13177-13182 (expand_word_list_internal is_nullcmd arm -> posix_variable_assignment_error(0)), subst.c:13186-13195 (tempenv arm -> bash_variable_assignment_error(is_special)), subst.c:11169-11196, execute_cmd.c:3085-3089 (execute_for_command readonly bind), execute_cmd.c:3587-3592 (execute_select_command readonly bind). WSL 5.3.0 oracle: nullcmd 127, tempenv-special 127, for 127, select 127, subshell-contained 1, script/stdin 1, ordinary-builtin tempenv nonfatal 0. The six fatal arms now route through expansion_fatal_status(), the established context owner of that mapping (parameter_errors.rs:845). #590 invocation face for $0: GNU set_shell_name (shell.c:1778-1806) binds dollar_vars[0] = argv[0] (shell.c:1797-1799) and keys the sh/ash (shell.c:733-737) and rbash (shell.c:1258-1299) contracts off its basename. The shim forwarded only sh/ash, so 'bash.exe -c echo $0' lost the face and the host reported its product name. forwarded_invocation_name now forwards sh/ash/bash/rbash (leading dash preserved, .exe stripped) and the engine consumes NIU_INVOKED_AS as the erased argv[0] — before the process-env import, ranked behind an explicit BASH_ARGV0 (variables.c:1547-1555), feeding set_shell_name's $0 slot and apply_invocation_shell_mode. The stdin-script driver binds $0 from the resolved face, not the engine path. Hosts that consume NIU_INVOKED_AS themselves keep their own flow (niubash#262 companion applies for the bash stem). #591 -s in $-: flags.c:294-306 which_set_flags appends 's' while read_from_stdin (shell.c:301) is set; shell.c:928 records the explicit -s at option-parse time. The engine's own drivers armed the marker inside run_stdin_script / run_interactive_stdin, so a library host driving its own stdin reader lost the letter ('printf echo [$-] | niu -s' printed [hB] against GNU [hBs]). ShellInvocation::apply_to_executor now arms the read-from-stdin marker for every -s invocation — the shared surface every host calls. Tests: tests/issue589_posix_special_fatal_c_exit_regressions.rs (10 cells against the WSL 5.3.0 matrix), tests/issue590_dollar0_invocation_face_regressions.rs (9 cells: shim chain per face, consume-on-read, BASH_ARGV0 ranking, -c operand, stdin-script face), tests/issue591_stdin_script_dollar_minus_regressions.rs (6 cells: -s/no-operand/-c/script-file shapes, process-local marker, apply_to_executor library contract). cargo check + -D warnings clean, fmt applied.
…n-script driver, resolve run_stdin_script conflict
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.
One CLI-entry patch, three tickets, each anchored in the vendored bash source (bash-5.3-16-gb4608166, zero copied code) and probed cell-by-cell against WSL GNU 5.3.0 (
wsl -e bash, 2026-10-13).#589 — posix special-builtin/assignment fatal exits 127 under -c
Root cause. GNU raises the fatal as a FORCE_EOF jump with
last_command_exit_value = EXECUTION_FAILURE, and the entry re-maps it:shell.c:1471-1472 run_one_command(case FORCE_EOF: return last_command_exit_value = 127) for-c, whileeval.c:104-109(reader_loop) ends script input and exits withlast_command_exit_value(1), andexecute_cmd.c:1811contains the jump at 1 inside subshell children. Producers:subst.c:13177-13182(expand_word_list_internal is_nullcmd arm →posix_variable_assignment_error(0),subst.c:11181-11196),subst.c:13186-13195(tempenv arm →bash_variable_assignment_error(is_special_builtin),subst.c:11169-11180),execute_cmd.c:3085-3089(execute_for_command readonly bind),execute_cmd.c:3587-3592(execute_select_command readonly bind). Rubash hardcoded ExitCode(1) at every fatal arm.Fix. The six fatal arms (command_dispatch.rs standalone-assignments + tempenv-special, command_prepare.rs empty-words assignment, loop_select.rs both for-arms, select_exec.rs select arm) now route through
expansion_fatal_status()(parameter_errors.rs:845) — the established single owner of the -c→127 / script→1 / subshell→1 mapping.WSL 5.3.0 matrix (script +
-c): nullcmdro=2127 (was 1) · tempenv-specialro=2 :127 (was 1) · for-bind 127 (was 1) · select-bind 127 (was 1) · same-linero=2; echo post127 ·(ro=2)contained, parent $? = 1, shell rc 0 ·ro=2 truenonfatal 0 ·x=${ro:=v}0 ·read ro0 · stdin-script 1 · script file 1 · default mode 0. Every cell matches GNU after the fix.#590 — $0 follows the invocation face
Root cause.
shell.c:1778-1806 set_shell_namebindsdollar_vars[0] = argv[0]verbatim (shell.c:1797-1799) and keys the sh/ash (shell.c:733-737) and rbash (shell.c:1258-1299) contracts off its basename. The #504 shim forwarded only sh/ash, sobash.exe -c 'echo $0'lost the face and the host reported its product name.Fix.
forwarded_invocation_name(src/bin/bash.rs) forwards sh/ash/bash/rbash (leading-login marker preserved,.exestripped; other names still scrub). The engine consumesNIU_INVOKED_ASas the erased argv[0] — read before the process-env import so the name never becomes a shell variable, ranked behind an explicitBASH_ARGV0(variables.c:1547-1555), feeding bothset_shell_name's $0 slot andapply_invocation_shell_mode(posix on for sh, rbash restricted, login marker). Consume-on-read keeps the #504 isolation: a nestedsh -c 'bash -c ...'re-forwards its own face.Probes (shim + engine chain):
sh -c 'echo $0'→sh+ posix on ·bash -c 'echo $0'→bash·rbash -c 'echo $0'→rbash· $NIU_INVOKED_AS invisible in the shell env ·BASH_ARGV0=customstill outranks the face · explicit-coperand still wins · stdin script reports the face.Companion note. Product hosts that consume NIU_INVOKED_AS in their own runtime (niubash Shell::new, per #504/#262) need the same one-line extension to honor the bash stem; this PR keeps the engine-side contract complete and tested (engine honors the variable directly, tests exercise the full shim→engine chain).
#591 —
=sshowssin $-Root cause.
flags.c:294-306 which_set_flagsappendsswhileread_from_stdin(shell.c:301) is set;shell.c:928records the explicit=sat option-parse time. Rubash armed the marker only inside its own stdin drivers, so a library host driving its own stdin reader lost the letter:printf 'echo [$-]' | niu -sprinted[hB]against GNU[hBs].Fix.
ShellInvocation::apply_to_executor(src/invocation.rs) armsREAD_STDIN_MARKERfor every=sinvocation — the shared surface every host calls.-carms nothing ([hBc]both sides), script files neither ([hB]).Verification
tests/issue589_posix_special_fatal_c_exit_regressions.rs(10 cells),tests/issue590_dollar0_invocation_face_regressions.rs(9),tests/issue591_stdin_script_dollar_minus_regressions.rs(6) — all green, alongside the merged [cli] invocation-name-aware help is forked: bash --help / sh --help print the niu product help instead of the GNU usage contract #585/[cli][P1] -s stdin-script pre-buffers the whole stream: $(exec cat) hits EOF and unconsumed data lines execute as code (#583 -c/-s gap) #586/[exec][P1] pipeline members skip shell functions: 'date(){ echo FAKE; }; date | cat' runs the external date #587/[path][P1] PATH lookup falls back to the embedded /bin and Windows search after an assignment: 'PATH=/nonexistent; hash -r; ls' runs ls, rc 0 #588 test files.cargo check+RUSTFLAGS="-D warnings" cargo checkclean;cargo fmtapplied.RUST_TEST_THREADS=1 cargo test --no-fail-fast: failure set bidirectionally identical (comm empty) to fresh origin/master (306c001), 41 known environment failures on both sides; same result against the pre-merge b5e1a2f base.closes #589, closes #590, closes #591