Skip to content

Running without a TTY causes --version / --help to fail #194

Open
@RossSmyth

Description

@RossSmyth

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

STATE.stdin = check_int_return(libc::open(c"/dev/tty".as_ptr(), libc::O_RDONLY))?;

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

DHowett commented on May 21, 2025

@DHowett
Member

@rhubarb-geek-nz they're correct that we should not need /dev/tty before printing the version number. 🙂

rhubarb-geek-nz

rhubarb-geek-nz commented on May 21, 2025

@rhubarb-geek-nz
Contributor

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.

changed the title [-]Running without a TTY causes an error even if not required[/-] [+]Running without a TTY causes --version / --help to fail[/+] on May 21, 2025
added
I-bugIt shouldn't be doing this.
P-lowLow(er) priority. Example: Bugs in less commonly used features.
E-help-wantedWe encourage you to jump in on these!
on May 21, 2025
jhudsoncedaron

jhudsoncedaron commented on May 27, 2025

@jhudsoncedaron

@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

Nihal-Pandey-2302 commented on May 27, 2025

@Nihal-Pandey-2302

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

lhecker commented on May 27, 2025

@lhecker
Member

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.

added a commit that references this issue on May 27, 2025

Fix microsoft#194: Defer TTY initialization to allow --version/--help

a2bc1bb
lhecker

lhecker commented on May 27, 2025

@lhecker
Member

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    E-help-wantedWe encourage you to jump in on these!I-bugIt shouldn't be doing this.P-lowLow(er) priority. Example: Bugs in less commonly used features.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @DHowett@lhecker@jhudsoncedaron@RossSmyth@rhubarb-geek-nz

      Issue actions

        Running without a TTY causes --version / --help to fail · Issue #194 · microsoft/edit