edit
edit copied to clipboard
Running without a TTY causes --version / --help to fail
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
https://github.com/microsoft/edit/blob/f88609160afa8a6d19a5bcccaf1870b0c6b78e41/src/sys/unix.rs#L51
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
@rhubarb-geek-nz they're correct that we should not need /dev/tty before printing the version number. 🙂
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.
@rhubarb-geek-nz : ldd doesn't seem to be a good way of validating a build. Ever try it on a statically linked binary?
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!
That won't be trivially possible because the sys::init function is responsible for making sys::write_stdout work, which you need for printing those messages. What we need to do instead is separate the TTY check out of sys::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.
@DHowett suggested an alternative approach: We could split up sys::write_stdout into sys::write_stdout and sys::write_tty. We would then store the stdout and tty-stdout handles in separate members.