Skip to content

fix(opt): forward adapted commands with an argv prefix; gawk exits text mode (#467) - #1270

Merged
caomengxuan666 merged 1 commit into
mainfrom
fix/niubash-467-gawk-binmode
Oct 21, 2026
Merged

caomengxuan666 merged 1 commit into
mainfrom
fix/niubash-467-gawk-binmode

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Summary

The bundled opt\gawk payload (ezwinports GNU Awk 5.4.1, installed via the wpm gawk package into every Niubash layout) is a text-mode mingw build: its CRT rewrote every \n as \r\n on write and folded \r\n into \n on read — awk '{print}' > f landed CRLF files, ORS="\r\n" doubled the CR to \r\r\n, and pipelines passed polluted bytes downstream, while every other bundled applet does binary stdio (unixwin/niubash#467; same root cause as the fixed text-mode family #1202/#1211/#1212/#1214/#1218/#1219, but the payload is an external component the applet sweep did not cover).

Runtime difference found (verified against the shipped opt/gawk/gawk.exe): this build carries gawk's BINMODE feature but ignores the BINMODE environment variable — -v BINMODE=3 is the only lever, and it moves stdin/stdout/stderr and the program's own opens to binary, matching GNU awk byte-for-byte. The payload keeps its shipped bytes; the fix lives in the forwarders:

  • winuxcmd-shim.exe gains an ArgvAdapter table (awk/gawk → -v BINMODE=3) spliced ahead of the forwarded arguments, so a caller's own later -v BINMODE=... still wins; it now probes the install root at the bin\ depth too, since adapted commands route their PATH-entry link through the shim.
  • winuxcmd.exe (forwardToOptPayload) applies the same prefix on the dispatcher path and probes the root at both depths.
  • wpm points the PATH-entry link (bin\<cmd>.exe) of adapted commands at a forwarder (winuxcmd-shim.exe, or winuxcmd.exe when the install predates it) instead of the payload — closing the bin\ bypass that would have reached the payload unadapted.
  • Incidental fix in the same forwarding path: winuxcmd <verb> args no longer forwards the verb token itself as the payload's first argument — winuxcmd gawk '{print}' previously died on "cannot open file" and every layout: shim payload reached through the verb form saw a corrupted argv.

layout: shim is now load-bearing for gawk, not cosmetic — a flat payload mapping onto usr\bin would bypass the adapter and re-ship CRLF.

Test plan

  • winuxcmd-tests.exe --gtest_filter='wpm.*' — 73/73 pass, incl. new wpm_adapted_command_entry_link_targets_the_forwarder (adapted bin\gawk.exe links the forwarder; unadapted bin\tool.exe still links the payload directly)
  • Byte-level end-to-end on a staged fixture (opt\gawk real payload + shims.map + forwarder links at both depths):
    • usr\bin\gawk.exe (shim, canonical depth): a\nb\n
    • usr\bin\awk.exe (winuxcmd.exe forwarding): a\nb\n
    • bin\gawk.exe, bin\awk.exe (shim at bin\ depth): a\nb\n
    • winuxcmd gawk '{print $1}' (verb form): a\nb\n — verb token no longer leaks into argv
    • explicit ORS="\r\n" lands exactly a\r\nb\r\n (no \r\r\n doubling); -v BINMODE=0 user override still wins (a\r\nb\r\n); CRLF input -F, '{print $2}' yields y\r\n matching GNU
  • Niubash side: test(release): gate the staged awk pipeline on raw output bytes (#467) niubash#479 adds the raw-byte staged-release gate — a release whose bundled forwarder lacks this adapter fails its x64 verify (fail-closed), so this PR and the winuxcmd-pin.json bump are one change window

Refs unixwin/niubash#467

Generated with Devin

…xt mode (unixwin/niubash#467)

The bundled ezwinports gawk is a text-mode mingw build: its CRT rewrote
every \n as \r\n on write and folded \r\n into \n on read, while every
winuxcmd applet does binary stdio, so `awk '{print}' > f` landed CRLF
files and `ORS="\r\n"` doubled the CR. The build carries gawk's BINMODE
feature but ignores the BINMODE environment variable, so `-v BINMODE=3`
is the only lever that moves stdin/stdout/stderr - and the files the
program opens - to binary, matching GNU awk byte-for-byte.

- winuxcmd-shim splices ` -v BINMODE=3` ahead of the forwarded arguments
  for awk/gawk so a user's own `-v BINMODE=...` still wins, and probes
  the install root at the bin\ depth too since adapted commands route
  their PATH-entry link through the shim.
- forwardToOptPayload applies the same prefix on the winuxcmd.exe
  forwarding path and probes the root at both depths.
- wpm's PATH-entry link (bin\<cmd>.exe) for adapted commands hardlinks a
  forwarder (winuxcmd-shim.exe, or winuxcmd.exe when it predates the
  shim) instead of the payload, closing the unadapted bypass.
- `winuxcmd <verb> args` no longer forwards the verb itself as the
  payload's first argument - it corrupted the argv of every shim payload
  reached through the verb form.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
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