Repository navigation
history -s inside a SEVAL_NOHIST unit appends without popping (Refs #2824) - #3238
Merged
Merged
Conversation
…r faces Refs-only pin commit (no behavior change): - issue2824_script_history_records_trap_line: a script-mode EXIT trap's history -s must not pop the recorded trap line itself (GNU builtins/history.def:435-439 push_history gates the pop on remember_on_history; trap actions run under SEVAL_NOHIST, trap.c:1069). - issue3093_debug_trap_history_order: the first DEBUG firing for a command must observe that command already recorded (interactive PTY cells plus a script-form regression lock). Byte-identical to the pins already in flight on the wave-2 pin branches; this copy rides with the fix so the pair lands together.
…efs #2824) GNU builtins/history.def:435-439 push_history pops the last entry only under remember_on_history. Trap actions run through parse_and_execute with SEVAL_NOHIST (trap.c:494/1069/1195) and the plain evalstring units carry the same flag; evalstring.c:291-292 turns it into bash_history_disable (bashhist.c:297-302) for the unit's duration, so inside any trap action or eval unit a history -s/-p appends without popping. Rubash gated the pop on the set -o history option alone, so an EXIT trap's history -s ate the recorded trap ... EXIT line itself (and the same wrong pop was reachable from DEBUG/ERR/RETURN/signal trap actions, eval, and PROMPT_COMMAND). - history_exec: the pop gate becomes history_remembering() - the option AND no SEVAL_NOHIST window (any *_trap_running flag, the PROMPT_COMMAND nohist marker, or the new eval-unit depth). - Executor::nohist_parse_depth counts execute_eval_source units (evalstring.c parse_and_execute funnels: eval, mapfile -C, and siblings); fork copies start at zero like a fresh GNU image. - The same-line legitimate pop at reader level is unchanged: no window is open there.
caomengxuan666
added a commit
that referenced
this pull request
Nov 11, 2026
…rp (W-I2) (#3239) driver: read-time set -v echo; job-control diagnostics print shell_pgrp (W-I2) Fixes #2773 Refs #2774 Wave-2 pin-to-fix lane W-I2 (driver / interactive face). The two pin files are carried verbatim from pin PR #3172 (branch `test/wave2-pins-i2`, head `64209f64`) as the first commit of this branch; that pin PR itself is left for the captain to dispose of. ## Mechanism Verbose echo (`set -v`): GNU echoes each input line to stderr as it is READ, under the flag state then in effect (flags.c:284 `echo_input_at_read = verbose_flag`; parse.y:2712 prints `shell_input_line`; heredoc secondary lines echo via make_cmd.c:584 `read_secondary_line`). The engine echoed the rendered command at execution time from `Executor::set_current_command`, which split `;`-joined lines per command, dropped comments, re-rendered compound bodies per stage and per iteration, and never echoed comment, blank, or continuation lines. - New single echo point `script_driver::echo_verbose_input_lines`, called at every real read point: the grouped reader's per-line consumption (`read_next_source_group`), the stdin script reader's per-line read (`run_stdin_script`), and the whole-string read boundaries (the `-c` and Session fast paths, and parse_and_execute strings via `execute_eval_source`). - New over-admitting routing scan `script_driver::script_may_toggle_verbose` (same family shape as `script_may_set_onecmd`): a text that may toggle verbose mid-read takes the grouped reader on the script-file, `-c`, and Session routes; a script file entered with verbose already on takes it too. The fast paths keep a single boundary echo, which is the same answer when the scan shows the entry state holds for every line. The scan only routes; it decides no semantics. - The execution-time echo arm in `set_current_command` is deleted (see the deletion section below). Job-control diagnostics: GNU prints `shell_pgrp` — jobs.c:4737 `shell_pgrp = getpgid (0)` at `initialize_job_control` entry, reported by jobs.c:4844/4853. Both establishment print sites printed the shell's pid instead; they now share `script_driver::shell_process_group_id()`. The monitor-mode establishment itself was already correct (the second pin is a regression lock, green before and after). ## GNU anchors - flags.c:284; parse.y:2712; make_cmd.c:584 - jobs.c:4731-4869 (4737, 4844, 4853, 4858, 4869); shell.c:1969 - All behavioral claims probed against GNU bash 5.3.20 (vendored oracle): `-c` strings read line by line like files (mid-string toggles start/stop the echo), heredoc body and delimiter lines echo, sourced-file lines echo with the toggle persisting after return, stdin scripts echo per line read, and the job-control diagnostic names the inherited process group when pid != pgid. ## Verification (captain review, local re-runs of the lane's box numbers) - Fail-first on the true merge-base `e1afd25d` with the two pin files topped up: verbose stem **1 passed / 7 failed**, the seven reds exactly the registered defect cells (sole green = the toggle cell); job-control stem 4 passed / 0 failed (regression lock). - Head `b613ba41`: verbose stem **8 passed / 0 failed**; job-control stem **4 passed / 0 failed** (scrubbed and plain-cargo routes agree). - Neighbor stems all green, 40 tests: case_command_head_bash_command_regressions 4, heredoc_regressions 3, issue1016_1072_1073_1254_1255_history_interactive_regressions 7, issue1040_ps4_xtrace_regressions 2, issue1102_exec_stdin_regressions 1, issue1252_interactive_defaults_regressions 3, issue1476_lastpipe_monitor_regressions 1, issue1494_jobs_refresh_regressions 2 (+1 pre-existing ignored residual cell), issue1563_eval_source_errexit_frame_regressions 13, issue1573_stdin_conditional_group_regressions 4. - Lib tests bilateral: head 1243 passed / 0 failed / 4 ignored; base 1243 passed / 0 failed / 4 ignored; failure-name sets empty on both sides, diff ∅. - `RUSTFLAGS="-D warnings"` on product code (`--lib --bins`, flag loading proven by touch + `-v`, 40 flagged rustc invocations): rc=0. The `--all-targets` form fails only on pre-existing dead-code cells in test files this branch does not touch (issue2634 on the head tree, issue2702 on the base tree — cargo stops at the first failing test target per tree, so the two runs surface different members of the same pre-existing family). - `cargo fmt --check` full tree: rc=0. UTF-8 boundary hygiene: clean. Marker-lint: OK (marker face untouched). - Cross-target: `cargo check --tests --target armv7-linux-androideabi` (NDK r26d recipe) rc=0; the head's pushed CI is fully green including the darwin and android cross-target legs (11 check-runs: 10 success, 1 skipped, 0 red). - Binary probe on the head build with pid != pgid (inner shell pid 49842, its process group 49841): the diagnostic prints **49841**, the process-group number, not the pid. ## Collision notes for sequencing This branch and PR #3238 (still open) both touch `src/executor/trap_exec.rs` in the same function (`execute_eval_source`): this branch adds the read-boundary echo at the function head (base lines ~1091-1097); #3238 wraps the inner call further down (base lines ~1116-1134). The hunks share no line, but a three-way merge after a master advance must be hand-read, and whichever of the two PRs merges second must, after its update-branch, re-run the other PR's pin stem on the merged tree in addition to its own (issue2824 stem if #3238 lands second; issue2773/issue2774 stems if this branch lands second). ## 本 PR 删除了什么 - The execution-time verbose echo arm in `Executor::set_current_command` (`src/executor/public_accessors.rs`): the `if shell_option_enabled(..., "verbose")` block that wrote the rendered `bash_command_source_text(cmd)` to stderr, together with its comment block (14 lines). The `$BASH_COMMAND` bookkeeping that shares the preamble is kept; only the echo is gone, replaced by a comment pointing at the read points. - Nothing else is deleted. The two job-control print sites keep their lines; only the printed value expression changes from the pid to the shared process-group helper.
GNU's two history deletes are asymmetric: push_history's -s delete is gated on remember_on_history (builtins/history.def:435-439), but the -p delete at the head of expand_and_print_history (history.def:462) is conditioned on hist_last_line_pushed/hist_last_line_added alone. The first version of this branch put both arms under history_remembering(), which stopped an eval-unit `history -p` from popping its eval line — a regression against the base, measured three-way against GNU bash 5.3.20. - Print arm: back to the plain `set -o history` option gate (the base form); Save arm unchanged (keeps the NOHIST gate). - Citations corrected in both arms' comments: the "-p same gate" reading of :462-463 was a mis-citation, and the delete returns 1 on success (bashhist.c:361 bash_delete_histent), so the C `== 0` comparison is a failure-only bail-out. - Three new cells in the issue2824 stem: eval -p pops the eval line, eval -s appends and keeps it, EXIT-trap -p pops the trap definition line (saved-file surface). Refs #2824
caomengxuan666
marked this pull request as ready for review
November 11, 2026 07:47
This was referenced Nov 11, 2026
Closed
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.
本 PR 的内容
三颗提交:先钉、再修、队长复核返工一颗。
95eb566ftest: W-HIST regression pins for the script history / DEBUG trap order facese7c24ca2the engine change described belowdbc04a12history -p: restore the ungated delete (captain-review rework)Refs #2824
Refs #3093
机制与 GNU 依据
GNU 的两个历史删除并不对称:
push_history(history -s)的删除只在remember_on_history为真时才发生(builtins/history.def:435-439,删除条件活支;删除成功返 1 ——
bashhist.c:361
bash_delete_histent——== 0只是删除失败时的bail-out,成功后照常走追加)。
expand_and_print_history(history -p)的删除在其函数头部(builtins/history.def:462),条件只有
hist_last_line_pushed == 0 && hist_last_line_added,不带
remember_on_history门。trap 动作经
parse_and_execute以SEVAL_NOHIST运行(trap.c:494 / trap.c:1069 / trap.c:1195),PROMPT_COMMAND 同样以 NOHIST 运行
(eval.c:305);
SEVAL_NOHIST在单元期间落为bash_history_disable()(builtins/evalstring.c:291-292;bashhist.c:297-302),由 unwind-protect 恢复。
因此在任何 trap 动作或 eval 单元内:
-s只追加、永不弹出;-p则照常弹出外层记录行(其删除本就无门)。rubash 原先只以
set -o history选项作为-s的弹出门:脚本最后一行被记录后,EXIT trap 里的
-s把trap ... EXIT那一行本身弹掉了;同一错误弹出还可从 DEBUG/ERR/RETURN/信号 trap 动作、eval 族单元与
PROMPT_COMMAND 到达。
修法(按机制,不按个案):
history_exec的 Save(-s)臂弹出门为history_remembering():选项开启 且 当前无 SEVAL_NOHIST 窗口——任一
*_trap_running标志、PROMPT_COMMAND 的 nohist env 标记、或新的 eval 单元深度计数,任一存在即不弹。
-p)臂维持基底的纯选项门:其删除在 GNU 侧本就无remember 门(history.def:462),并门会使
eval 'history -p …'不再弹出 eval 行——那正是基底做对、初版做错的一格(返工提交
dbc04a12恢复,并订正了初版关于「-p 同门(:462-463)」的引文误植)。Executor::nohist_parse_depth在execute_eval_source期间递增(evalstring 单元的 rubash 漏斗);fork 副本从 0 起,如同新的 GNU 镜像。
钉中的同行锁测试保持绿(见验证)。
返工新增三格钉(issue2824 茎内):eval 内
-p弹出 eval 行(列表面)、eval 内
-s追加且 eval 行保留(列表面)、EXIT trap 内-p弹出trap 定义行(保存文件面)。三格期望均以 GNU bash 5.3.20 脚本文件形实测
定版。fail-first(box 实测):基底 4 passed / 4 failed(红名恰原三缺陷
格 + G3 格);返工前头 6 passed / 2 failed(红名恰 G1/G2 两格);
返工后 8 passed / 0 failed。
关于第二颗钉(独立二进制面)
该钉在基底
beab07dc上实测全绿(PTY 三格 + 脚本形一格,4/4),与 wave-2 MANIFEST 预登记口径相符:独立二进制面无此缺陷,
缺陷面在宿主/API 层(niubash REPL 驱动 Session 契约的顺序)。
本 PR 对该面不做引擎改动,钉子作为独立二进制的回归锁随 PR 落地;
宿主层的后续工作已回报队长另行派发。
钉子重复说明(合并前必读)
本 PR 的两个钉文件与在飞的钉 PR 内容逐字节相同:
tests/issue2824_script_history_records_trap_line.rs亦在 PR test: wave-2 pins I2 (Refs #2773 #2774 #2791 #2824) #3172tests/issue3093_debug_trap_history_order.rs亦在 PR test: wave-2 pins W2c (Refs #3049, #3091, #3093) #3166本 PR 自带一份,使「钉 + 修」原子落地。若钉 PR 先合,
rebase 时请丢弃本分支的钉提交
95eb566f;修法提交与之独立。(返工提交
dbc04a12在 issue2824 钉文件上追加三格,与上述两 PR 所携版本自此分岔,合入轮的钉提交处置以队长卷宗 §9 条件为准。)
验证(逐茎 test result 行)
基底
beab07dcfail-first(Simular box,plain cargo test,PTY 钉在真实 PTY 下):同行合法弹出锁与无历史文件对照在基底即绿)
本分支头(返工前
e7c24ca2):cargo fmt --check(工作树):rc=0issue2352_exit_trap_status_regressions一茎 5 passed / 3 failed,但基底同茎同名三红(hup_ancestor / hup_direct / int_direct,
逐名比对一致)——基底既有失败、与本 PR 无关(Δ +0/−0),
系 box 环境下信号投递时序形。
RUSTFLAGS="-D warnings" cargo check(头):rc=0。返工头
dbc04a12(box 小集复核,日志在 review-3238 卷宗):-D warnings(带旗 rustc 调用 37 次、warning 0)/cargo check --tests/ UTF-8 全树 / marker-lint:全 rc=0G1/G2/G3/G4 + lg1/lg2/lg3 + w3(文件面)/ w5(-p 后 -s)九形,
返工头与 GNU 逐字一致
GNU oracle 注记:本沙箱内 oracle 的
history -w写文件面异常(rc=1、0 字节文件),故 GNU 侧核对以会话内
history列表面与EXIT 保存文件面为准;语义依据以上述 C 源码为准。
本 PR 删除了什么
history_exec中 Save/Print 两臂各自内联的旧弹出判定,由
history_remembering()辅助判定取代;返工后 Print 臂恢复为与基底相同的纯选项门判定(内联),Save 臂保留
history_remembering();净行数以最终 diff 为准。