Skip to content

fix(hostid): reject -h as invalid option, wire --help/--version text (Refs #1802) - #1805

Merged
caomengxuan666 merged 1 commit into
mainfrom
fix/1802-hostid-short-h
Nov 16, 2026
Merged

caomengxuan666 merged 1 commit into
mainfrom
fix/1802-hostid-short-h

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Refs #1802.

根因

hostid 的 GNU 锚点是 hostid.c:63-65 调 lib/long-options.c:98 parse_gnu_standard_options_only,optstring 为空——只有长 --help/--version 是合法选项,-h 是 getopt 的 invalid option -- 'h'(rc 1),不是 help 别名。修法前两处偏离:

  1. hostid -h 走 argopt 的 bare-h → --help 映射,静默 rc 0(ho12 note 行,MASKED-DIVERGENCE;users -h 同类,us17,不在本单范围)。
  2. --help/--version 只返回 rc 0、不打印任何文本(HELP-SURFACE.md 的 hostid 两行 EMPTY-HELP;产品 exe 侧 dispatcher 拦截印 branded 文本,rust2 驱动/ABI 侧一直是空的)。

修法(按机制,不打地鼠)

  • rust2/crates/winux-cmds/src/hostid.rs:注册共享的 argopt::H_REJECT_SPEC marker(ptx/who/pathchk/shuf/csplit 同款机制),parse 后 rejected_short_h 先于 help/version 分支报 hostid: invalid option -- 'h' + try-help 行、rc 1;--help/--version 按 argv 顺序取首个,打印探针实测的 GNU 9.4 文本(help 体 + gnuhelp::footer("hostid", "hostid invocation"),version 用 gnuhelp::coreutils_version("hostid", "Jim Meyering"),whoami/ptx 同款)。
  • 顺序契约(argopt: --help/--version 之后的未知选项未按 getopt_long 短路(GNU 先出帮助 rc 0) #1573):--help -h 仍打印 help rc 0(getopt 在 --help 处即退出,后面的 token 不校验);-h --help 仍 rc 1(getopt 先撞 -h)。
  • 门面:gen-cases.py ho12 note → win(rust↔cpp rc 对照;fix(hostid): accept only --help/--version (ho13 system-id row) #1800 的 ho13 同例),cases/hostid.tsv 重生成(仅此一行变);note-registry.tsv 删 ho12 行(note 已无标的,NOTE-QC.md 待 X299 腿重生成);tests/unit/hostid/hostid_unit_test.cpp 加 -h 拒绝钉。

本 PR 删除了什么

  • 删 hostid_cmd 里 --help/--version 只返回 Ok(0) 不打印的空分支,改为打印 GNU 文本;删 long_version_is_accepted 旧钉(它断言 --version 输出为空,正是 EMPTY-HELP 缺口本身)。
  • 删 note-registry.tsv 的 hostid/ho12-short-help 注册行(见上)。
  • 未删任何测试用例、未改产品代码(C++ 侧只加一枚 ctest 钉;src/commands/hostid.cpp 不动,dispatcher 的 sole --help/--version 拦截继续印 branded 文本);未引入 trust/签名/加载期校验机制。

验证(X299-2607 腿,待补——本 PR 先开草稿)

  • rust2 钉:short_h_is_invalid_option(-h/-x 逐字节 stderr + rc 1)、h_help_ordering_follows_argv、gnu_help_version_surface(--help/--version 文本起止)、既有 -V/-v/extra-operand 钉不倒退;cargo test -p winux-cmds --lib hostid(Windows)。
  • C++ 腿:hostid_short_h_rejected_issue1802 ctest;hostid --help/--version 走 dispatcher branded 文本 rc 0。
  • 门面:run-gate.sh hostid 20 行(ho12 由 note 转 win,rust↔cpp rc 1 对齐);qc_help_surface.py 重扫(hostid --help/--version 由 EMPTY-HELP 转 ALIGNED,-h 由 RC-ONLY 转 ALIGNED);qc_note_audit.py 重生成 NOTE-QC.md(ho12 退出清单)。
  • Oracle 对照(Linux coreutils 9.4 实测已取,oracle/):-h/-x/-v/-V 皆 invalid option + try-help、rc 1;--help/--version 文本逐字节取样。
  • 本地 Linux 腿 VOID:winux-cmds 是 Windows 目标 crate,cargo test 在 Linux 上 40 个 E0433(windows in os),与本单无关;rustfmt --check 干净。

UNVERIFIED-BY-CAPTAIN

@caomengxuan666
caomengxuan666 marked this pull request as ready for review November 16, 2026 15:57
@caomengxuan666
caomengxuan666 merged commit 49d22e6 into main Nov 16, 2026
26 of 28 checks passed
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