Skip to content
This repository has been archived by the owner on May 4, 2018. It is now read-only.

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

Closed
bnoordhuis opened this issue Oct 24, 2012 · 1 comment
Closed

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

bnoordhuis opened this issue Oct 24, 2012 · 1 comment
Assignees
Labels

Comments

@bnoordhuis
Copy link
Contributor

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]
events.js:68
        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 nodejs/node-v0.x-archive#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
@bnoordhuis
Copy link
Contributor Author

Landed in 31f9fbc.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

1 participant