Skip to content

fix(printf): pass-granular fd-1 write-failure abort (Refs #3453) - #3597

Merged
caomengxuan666 merged 1 commit into
masterfrom
fix/3453-printf-pass-abort
Nov 15, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
fix/3453-printf-pass-abort

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Summary

GNU printf.def:819 checks ferror(stdout) once per rendering pass — a
failed fd-1 write aborts the builtin at the pass boundary: the failing
pass's diagnostics still print, later passes' renderings die.

  • printf.rs: PassBoundary segment marks each render pass;
    execute_with_io_and_store writes it to an optional boundary sink.
  • OrderedOutputLog: pass_boundary_writer() emits fd=u8::MAX marker
    chunks into the same production-ordered log.
  • route_builtin_buffered_output_chunks: marked chunks take a
    pass-aware walk — first fd-1 write failure (or Closed target) arms
    the abort, the diagnostic lands after the failing pass's last chunk,
    later-pass chunks drop. write_to_fd swallows Closed with Ok, so the
    verdict is read off fd_target(1).
  • route_pipeline_stage_streams_inner: when the stage's fd-1 delivery
    targets a certainly-failing sink, the stderr leg is rebuilt from the
    pass-tagged ordered log (stage streams learn the verdict only at
    delivery).
  • write_stage_stream_to_target: the write-error diagnostic and
    status-1 now attach to fd-1 failures only — a failed fd-2 delivery
    is lost silently, like GNU's builtin_error writing to the
    descriptor that just failed (rubash#699 R1.3).

Pins: tests/issue3453_printf_pass_abort.rs — pipeline stage keeps
only the write error (was: bad diagnostic resurrected), 1>&- 2>&-
stays silent (was: write error leaked through the pipe), non-pipe
closed-fd1 keeps same-pass diagnostics (was: dropped).

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

GNU printf.def:819 checks ferror(stdout) once per rendering pass — a
failed fd-1 write aborts the builtin at the pass boundary: the failing
pass's diagnostics still print, later passes' renderings die.

- printf.rs: PassBoundary segment marks each render pass;
  execute_with_io_and_store writes it to an optional boundary sink.
- OrderedOutputLog: pass_boundary_writer() emits fd=u8::MAX marker
  chunks into the same production-ordered log.
- route_builtin_buffered_output_chunks: marked chunks take a
  pass-aware walk — first fd-1 write failure (or Closed target) arms
  the abort, the diagnostic lands after the failing pass's last chunk,
  later-pass chunks drop. write_to_fd swallows Closed with Ok, so the
  verdict is read off fd_target(1).
- route_pipeline_stage_streams_inner: when the stage's fd-1 delivery
  targets a certainly-failing sink, the stderr leg is rebuilt from the
  pass-tagged ordered log (stage streams learn the verdict only at
  delivery).
- write_stage_stream_to_target: the write-error diagnostic and
  status-1 now attach to fd-1 failures only — a failed fd-2 delivery
  is lost silently, like GNU's builtin_error writing to the
  descriptor that just failed (rubash#699 R1.3).

Pins: tests/issue3453_printf_pass_abort.rs — pipeline stage keeps
only the write error (was: bad diagnostic resurrected), 1>&- 2>&-
stays silent (was: write error leaked through the pipe), non-pipe
closed-fd1 keeps same-pass diagnostics (was: dropped).

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@caomengxuan666

Copy link
Copy Markdown
Member Author

【WIN-AGENT-AUDIT】
PR #3597 第1轮 — 建议:PASS
head: d5b64cd base(merge-base): 96802ca 文件: 7 个 +312/-11
关联 issue: #3453(状态:open,我核过的时间:2026-11-15 本地)

机制核查:

  • printf 的 fd-1 写失败按「渲染 pass」粒度中止:GNU printf.def:819 在每个 rendering pass 末尾查一次 if (vflag == 0 && ferror (stdout)) PRETURN (EXECUTION_FAILURE) → 失败 pass 内的 fd-2 诊断存活、pass 边界处发 write error、后续 pass 的渲染与诊断整体丢弃。本 PR 以 PrintfSegment::PassBoundary + RenderedPrintf pass 标记 + (fd, text, pass) 有序 chunk(u8::MAX 哨兵)在 redirection.rs 复刻该粒度,fd-2 投递失败静默(对应 GNU builtin_error 写已败描述符,rubash#699 R1.3)。机制贴 GNU,无半成品/翻译层。
  • 无关改动:无(mod.rs / trap_stack_builtins.rs / pipeline_exec.rs 仅为新签名与 chunk 形状接线)。

腿:

  • 钉自跑(head):issue3453_printf_pass_abort 1 passed / 4 failed。4 红全部仅因 argv0 前缀:期望 bash: line 1: 实得 /d/.../rubash.exe: line 1:,断言体(printf: write error: Bad file descriptor、bad: invalid number、rc=0/1、pass 粒度)逐字节等于 GNU。该形状与仓库既有钉惯例一致(unix arg0("bash") + bash: 断言,如 tests/issue518_redirect_message_regressions.rs),Windows 本机恒红、Windows CI 仅编译不跑测。
  • fail-first(base 96802ca):同 stem 0 passed / 5 failed。其中 pipeline_stage_both_fds_closed_stays_silent 断言空 stderr 无前缀——head 绿、base 红,Windows 上可判别的真 fail-first;其余 4 钉 base 红但 Windows 上被前缀掩盖(unix CI 腿承担判别)。
  • lib 双边:以 CI head 腿日志代——Linux 腿 lib 红集 {issue2875_input_procsub_child_runs_as_rubash_shell}(1350/1351),macOS 腿红集 {issue2875}(1243/1247);均为规程已知基线红,差集 ∅。
  • -D warnings:cargo check --locked --bin rubash 完成,0 警告。
  • 卫生:rustfmt --check 7 个 PR 文件全 OK。
  • CI:红腿 3 个(GNU regression goldens / Rust tests / Rust tests macOS),红名各仅 issue2875(基线);其余腿全绿。
  • GNU 对照:wsl bash 5.3.20(1)-release(vendored 5.3 p20),脚本 target/p-3453b.sh:
    • printf '%d\n' 5 bad 7 2>&1 1>&- | cat; echo rc=$? → GNU:printf: write error: Bad file descriptor + rc=0;本 PR 相同(仅前缀为 exe 路径)✓
    • printf '%d\n%d\n' 5 bad 2>/tmp/e3453 1>&-; cat /tmp/e3453 → GNU:bad: invalid number + write error(同 pass 诊断存活);本 PR 相同 ✓
    • printf '%d\n' 5 1>&- → 双方 write error + rc=1 ✓

F 点:无

未跑/VOID 的腿:

  • 本地全量 lib 未跑:以 CI head 腿红集 + 已知基线(issue2875)代替判读。
  • unix 钉形态(bash: 前缀断言)本机不可跑:由 unix CI 腿覆盖,Windows 侧以 pipeline_stage_both_fds_closed_stays_silent 提供 fail-first 判别。

@caomengxuan666

Copy link
Copy Markdown
Member Author

【队长终裁】PASS(合入条件:Unix 钉腿先行)

核过审计报告(6886772032)+ CI 全表,并复核了钉文件:钉用 cmd.arg0("bash")(tests/issue3453_printf_pass_abort.rs:19),期望 bash: line 1:——与仓库既有钉惯例(tests/issue518_redirect_message_regressions.rs)一致。Windows head 上 1/5,4 红仅因 argv0 前缀(实得 exe 路径);GNU oracle 在 head 二进制上三形状逐字节一致(仅前缀差异);fail-first base 0/5,其中 pipeline_stage_both_fds_closed_stays_silent 在 Windows 上可判别(head 绿/base 红)。-D warnings 0 警告;fmt 7 文件 OK;CI 三红红名全为 issue2875 基线。纠正审计一处说法:「unix CI 覆盖」字面不成立——普查步因 issue2875 不可达(见 #3656),没有任何 CI 腿执行本 stem;因此合入条件:合入轮先在 Unix 腿上跑本 stem 5/5,绿了再合。合入正文 Refs #3453(合入后由队长手动关闭)。

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.

1 participant