Repository navigation
fix(redirect): DOS device targets — append opens, <>CON split, test(1) /dev/tty (niubash#519) - #1324
Merged
Merged
Conversation
unixwin/niubash#519: `echo >/dev/tty` failed `Invalid argument` and broke niugit's askpass prompt. The /dev/tty -> CON translation (executor/path.rs) reached CreateFileW with FILE_APPEND_DATA, which a device rejects with ERROR_INVALID_PARAMETER: the redirect's own open succeeded while every append-mode reopen — OutputTarget::Path's deferred writes, `>>` probes, external `>>` seek-end wiring, and the fd-table `exec N>>` bind — failed the same way. GNU redir.c:725 redir_open does one open(O_WRONLY|O_CREAT|O_APPEND), which succeeds on a POSIX tty because O_APPEND is a no-op on a character device. The Windows adaptation now recognizes bare DOS device names (CON, CONIN$, CONOUT$, NUL, PRN, AUX, COM1-9, LPT1-9) via fd::is_dos_device_path and opens them in plain write mode — a stream device has no file offset for append to act on. Every user-facing append open goes through the new open_redirect_append helper; FileFd::open_write's append arm gets the same treatment so `exec 3>>/dev/tty` binds too. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Same niubash#519 class, second surface: `exec 5<>/dev/tty`,
`{var}<>/dev/tty`, `cmd <>/dev/tty`, and background `N<>` all failed
`Invalid argument` — the console multiplex device CON is two kernel
objects, so GENERIC_READ|GENERIC_WRITE fails CreateFileW with
ERROR_INVALID_PARAMETER (verified: CON rw -> 87; CONIN$/CONOUT$ each
open read-write fine; NUL rw fine).
GNU redir.c r_input_output does open(filename, O_RDWR|O_CREAT) once —
one description for both directions. On Windows the console cannot be
one handle, so FileFd::open_readwrite_pair returns an endpoint pair:
the same Rc for regular files, or CONIN$ (read) + CONOUT$ (write) for
CON. fd-table binds (`set_fd_readwrite_file`, `{var}<>`), the
validation probe, and the background-stdio/probe/open-for-fd0 sites
use it — probes and child stdin need only the CONIN$ half.
Generated with [Devin](https://devin.ai)
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
niubash#519 family, third surface: `test -e /dev/tty` (and -r/-w)
returned false — the virtual device table covered /dev/null and
/dev/std* but not /dev/tty, so the checks fell through to
metadata("CON"), which fails on DOS device names.
GNU's node always exists and is a readable+writable character device:
stat(2)/access(2) succeed on /dev/tty even without a controlling
terminal (only open() fails ENXIO), so the truth table is /dev/null's
— no probing needed.
Generated with [Devin](https://devin.ai)
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
1 task
This was referenced Oct 24, 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
Windows console/DOS devices reject operations that are fine on POSIX ttys — this PR fixes the three surfaces found under niubash#519 (
echo >/dev/tty→Invalid argument, breaking niugit's askpass):5919d6f4):CON/CONIN$/CONOUT$/NUL/COMx/LPTxrejectFILE_APPEND_DATA(ERROR_INVALID_PARAMETER). Newfd::is_dos_device_path+open_redirect_appendroute every user-facing append open;FileFd::open_writegets the same treatment forexec N>>binds.<>family (719334d5):CONalso rejectsGENERIC_READ|GENERIC_WRITE. NewFileFd::open_readwrite_pairbindsCONIN$(read) +CONOUT$(write) forexec N<>,{var}<>,cmd <>, background<>; probes open theCONIN$half.87c2f7c4):test -e/-r/-w/-c /dev/ttyanswered beforemetadata("CON"), which fails on device names. GNU's node always exists + is a rw char device.Verification
echo >/dev/tty,>>,&>,&>>,2>,exec 3>/3>>,exec 5<>,{v}<>,cmd <>all exit 0 under a real console.tests/issue519_dev_tty_redirect_regressions.rs(5 legs, console-gated skip in headless CI) +is_dos_device_pathunit test.cargo test --lib789/789; ~20 redirect-related test files green; regular-file append/truncate/offset semantics unchanged.niu -c(niubash builds against this tree).{var}fd-var), rubash#1314 (residual edges).Generated with Devin