Repository navigation
fix(opt): forward adapted commands with an argv prefix; gawk exits text mode (#467) - #1270
Merged
Merged
Conversation
…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>
3 of 4 tasks
This was referenced Oct 21, 2026
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.
Summary
The bundled
opt\gawkpayload (ezwinports GNU Awk 5.4.1, installed via the wpmgawkpackage into every Niubash layout) is a text-mode mingw build: its CRT rewrote every\nas\r\non write and folded\r\ninto\non read —awk '{print}' > flanded 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'sBINMODEfeature but ignores theBINMODEenvironment variable —-v BINMODE=3is 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.exegains anArgvAdaptertable (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 thebin\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.wpmpoints the PATH-entry link (bin\<cmd>.exe) of adapted commands at a forwarder (winuxcmd-shim.exe, orwinuxcmd.exewhen the install predates it) instead of the payload — closing thebin\bypass that would have reached the payload unadapted.winuxcmd <verb> argsno longer forwards the verb token itself as the payload's first argument —winuxcmd gawk '{print}'previously died on "cannot open file" and everylayout: shimpayload reached through the verb form saw a corrupted argv.layout: shimis now load-bearing for gawk, not cosmetic — a flat payload mapping ontousr\binwould bypass the adapter and re-ship CRLF.Test plan
winuxcmd-tests.exe --gtest_filter='wpm.*'— 73/73 pass, incl. newwpm_adapted_command_entry_link_targets_the_forwarder(adaptedbin\gawk.exelinks the forwarder; unadaptedbin\tool.exestill links the payload directly)opt\gawkreal payload +shims.map+ forwarder links at both depths):usr\bin\gawk.exe(shim, canonical depth):a\nb\nusr\bin\awk.exe(winuxcmd.exe forwarding):a\nb\nbin\gawk.exe,bin\awk.exe(shim atbin\depth):a\nb\nwinuxcmd gawk '{print $1}'(verb form):a\nb\n— verb token no longer leaks into argvORS="\r\n"lands exactlya\r\nb\r\n(no\r\r\ndoubling);-v BINMODE=0user override still wins (a\r\nb\r\n); CRLF input-F, '{print $2}'yieldsy\r\nmatching GNUwinuxcmd-pin.jsonbump are one change windowRefs unixwin/niubash#467
Generated with Devin