Open
Description
Hello, thanks for this neat project! I am attempting to build it in a sandboxed environment. This environemnt does not have a /dev/tty
, but I would like to ensure that Edit compiled successfully by running edit --version
. This currently fails because it attempts to open /dev/tty
Line 51 in f886091
so the strace looks something like:
ioctl(0, TCGETS, 0x7fffffffd1b0) = -1 ENOTTY (Inappropriate ioctl for device)
openat(AT_FDCWD, "/dev/tty", O_RDONLY) = -1 ENXIO (No such device or address)
write(1, "Error 6: No such device or addre"..., 36) = 36
sigaltstack({ss_sp=NULL, ss_flags=SS_DISABLE, ss_size=8192}, NULL) = 0
Activity
DHowett commentedon May 21, 2025
@rhubarb-geek-nz they're correct that we should not need
/dev/tty
before printing the version number. 🙂rhubarb-geek-nz commentedon May 21, 2025
To validate the build you could use "ldd" to confirm the binary can be loaded
As a work around for the moment then run it and check for the expected error.
[-]Running without a TTY causes an error even if not required[/-][+]Running without a TTY causes --version / --help to fail[/+]jhudsoncedaron commentedon May 27, 2025
@rhubarb-geek-nz : ldd doesn't seem to be a good way of validating a build. Ever try it on a statically linked binary?
Nihal-Pandey-2302 commentedon May 27, 2025
Hi, I'd like to try working on this issue. I'm new to Rust and this seems like a good opportunity to learn. My plan is to check for --version/--help arguments early in main.rs and exit before the TTY initialization in src/sys/unix.rs is called. Any initial guidance or things to watch out for would be appreciated!
lhecker commentedon May 27, 2025
That won't be trivially possible because the
sys::init
function is responsible for makingsys::write_stdout
work, which you need for printing those messages. What we need to do instead is separate the TTY check out ofsys::init
into its own function.sys::init
should initialize the stdout/stdin handles with the default handles. The separated function can then check if they're redirected and swap them to the TTY.Fix microsoft#194: Defer TTY initialization to allow --version/--help
lhecker commentedon May 27, 2025
@DHowett suggested an alternative approach: We could split up
sys::write_stdout
intosys::write_stdout
andsys::write_tty
. We would then store the stdout and tty-stdout handles in separate members.