Revert "unix: reopen tty as /dev/tty"
This reverts commit31f9fbce63. The reverted commit depends on commit5da380a("use select() for specific fds on OS X") which polls /dev/tty file descriptors in a separate thread to work around deficiencies in the kqueue API on OS X. Unfortunately,5da380ahas a bug that effectively makes the select() thread busy-loop. Revert this commit for now.
This commit is contained in:
parent
b5fc9444b1
commit
20bb1bfd70
@ -34,53 +34,18 @@ static struct termios orig_termios;
|
|||||||
|
|
||||||
|
|
||||||
int uv_tty_init(uv_loop_t* loop, uv_tty_t* tty, int fd, int readable) {
|
int uv_tty_init(uv_loop_t* loop, uv_tty_t* tty, int fd, int readable) {
|
||||||
int flags;
|
|
||||||
int newfd;
|
|
||||||
int r;
|
|
||||||
|
|
||||||
uv__stream_init(loop, (uv_stream_t*)tty, UV_TTY);
|
uv__stream_init(loop, (uv_stream_t*)tty, UV_TTY);
|
||||||
|
|
||||||
/* Reopen the file descriptor when it refers to a tty. This lets us put the
|
if (readable) {
|
||||||
* tty in non-blocking mode without affecting other processes that share it
|
uv__nonblock(fd, 1);
|
||||||
* with us.
|
uv__stream_open((uv_stream_t*)tty, fd, UV_STREAM_READABLE);
|
||||||
*
|
} else {
|
||||||
* Example: `node | cat` - if we put our fd 0 in non-blocking mode, it also
|
/* Note: writable tty we set to blocking mode. */
|
||||||
* affects fd 1 of `cat` because both file descriptors refer to the same
|
uv__stream_open((uv_stream_t*)tty, fd, UV_STREAM_WRITABLE);
|
||||||
* struct file in the kernel. When we reopen our fd 0, it points to a
|
tty->flags |= UV_STREAM_BLOCKING;
|
||||||
* different struct file, hence changing its properties doesn't affect
|
|
||||||
* other processes.
|
|
||||||
*/
|
|
||||||
if (isatty(fd)) {
|
|
||||||
newfd = open("/dev/tty", O_RDWR);
|
|
||||||
|
|
||||||
if (newfd == -1)
|
|
||||||
return uv__set_sys_error(loop, errno);
|
|
||||||
|
|
||||||
do
|
|
||||||
r = dup2(newfd, fd);
|
|
||||||
while (r == -1 && (errno == EINTR || errno == EBUSY));
|
|
||||||
|
|
||||||
/* EINVAL means newfd == fd which could conceivably happen if another
|
|
||||||
* thread called close(fd) between our calls to isatty() and open().
|
|
||||||
* That's a rather unlikely event but let's handle it anyway.
|
|
||||||
*/
|
|
||||||
if (r == -1 && errno != EINVAL) {
|
|
||||||
close(newfd);
|
|
||||||
return uv__set_sys_error(loop, errno);
|
|
||||||
}
|
|
||||||
|
|
||||||
fd = newfd;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (readable)
|
|
||||||
flags = UV_STREAM_READABLE;
|
|
||||||
else
|
|
||||||
flags = UV_STREAM_WRITABLE;
|
|
||||||
|
|
||||||
uv__nonblock(fd, 1);
|
|
||||||
uv__stream_open((uv_stream_t*)tty, fd, flags);
|
|
||||||
tty->mode = 0;
|
tty->mode = 0;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user