summaryrefslogtreecommitdiff
path: root/deps/uv/src/unix/tty.c
diff options
context:
space:
mode:
Diffstat (limited to 'deps/uv/src/unix/tty.c')
-rw-r--r--deps/uv/src/unix/tty.c43
1 files changed, 34 insertions, 9 deletions
diff --git a/deps/uv/src/unix/tty.c b/deps/uv/src/unix/tty.c
index 32fa37eac9..b2d37f4c2c 100644
--- a/deps/uv/src/unix/tty.c
+++ b/deps/uv/src/unix/tty.c
@@ -30,13 +30,17 @@
#include <errno.h>
#include <sys/ioctl.h>
+#if defined(__MVS__) && !defined(IMAXBEL)
+#define IMAXBEL 0
+#endif
+
static int orig_termios_fd = -1;
static struct termios orig_termios;
static uv_spinlock_t termios_spinlock = UV_SPINLOCK_INITIALIZER;
static int uv__tty_is_slave(const int fd) {
int result;
-#if defined(__linux__) || defined(__FreeBSD__)
+#if defined(__linux__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
int dummy;
result = ioctl(fd, TIOCGPTN, &dummy) != 0;
@@ -57,6 +61,7 @@ int uv_tty_init(uv_loop_t* loop, uv_tty_t* tty, int fd, int readable) {
int flags;
int newfd;
int r;
+ int saved_flags;
char path[256];
/* File descriptors that refer to files cannot be monitored with epoll.
@@ -113,6 +118,22 @@ 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);
@@ -120,13 +141,20 @@ skip:
* the handle queue, since it was added by uv__handle_init in uv_stream_init.
*/
+ if (!(flags & UV_STREAM_BLOCKING))
+ uv__nonblock(fd, 1);
+
#if defined(__APPLE__)
r = uv__stream_try_select((uv_stream_t*) tty, &fd);
if (r) {
+ int rc = r;
if (newfd != -1)
uv__close(newfd);
QUEUE_REMOVE(&tty->handle_queue);
- return r;
+ do
+ r = fcntl(fd, F_SETFL, saved_flags);
+ while (r == -1 && errno == EINTR);
+ return rc;
}
#endif
@@ -135,9 +163,6 @@ skip:
else
flags |= UV_STREAM_WRITABLE;
- if (!(flags & UV_STREAM_BLOCKING))
- uv__nonblock(fd, 1);
-
uv__stream_open((uv_stream_t*) tty, fd, flags);
tty->mode = UV_TTY_MODE_NORMAL;
@@ -147,7 +172,7 @@ skip:
static void uv__tty_make_raw(struct termios* tio) {
assert(tio != NULL);
-#ifdef __sun
+#if defined __sun || defined __MVS__
/*
* This implementation of cfmakeraw for Solaris and derivatives is taken from
* http://www.perkin.org.uk/posts/solaris-portability-cfmakeraw.html.
@@ -268,14 +293,14 @@ uv_handle_type uv_guess_handle(uv_file file) {
return UV_UDP;
if (type == SOCK_STREAM) {
-#if defined(_AIX)
- /* on AIX the getsockname call returns an empty sa structure
+#if defined(_AIX) || defined(__DragonFly__)
+ /* on AIX/DragonFly the getsockname call returns an empty sa structure
* for sockets of type AF_UNIX. For all other types it will
* return a properly filled in structure.
*/
if (len == 0)
return UV_NAMED_PIPE;
-#endif /* defined(_AIX) */
+#endif /* defined(_AIX) || defined(__DragonFly__) */
if (sa.sa_family == AF_INET || sa.sa_family == AF_INET6)
return UV_TCP;