Skip to content

WIP: startup shape from own argv, not inherited carriers (rubash#2129, #2133) - #2138

Merged
caomengxuan666 merged 2 commits into
masterfrom
fix/2129-startup-carrier-recursion
Oct 29, 2026
Merged

caomengxuan666 merged 2 commits into
masterfrom
fix/2129-startup-carrier-recursion

Conversation

@caomengxuan666

@caomengxuan666 caomengxuan666 commented Oct 29, 2026 •

Copy link
Copy Markdown
Member

WIP: startup shape from own argv — inherited-carrier recursion fix

What

run_startup_files chose its branch by reading the
__RUBASH_INTERACTIVE / __RUBASH_LOGIN_SHELL env carriers, which an
interactive parent exports to every child. A -c child that merely
inherited both adopted the parent's interactive-login shape,
re-sourced the startup chain, and — with fzf's completion procsub
line in rc/profile — recursed without bound (field report: Android/
Termux, one blocked generation per ~0.15s).

GNU decides startup behavior from the invocation itself
(shell.c:540-549, shell.c:497-503, shell.c:269-270;
execute_cmd.c:1576 for respawned children). The fix keys every
startup-shape decision on this process's own argv plus the explicit
respawn marker, at the child's entry decision point:

  • OWN_INTERACTIVE_SHELL / OWN_LOGIN_SHELL statics recorded at every
    own-argv site (-i, -l/--login, argv[0] -, the tty pair);
    branch selection and the -c init/history gates read own shape.
  • Respawn door first in run_startup_files: a respawned internal
    child runs no branch, $BASH_ENV included.
  • An unearned inherited __RUBASH_LOGIN_SHELL carrier is dropped,
    so the logout face and this process's children never see it.
  • The F6 suppressor face: the intra-process startup-carrier family
    is stripped consume-on-read at run_main entry (the NIU_INVOKED_AS
    rule), so an inherited __RUBASH_NO_PROFILE / __RUBASH_NO_RC /
    __RUBASH_STARTUP_FILES_DONE / __RUBASH_SOURCED_RC can no longer
    defeat this process's own explicit -l / -i; only its own
    --noprofile / --norc argv arms re-arm the suppressors.

Spawn-side filtering is not the rule: the spawn whitelist is
structurally defeated by the unfiltered process_env_pairs() base
(compound_exec.rs:767, external_setup.rs:1261,
command_substitution.rs:1877) and the input-procsub site's additive
.env() inheritance (trap_exec.rs:3249). Full census and provenance
in the cluster REPORT (bisect redo: the adoption wiring dates to
29da109, 2026-10-10, rubash#487 — the live exposure is the niu
Session-migration composition; a niu-side funnel fix is specified
separately and not in this PR).

Verification

  • Pins tests/issue2129_startup_carrier_recursion.rs: 15/15 on the
    fixed tree; 10 red / 5 green on baseline (greens are the guard
    pins). Watchdog-bounded, counter-file generation counting.
  • Probe battery (35 checks): fixed 35/35; baseline 13 red;
    rebuilt d15a02d 11 red.
  • Regression targets green: rubash 自带交互循环下 nvm ls 出现 event-not-found 与 line 13 语法噪声(niu 宿主无此面) #2072 pins, issue1158_bashrc_compat,
    issue1830, issue1852, debugger_flag_gnu_parity,
    issue1076_startup_variables, bin login_shell_tests, niubash_404
    exit-echo pin. One adjacent pre-existing red
    (issue_1306_dash_c_mode_leaves_bash_source_unset) fails
    identically on pristine master — not this diff.

Refs #2129(引擎侧;niu 宿主漏斗面由 niubash 配套 PR 承载关单)
Fixes #2133

…(rubash#2129, #2133)

run_startup_files chose its branch by reading the __RUBASH_INTERACTIVE /
__RUBASH_LOGIN_SHELL env carriers, which an interactive parent exports
to every child (Executor::set_env mirrors __RUBASH_* into the process
env). A -c child that merely inherited both markers adopted the
parent's interactive-login shape, re-sourced the startup chain, and —
with an rc/profile line that respawns the shell (fzf's completion
procsub) — recursed without bound. GNU decides startup behavior from
the invocation itself: shell.c:540-549 (interactive only for
forced_interactive/-i or the no-operand tty pair), shell.c:497-503
(LOGIN_SHELL only from -l/--login, argv[0] '-' mark in
set_shell_name), shell.c:269-270 (no_rc/no_profile are this
invocation's own option-parse flags), execute_cmd.c:1576
(execute_in_subshell: a respawned child inherits post-startup state).

- OWN_INTERACTIVE_SHELL / OWN_LOGIN_SHELL statics recorded at every
  own-argv site (-i, -l/--login, argv[0] '-', the tty pair); branch
  selection, the -c interactive-init gate and the history gate read
  own shape, never the carriers.
- run_startup_files: respawn door first (RESPAWNED_CHILD runs no
  branch, $BASH_ENV included); an unearned inherited
  __RUBASH_LOGIN_SHELL carrier is dropped so the logout face
  (builtins/exit.def:79-90) and children never see it.
- #2133: the run-once guard is the process-local STARTUP_FILES_DONE
  static — as the __RUBASH_STARTUP_FILES_DONE carrier it was exported
  to children and suppressed a genuine nested login shell's own
  profile chain.
- #2133/F6: run_main strips the intra-process startup-carrier family
  (__RUBASH_STARTUP_FILES_DONE, __RUBASH_SOURCED_RC,
  __RUBASH_NO_PROFILE, __RUBASH_NO_RC) consume-on-read before
  Executor::new imports the environment — the NIU_INVOKED_AS rule —
  so an inherited suppressor can no longer defeat an explicit -l/-i;
  only this process's own --noprofile/--norc argv arms re-arm them.

Why not filter at spawn: the spawn whitelist is structurally
defeated by the unfiltered process_env_pairs() base
(compound_exec.rs:767, external_setup.rs:1261,
command_substitution.rs:1877) and the input-procsub site's additive
.env() inheritance (trap_exec.rs:3249) — the rule belongs at the
child's entry decision point.
…#2129, #2133)

15 watchdog-bounded, counter-file pins: marker-injection zero-sourcing
(both markers and each single), the P0 repro terminating, own -lc/-ic
earning their branches, nested-login double sourcing (#2133),
inherited-suppressor vs own argv in both directions (F6), DONE never
visible to commands, $BASH_ENV sourced exactly once with a respawn
inside it, the logout face in both directions, and the fzf-shaped
interactive startup completing exactly once. Baseline: 10 red / 5
green (the greens are the guard pins); fixed: 15/15.
@caomengxuan666
caomengxuan666 marked this pull request as ready for review October 29, 2026 16:39
@caomengxuan666
caomengxuan666 merged commit a2fba85 into master Oct 29, 2026
11 checks passed
@caomengxuan666
caomengxuan666 deleted the fix/2129-startup-carrier-recursion branch October 30, 2026 01:41
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.

[bug] 哨兵反向泄漏:真嵌套登录/交互 shell 静默丢失启动文件(#2129 镜像面)

1 participant