0.3.0: vendor latest libuv
This commit is contained in:
Vendored
+77
-32
@@ -48,6 +48,42 @@ static int uv__tty_is_slave(const int fd) {
|
||||
char dummy[256];
|
||||
|
||||
result = ioctl(fd, TIOCPTYGNAME, &dummy) != 0;
|
||||
#elif defined(__NetBSD__)
|
||||
/*
|
||||
* NetBSD as an extension returns with ptsname(3) and ptsname_r(3) the slave
|
||||
* device name for both descriptors, the master one and slave one.
|
||||
*
|
||||
* Implement function to compare major device number with pts devices.
|
||||
*
|
||||
* The major numbers are machine-dependent, on NetBSD/amd64 they are
|
||||
* respectively:
|
||||
* - master tty: ptc - major 6
|
||||
* - slave tty: pts - major 5
|
||||
*/
|
||||
|
||||
struct stat sb;
|
||||
/* Lookup device's major for the pts driver and cache it. */
|
||||
static devmajor_t pts = NODEVMAJOR;
|
||||
|
||||
if (pts == NODEVMAJOR) {
|
||||
pts = getdevmajor("pts", S_IFCHR);
|
||||
if (pts == NODEVMAJOR)
|
||||
abort();
|
||||
}
|
||||
|
||||
/* Lookup stat structure behind the file descriptor. */
|
||||
if (fstat(fd, &sb) != 0)
|
||||
abort();
|
||||
|
||||
/* Assert character device. */
|
||||
if (!S_ISCHR(sb.st_mode))
|
||||
abort();
|
||||
|
||||
/* Assert valid major. */
|
||||
if (major(sb.st_rdev) == NODEVMAJOR)
|
||||
abort();
|
||||
|
||||
result = (pts == major(sb.st_rdev));
|
||||
#else
|
||||
/* Fallback to ptsname
|
||||
*/
|
||||
@@ -56,13 +92,15 @@ static int uv__tty_is_slave(const int fd) {
|
||||
return result;
|
||||
}
|
||||
|
||||
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 unused) {
|
||||
uv_handle_type type;
|
||||
int flags;
|
||||
int newfd;
|
||||
int r;
|
||||
int saved_flags;
|
||||
int mode;
|
||||
char path[256];
|
||||
(void)unused; /* deprecated parameter is no longer needed */
|
||||
|
||||
/* File descriptors that refer to files cannot be monitored with epoll.
|
||||
* That restriction also applies to character devices like /dev/random
|
||||
@@ -70,11 +108,20 @@ int uv_tty_init(uv_loop_t* loop, uv_tty_t* tty, int fd, int readable) {
|
||||
*/
|
||||
type = uv_guess_handle(fd);
|
||||
if (type == UV_FILE || type == UV_UNKNOWN_HANDLE)
|
||||
return -EINVAL;
|
||||
return UV_EINVAL;
|
||||
|
||||
flags = 0;
|
||||
newfd = -1;
|
||||
|
||||
/* Save the fd flags in case we need to restore them due to an error. */
|
||||
do
|
||||
saved_flags = fcntl(fd, F_GETFL);
|
||||
while (saved_flags == -1 && errno == EINTR);
|
||||
|
||||
if (saved_flags == -1)
|
||||
return UV__ERR(errno);
|
||||
mode = saved_flags & O_ACCMODE;
|
||||
|
||||
/* Reopen the file descriptor when it refers to a tty. This lets us put the
|
||||
* tty in non-blocking mode without affecting other processes that share it
|
||||
* with us.
|
||||
@@ -92,21 +139,21 @@ int uv_tty_init(uv_loop_t* loop, uv_tty_t* tty, int fd, int readable) {
|
||||
* slave device.
|
||||
*/
|
||||
if (uv__tty_is_slave(fd) && ttyname_r(fd, path, sizeof(path)) == 0)
|
||||
r = uv__open_cloexec(path, O_RDWR);
|
||||
r = uv__open_cloexec(path, mode | O_NOCTTY);
|
||||
else
|
||||
r = -1;
|
||||
|
||||
if (r < 0) {
|
||||
/* fallback to using blocking writes */
|
||||
if (!readable)
|
||||
flags |= UV_STREAM_BLOCKING;
|
||||
if (mode != O_RDONLY)
|
||||
flags |= UV_HANDLE_BLOCKING_WRITES;
|
||||
goto skip;
|
||||
}
|
||||
|
||||
newfd = r;
|
||||
|
||||
r = uv__dup2_cloexec(newfd, fd);
|
||||
if (r < 0 && r != -EINVAL) {
|
||||
if (r < 0 && r != UV_EINVAL) {
|
||||
/* 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.
|
||||
@@ -118,22 +165,6 @@ int uv_tty_init(uv_loop_t* loop, uv_tty_t* tty, int fd, int readable) {
|
||||
fd = newfd;
|
||||
}
|
||||
|
||||
#if defined(__APPLE__)
|
||||
/* Save the fd flags in case we need to restore them due to an error. */
|
||||
do
|
||||
saved_flags = fcntl(fd, F_GETFL);
|
||||
while (saved_flags == -1 && errno == EINTR);
|
||||
|
||||
if (saved_flags == -1) {
|
||||
if (newfd != -1)
|
||||
uv__close(newfd);
|
||||
return -errno;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Pacify the compiler. */
|
||||
(void) &saved_flags;
|
||||
|
||||
skip:
|
||||
uv__stream_init(loop, (uv_stream_t*) tty, UV_TTY);
|
||||
|
||||
@@ -141,7 +172,7 @@ skip:
|
||||
* the handle queue, since it was added by uv__handle_init in uv_stream_init.
|
||||
*/
|
||||
|
||||
if (!(flags & UV_STREAM_BLOCKING))
|
||||
if (!(flags & UV_HANDLE_BLOCKING_WRITES))
|
||||
uv__nonblock(fd, 1);
|
||||
|
||||
#if defined(__APPLE__)
|
||||
@@ -158,10 +189,10 @@ skip:
|
||||
}
|
||||
#endif
|
||||
|
||||
if (readable)
|
||||
flags |= UV_STREAM_READABLE;
|
||||
else
|
||||
flags |= UV_STREAM_WRITABLE;
|
||||
if (mode != O_WRONLY)
|
||||
flags |= UV_HANDLE_READABLE;
|
||||
if (mode != O_RDONLY)
|
||||
flags |= UV_HANDLE_WRITABLE;
|
||||
|
||||
uv__stream_open((uv_stream_t*) tty, fd, flags);
|
||||
tty->mode = UV_TTY_MODE_NORMAL;
|
||||
@@ -198,7 +229,7 @@ int uv_tty_set_mode(uv_tty_t* tty, uv_tty_mode_t mode) {
|
||||
fd = uv__stream_fd(tty);
|
||||
if (tty->mode == UV_TTY_MODE_NORMAL && mode != UV_TTY_MODE_NORMAL) {
|
||||
if (tcgetattr(fd, &tty->orig_termios))
|
||||
return -errno;
|
||||
return UV__ERR(errno);
|
||||
|
||||
/* This is used for uv_tty_reset_mode() */
|
||||
uv_spinlock_lock(&termios_spinlock);
|
||||
@@ -228,7 +259,7 @@ int uv_tty_set_mode(uv_tty_t* tty, uv_tty_mode_t mode) {
|
||||
|
||||
/* Apply changes after draining */
|
||||
if (tcsetattr(fd, TCSADRAIN, &tmp))
|
||||
return -errno;
|
||||
return UV__ERR(errno);
|
||||
|
||||
tty->mode = mode;
|
||||
return 0;
|
||||
@@ -244,7 +275,7 @@ int uv_tty_get_winsize(uv_tty_t* tty, int* width, int* height) {
|
||||
while (err == -1 && errno == EINTR);
|
||||
|
||||
if (err == -1)
|
||||
return -errno;
|
||||
return UV__ERR(errno);
|
||||
|
||||
*width = ws.ws_col;
|
||||
*height = ws.ws_row;
|
||||
@@ -262,7 +293,14 @@ uv_handle_type uv_guess_handle(uv_file file) {
|
||||
if (file < 0)
|
||||
return UV_UNKNOWN_HANDLE;
|
||||
|
||||
#if defined(__PASE__)
|
||||
/* On IBMi PASE isatty() always returns true for stdin, stdout and stderr.
|
||||
* Use ioctl() instead to identify whether it's actually a TTY.
|
||||
*/
|
||||
if (!ioctl(file, TXISATTY + 0x81, NULL) || errno != ENOTTY)
|
||||
#else
|
||||
if (isatty(file))
|
||||
#endif
|
||||
return UV_TTY;
|
||||
|
||||
if (fstat(file, &s))
|
||||
@@ -322,15 +360,22 @@ int uv_tty_reset_mode(void) {
|
||||
|
||||
saved_errno = errno;
|
||||
if (!uv_spinlock_trylock(&termios_spinlock))
|
||||
return -EBUSY; /* In uv_tty_set_mode(). */
|
||||
return UV_EBUSY; /* In uv_tty_set_mode(). */
|
||||
|
||||
err = 0;
|
||||
if (orig_termios_fd != -1)
|
||||
if (tcsetattr(orig_termios_fd, TCSANOW, &orig_termios))
|
||||
err = -errno;
|
||||
err = UV__ERR(errno);
|
||||
|
||||
uv_spinlock_unlock(&termios_spinlock);
|
||||
errno = saved_errno;
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
void uv_tty_set_vterm_state(uv_tty_vtermstate_t state) {
|
||||
}
|
||||
|
||||
int uv_tty_get_vterm_state(uv_tty_vtermstate_t* state) {
|
||||
return UV_ENOTSUP;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user