unix: re-open tty stdio fds as /dev/tty? #601

bnoordhuis opened this Issue Oct 24, 2012 · 1 comment


None yet
1 participant

bnoordhuis commented Oct 24, 2012

The basic logic is as follows, error handling elided for brevity:

for (fd = 0; fd <= 2; fd++) {
  if (isatty(fd))
    dup2(open("/dev/tty", O_RDWR), fd);

That lets libuv / node switch its tty to non-blocking mode without affecting other programs that expect it to be in blocking mode. That would, for example, fix the following issue:

$ node | cat
> process
[lots of data]
        throw arguments[1]; // Unhandled 'error' event
Error: write EPIPE
    at errnoException (net.js:787:11)
    at Object.afterWrite (net.js:598:19)
    at process._makeCallback (node.js:248:20)

See joyent/node#3027 and this comment in particular.

It remains to be investigated if this approach works on all supported platforms.

@ghost ghost assigned bnoordhuis Oct 24, 2012


This comment has been minimized.

Show comment Hide comment

bnoordhuis Oct 24, 2012


Landed in 31f9fbc.


bnoordhuis commented Oct 24, 2012

Landed in 31f9fbc.

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