summaryrefslogtreecommitdiff
path: root/deps/uv/src/unix
diff options
context:
space:
mode:
Diffstat (limited to 'deps/uv/src/unix')
-rw-r--r--deps/uv/src/unix/aix.c2
-rw-r--r--deps/uv/src/unix/core.c22
-rw-r--r--deps/uv/src/unix/darwin.c37
-rw-r--r--deps/uv/src/unix/freebsd.c2
-rw-r--r--deps/uv/src/unix/fs.c38
-rw-r--r--deps/uv/src/unix/internal.h3
-rw-r--r--deps/uv/src/unix/linux-core.c24
-rw-r--r--deps/uv/src/unix/linux-syscalls.c6
-rw-r--r--deps/uv/src/unix/linux-syscalls.h2
-rw-r--r--deps/uv/src/unix/netbsd.c2
-rw-r--r--deps/uv/src/unix/openbsd.c16
-rw-r--r--deps/uv/src/unix/pipe.c17
-rw-r--r--deps/uv/src/unix/sunos.c8
-rw-r--r--deps/uv/src/unix/tty.c47
-rw-r--r--deps/uv/src/unix/udp.c39
15 files changed, 143 insertions, 122 deletions
diff --git a/deps/uv/src/unix/aix.c b/deps/uv/src/unix/aix.c
index 349c2b558e..0c5d1f4b50 100644
--- a/deps/uv/src/unix/aix.c
+++ b/deps/uv/src/unix/aix.c
@@ -294,7 +294,7 @@ int uv_exepath(char* buffer, size_t* size) {
int fd;
char **argv;
- if ((buffer == NULL) || (size == NULL))
+ if (buffer == NULL || size == NULL || *size == 0)
return -EINVAL;
snprintf(pp, sizeof(pp), "/proc/%lu/psinfo", (unsigned long) getpid());
diff --git a/deps/uv/src/unix/core.c b/deps/uv/src/unix/core.c
index c08040e537..6f284ffa7a 100644
--- a/deps/uv/src/unix/core.c
+++ b/deps/uv/src/unix/core.c
@@ -74,7 +74,7 @@
#include <sys/ioctl.h>
#endif
-static void uv__run_pending(uv_loop_t* loop);
+static int uv__run_pending(uv_loop_t* loop);
/* Verify that uv_buf_t is ABI-compatible with struct iovec. */
STATIC_ASSERT(sizeof(uv_buf_t) == sizeof(struct iovec));
@@ -304,6 +304,7 @@ int uv_loop_alive(const uv_loop_t* loop) {
int uv_run(uv_loop_t* loop, uv_run_mode mode) {
int timeout;
int r;
+ int ran_pending;
r = uv__loop_alive(loop);
if (!r)
@@ -312,12 +313,12 @@ int uv_run(uv_loop_t* loop, uv_run_mode mode) {
while (r != 0 && loop->stop_flag == 0) {
uv__update_time(loop);
uv__run_timers(loop);
- uv__run_pending(loop);
+ ran_pending = uv__run_pending(loop);
uv__run_idle(loop);
uv__run_prepare(loop);
timeout = 0;
- if ((mode & UV_RUN_NOWAIT) == 0)
+ if ((mode == UV_RUN_ONCE && !ran_pending) || mode == UV_RUN_DEFAULT)
timeout = uv_backend_timeout(loop);
uv__io_poll(loop, timeout);
@@ -338,8 +339,7 @@ int uv_run(uv_loop_t* loop, uv_run_mode mode) {
}
r = uv__loop_alive(loop);
-
- if (mode & (UV_RUN_ONCE | UV_RUN_NOWAIT))
+ if (mode == UV_RUN_ONCE || mode == UV_RUN_NOWAIT)
break;
}
@@ -635,6 +635,11 @@ int uv_cwd(char* buffer, size_t* size) {
return -errno;
*size = strlen(buffer);
+ if (*size > 1 && buffer[*size - 1] == '/') {
+ buffer[*size-1] = '\0';
+ (*size)--;
+ }
+
return 0;
}
@@ -689,10 +694,13 @@ int uv_fileno(const uv_handle_t* handle, uv_os_fd_t* fd) {
}
-static void uv__run_pending(uv_loop_t* loop) {
+static int uv__run_pending(uv_loop_t* loop) {
QUEUE* q;
uv__io_t* w;
+ if (QUEUE_EMPTY(&loop->pending_queue))
+ return 0;
+
while (!QUEUE_EMPTY(&loop->pending_queue)) {
q = QUEUE_HEAD(&loop->pending_queue);
QUEUE_REMOVE(q);
@@ -701,6 +709,8 @@ static void uv__run_pending(uv_loop_t* loop) {
w = QUEUE_DATA(q, uv__io_t, pending_queue);
w->cb(loop, w, UV__POLLOUT);
}
+
+ return 1;
}
diff --git a/deps/uv/src/unix/darwin.c b/deps/uv/src/unix/darwin.c
index c9a45edee4..651545f85e 100644
--- a/deps/uv/src/unix/darwin.c
+++ b/deps/uv/src/unix/darwin.c
@@ -65,28 +65,33 @@ uint64_t uv__hrtime(uv_clocktype_t type) {
int uv_exepath(char* buffer, size_t* size) {
- uint32_t usize;
- int result;
- char* path;
- char* fullpath;
+ /* realpath(exepath) may be > PATH_MAX so double it to be on the safe side. */
+ char abspath[PATH_MAX * 2 + 1];
+ char exepath[PATH_MAX + 1];
+ uint32_t exepath_size;
+ size_t abspath_size;
- if (buffer == NULL || size == NULL)
+ if (buffer == NULL || size == NULL || *size == 0)
return -EINVAL;
- usize = *size;
- result = _NSGetExecutablePath(buffer, &usize);
- if (result) return result;
+ exepath_size = sizeof(exepath);
+ if (_NSGetExecutablePath(exepath, &exepath_size))
+ return -EIO;
- path = malloc(2 * PATH_MAX);
- fullpath = realpath(buffer, path);
- if (fullpath == NULL) {
- SAVE_ERRNO(free(path));
+ if (realpath(exepath, abspath) != abspath)
return -errno;
- }
- strncpy(buffer, fullpath, *size);
- free(fullpath);
- *size = strlen(buffer);
+ abspath_size = strlen(abspath);
+ if (abspath_size == 0)
+ return -EIO;
+
+ *size -= 1;
+ if (*size > abspath_size)
+ *size = abspath_size;
+
+ memcpy(buffer, abspath, *size);
+ buffer[*size] = '\0';
+
return 0;
}
diff --git a/deps/uv/src/unix/freebsd.c b/deps/uv/src/unix/freebsd.c
index d59e3773a5..55492adc48 100644
--- a/deps/uv/src/unix/freebsd.c
+++ b/deps/uv/src/unix/freebsd.c
@@ -78,7 +78,7 @@ int uv_exepath(char* buffer, size_t* size) {
int mib[4];
size_t cb;
- if (buffer == NULL || size == NULL)
+ if (buffer == NULL || size == NULL || *size == 0)
return -EINVAL;
#ifdef __DragonFly__
diff --git a/deps/uv/src/unix/fs.c b/deps/uv/src/unix/fs.c
index 65fd01230b..e7eee2f9ab 100644
--- a/deps/uv/src/unix/fs.c
+++ b/deps/uv/src/unix/fs.c
@@ -35,8 +35,10 @@
#include <string.h>
#include <sys/types.h>
+#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/time.h>
+#include <sys/uio.h>
#include <pthread.h>
#include <unistd.h>
#include <fcntl.h>
@@ -48,30 +50,12 @@
defined(__OpenBSD__) || \
defined(__NetBSD__)
# define HAVE_PREADV 1
-#elif defined(__linux__)
-# include <linux/version.h>
-# if defined(__GLIBC_PREREQ)
-# if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,30) && \
- __GLIBC_PREREQ(2,10)
-# define HAVE_PREADV 1
-# else
-# define HAVE_PREADV 0
-# endif
-# else
-# define HAVE_PREADV 0
-# endif
#else
# define HAVE_PREADV 0
#endif
#if defined(__linux__) || defined(__sun)
# include <sys/sendfile.h>
-#elif defined(__APPLE__) || defined(__FreeBSD__)
-# include <sys/socket.h>
-#endif
-
-#if HAVE_PREADV || defined(__APPLE__)
-# include <sys/uio.h>
#endif
#define INIT(type) \
@@ -219,6 +203,9 @@ static ssize_t uv__fs_mkdtemp(uv_fs_t* req) {
static ssize_t uv__fs_read(uv_fs_t* req) {
+#if defined(__linux__)
+ static int no_preadv;
+#endif
ssize_t result;
#if defined(_AIX)
@@ -245,16 +232,12 @@ static ssize_t uv__fs_read(uv_fs_t* req) {
result = preadv(req->file, (struct iovec*) req->bufs, req->nbufs, req->off);
#else
# if defined(__linux__)
- static int no_preadv;
- if (no_preadv)
+ if (no_preadv) retry:
# endif
{
off_t nread;
size_t index;
-# if defined(__linux__)
- retry:
-# endif
nread = 0;
index = 0;
result = 1;
@@ -578,6 +561,9 @@ static ssize_t uv__fs_utime(uv_fs_t* req) {
static ssize_t uv__fs_write(uv_fs_t* req) {
+#if defined(__linux__)
+ static int no_pwritev;
+#endif
ssize_t r;
/* Serialize writes on OS X, concurrent write() and pwrite() calls result in
@@ -603,16 +589,12 @@ static ssize_t uv__fs_write(uv_fs_t* req) {
r = pwritev(req->file, (struct iovec*) req->bufs, req->nbufs, req->off);
#else
# if defined(__linux__)
- static int no_pwritev;
- if (no_pwritev)
+ if (no_pwritev) retry:
# endif
{
off_t written;
size_t index;
-# if defined(__linux__)
- retry:
-# endif
written = 0;
index = 0;
r = 0;
diff --git a/deps/uv/src/unix/internal.h b/deps/uv/src/unix/internal.h
index daad61b782..03a9226101 100644
--- a/deps/uv/src/unix/internal.h
+++ b/deps/uv/src/unix/internal.h
@@ -52,9 +52,6 @@
# include <CoreServices/CoreServices.h>
#endif
-#define STATIC_ASSERT(expr) \
- void uv__static_assert(int static_assert_failed[1 - 2 * !(expr)])
-
#define ACCESS_ONCE(type, var) \
(*(volatile type*) &(var))
diff --git a/deps/uv/src/unix/linux-core.c b/deps/uv/src/unix/linux-core.c
index a2145b0f36..d77b13fd6f 100644
--- a/deps/uv/src/unix/linux-core.c
+++ b/deps/uv/src/unix/linux-core.c
@@ -33,7 +33,6 @@
#include <sys/prctl.h>
#include <sys/sysinfo.h>
#include <unistd.h>
-#include <signal.h>
#include <fcntl.h>
#include <time.h>
@@ -142,8 +141,7 @@ void uv__io_poll(uv_loop_t* loop, int timeout) {
struct uv__epoll_event e;
QUEUE* q;
uv__io_t* w;
- sigset_t* pset;
- sigset_t set;
+ uint64_t sigmask;
uint64_t base;
uint64_t diff;
int nevents;
@@ -194,24 +192,21 @@ void uv__io_poll(uv_loop_t* loop, int timeout) {
w->events = w->pevents;
}
- pset = NULL;
- if (loop->flags & UV_LOOP_BLOCK_SIGPROF) {
- pset = &set;
- sigemptyset(pset);
- sigaddset(pset, SIGPROF);
- }
+ sigmask = 0;
+ if (loop->flags & UV_LOOP_BLOCK_SIGPROF)
+ sigmask |= 1 << (SIGPROF - 1);
assert(timeout >= -1);
base = loop->time;
count = 48; /* Benchmarks suggest this gives the best throughput. */
for (;;) {
- if (no_epoll_wait || pset != NULL) {
+ if (no_epoll_wait || sigmask) {
nfds = uv__epoll_pwait(loop->backend_fd,
events,
ARRAY_SIZE(events),
timeout,
- pset);
+ sigmask);
} else {
nfds = uv__epoll_wait(loop->backend_fd,
events,
@@ -383,10 +378,13 @@ void uv_loadavg(double avg[3]) {
int uv_exepath(char* buffer, size_t* size) {
ssize_t n;
- if (buffer == NULL || size == NULL)
+ if (buffer == NULL || size == NULL || *size == 0)
return -EINVAL;
- n = readlink("/proc/self/exe", buffer, *size - 1);
+ n = *size - 1;
+ if (n > 0)
+ n = readlink("/proc/self/exe", buffer, n);
+
if (n == -1)
return -errno;
diff --git a/deps/uv/src/unix/linux-syscalls.c b/deps/uv/src/unix/linux-syscalls.c
index e036fad5ef..7bf2c0f87d 100644
--- a/deps/uv/src/unix/linux-syscalls.c
+++ b/deps/uv/src/unix/linux-syscalls.c
@@ -321,15 +321,15 @@ int uv__epoll_pwait(int epfd,
struct uv__epoll_event* events,
int nevents,
int timeout,
- const sigset_t* sigmask) {
+ uint64_t sigmask) {
#if defined(__NR_epoll_pwait)
return syscall(__NR_epoll_pwait,
epfd,
events,
nevents,
timeout,
- sigmask,
- _NSIG / 8);
+ &sigmask,
+ sizeof(sigmask));
#else
return errno = ENOSYS, -1;
#endif
diff --git a/deps/uv/src/unix/linux-syscalls.h b/deps/uv/src/unix/linux-syscalls.h
index fd6bb48665..6f249b7245 100644
--- a/deps/uv/src/unix/linux-syscalls.h
+++ b/deps/uv/src/unix/linux-syscalls.h
@@ -131,7 +131,7 @@ int uv__epoll_pwait(int epfd,
struct uv__epoll_event* events,
int nevents,
int timeout,
- const sigset_t* sigmask);
+ uint64_t sigmask);
int uv__eventfd2(unsigned int count, int flags);
int uv__inotify_init(void);
int uv__inotify_init1(int flags);
diff --git a/deps/uv/src/unix/netbsd.c b/deps/uv/src/unix/netbsd.c
index 5f1182f8b4..de99d135f7 100644
--- a/deps/uv/src/unix/netbsd.c
+++ b/deps/uv/src/unix/netbsd.c
@@ -83,7 +83,7 @@ int uv_exepath(char* buffer, size_t* size) {
size_t cb;
pid_t mypid;
- if (buffer == NULL || size == NULL)
+ if (buffer == NULL || size == NULL || *size == 0)
return -EINVAL;
mypid = getpid();
diff --git a/deps/uv/src/unix/openbsd.c b/deps/uv/src/unix/openbsd.c
index cde8d4d0c9..3e7ae848ee 100644
--- a/deps/uv/src/unix/openbsd.c
+++ b/deps/uv/src/unix/openbsd.c
@@ -85,7 +85,7 @@ int uv_exepath(char* buffer, size_t* size) {
pid_t mypid;
int err;
- if (buffer == NULL || size == NULL)
+ if (buffer == NULL || size == NULL || *size == 0)
return -EINVAL;
mypid = getpid();
@@ -108,17 +108,19 @@ int uv_exepath(char* buffer, size_t* size) {
}
argsbuf_size *= 2U;
}
+
if (argsbuf[0] == NULL) {
err = -EINVAL; /* FIXME(bnoordhuis) More appropriate error. */
goto out;
}
+
+ *size -= 1;
exepath_size = strlen(argsbuf[0]);
- if (exepath_size >= *size) {
- err = -EINVAL;
- goto out;
- }
- memcpy(buffer, argsbuf[0], exepath_size + 1U);
- *size = exepath_size;
+ if (*size > exepath_size)
+ *size = exepath_size;
+
+ memcpy(buffer, argsbuf[0], *size);
+ buffer[*size] = '\0';
err = 0;
out:
diff --git a/deps/uv/src/unix/pipe.c b/deps/uv/src/unix/pipe.c
index b20fb9210c..ef47700b7a 100644
--- a/deps/uv/src/unix/pipe.c
+++ b/deps/uv/src/unix/pipe.c
@@ -55,17 +55,15 @@ int uv_pipe_bind(uv_pipe_t* handle, const char* name) {
/* Make a copy of the file name, it outlives this function's scope. */
pipe_fname = strdup(name);
- if (pipe_fname == NULL) {
- err = -ENOMEM;
- goto out;
- }
+ if (pipe_fname == NULL)
+ return -ENOMEM;
/* We've got a copy, don't touch the original any more. */
name = NULL;
err = uv__socket(AF_UNIX, SOCK_STREAM, 0);
if (err < 0)
- goto out;
+ goto err_socket;
sockfd = err;
memset(&saddr, 0, sizeof saddr);
@@ -78,7 +76,7 @@ int uv_pipe_bind(uv_pipe_t* handle, const char* name) {
/* Convert ENOENT to EACCES for compatibility with Windows. */
if (err == -ENOENT)
err = -EACCES;
- goto out;
+ goto err_bind;
}
/* Success. */
@@ -86,11 +84,10 @@ int uv_pipe_bind(uv_pipe_t* handle, const char* name) {
handle->io_watcher.fd = sockfd;
return 0;
-out:
- /* unlink() before uv__close() to avoid races. */
- assert(pipe_fname != NULL);
- unlink(pipe_fname);
+err_bind:
uv__close(sockfd);
+
+err_socket:
free((void*)pipe_fname);
return err;
}
diff --git a/deps/uv/src/unix/sunos.c b/deps/uv/src/unix/sunos.c
index d6fb7f4950..ca183a6227 100644
--- a/deps/uv/src/unix/sunos.c
+++ b/deps/uv/src/unix/sunos.c
@@ -300,11 +300,15 @@ int uv_exepath(char* buffer, size_t* size) {
ssize_t res;
char buf[128];
- if (buffer == NULL || size == NULL)
+ if (buffer == NULL || size == NULL || *size == 0)
return -EINVAL;
snprintf(buf, sizeof(buf), "/proc/%lu/path/a.out", (unsigned long) getpid());
- res = readlink(buf, buffer, *size - 1);
+
+ res = *size - 1;
+ if (res > 0)
+ res = readlink(buf, buffer, res);
+
if (res == -1)
return -errno;
diff --git a/deps/uv/src/unix/tty.c b/deps/uv/src/unix/tty.c
index 7ae19905fb..068025eaf5 100644
--- a/deps/uv/src/unix/tty.c
+++ b/deps/uv/src/unix/tty.c
@@ -98,19 +98,19 @@ skip:
uv__nonblock(fd, 1);
uv__stream_open((uv_stream_t*) tty, fd, flags);
- tty->mode = 0;
+ tty->mode = UV_TTY_MODE_NORMAL;
return 0;
}
-int uv_tty_set_mode(uv_tty_t* tty, int mode) {
- struct termios raw;
+int uv_tty_set_mode(uv_tty_t* tty, uv_tty_mode_t mode) {
+ struct termios tmp;
int fd;
fd = uv__stream_fd(tty);
- if (mode && tty->mode == 0) { /* on */
+ if (tty->mode == UV_TTY_MODE_NORMAL && mode != UV_TTY_MODE_NORMAL) {
if (tcgetattr(fd, &tty->orig_termios))
return -errno;
@@ -121,27 +121,30 @@ int uv_tty_set_mode(uv_tty_t* tty, int mode) {
orig_termios_fd = fd;
}
uv_spinlock_unlock(&termios_spinlock);
+ }
- raw = tty->orig_termios;
- raw.c_iflag &= ~(BRKINT | ICRNL | INPCK | ISTRIP | IXON);
- raw.c_oflag |= (ONLCR);
- raw.c_cflag |= (CS8);
- raw.c_lflag &= ~(ECHO | ICANON | IEXTEN | ISIG);
- raw.c_cc[VMIN] = 1;
- raw.c_cc[VTIME] = 0;
-
- /* Put terminal in raw mode after draining */
- if (tcsetattr(fd, TCSADRAIN, &raw))
- return -errno;
-
- tty->mode = 1;
- } else if (mode == 0 && tty->mode) { /* off */
- /* Put terminal in original mode after flushing */
- if (tcsetattr(fd, TCSAFLUSH, &tty->orig_termios))
- return -errno;
- tty->mode = 0;
+ tmp = tty->orig_termios;
+ switch (mode) {
+ case UV_TTY_MODE_NORMAL:
+ break;
+ case UV_TTY_MODE_RAW:
+ tmp.c_iflag &= ~(BRKINT | ICRNL | INPCK | ISTRIP | IXON);
+ tmp.c_oflag |= (ONLCR);
+ tmp.c_cflag |= (CS8);
+ tmp.c_lflag &= ~(ECHO | ICANON | IEXTEN | ISIG);
+ tmp.c_cc[VMIN] = 1;
+ tmp.c_cc[VTIME] = 0;
+ break;
+ case UV_TTY_MODE_IO:
+ cfmakeraw(&tmp);
+ break;
}
+ /* Apply changes after draining */
+ if (tcsetattr(fd, TCSADRAIN, &tmp))
+ return -errno;
+
+ tty->mode = mode;
return 0;
}
diff --git a/deps/uv/src/unix/udp.c b/deps/uv/src/unix/udp.c
index 71a0e41f1f..2e1824c358 100644
--- a/deps/uv/src/unix/udp.c
+++ b/deps/uv/src/unix/udp.c
@@ -598,7 +598,11 @@ int uv_udp_set_membership(uv_udp_t* handle,
}
-static int uv__setsockopt_maybe_char(uv_udp_t* handle, int option, int val) {
+static int uv__setsockopt_maybe_char(uv_udp_t* handle,
+ int option4,
+ int option6,
+ int val) {
+ int r;
#if defined(__sun) || defined(_AIX)
char arg = val;
#else
@@ -608,7 +612,20 @@ static int uv__setsockopt_maybe_char(uv_udp_t* handle, int option, int val) {
if (val < 0 || val > 255)
return -EINVAL;
- if (setsockopt(handle->io_watcher.fd, IPPROTO_IP, option, &arg, sizeof(arg)))
+ if (handle->flags & UV_HANDLE_IPV6)
+ r = setsockopt(handle->io_watcher.fd,
+ IPPROTO_IPV6,
+ option6,
+ &arg,
+ sizeof(arg));
+ else
+ r = setsockopt(handle->io_watcher.fd,
+ IPPROTO_IP,
+ option4,
+ &arg,
+ sizeof(arg));
+
+ if (r)
return -errno;
return 0;
@@ -632,20 +649,26 @@ int uv_udp_set_ttl(uv_udp_t* handle, int ttl) {
if (ttl < 1 || ttl > 255)
return -EINVAL;
- if (setsockopt(handle->io_watcher.fd, IPPROTO_IP, IP_TTL, &ttl, sizeof(ttl)))
- return -errno;
-
- return 0;
+ return uv__setsockopt_maybe_char(handle,
+ IP_TTL,
+ IPV6_UNICAST_HOPS,
+ ttl);
}
int uv_udp_set_multicast_ttl(uv_udp_t* handle, int ttl) {
- return uv__setsockopt_maybe_char(handle, IP_MULTICAST_TTL, ttl);
+ return uv__setsockopt_maybe_char(handle,
+ IP_MULTICAST_TTL,
+ IPV6_MULTICAST_HOPS,
+ ttl);
}
int uv_udp_set_multicast_loop(uv_udp_t* handle, int on) {
- return uv__setsockopt_maybe_char(handle, IP_MULTICAST_LOOP, on);
+ return uv__setsockopt_maybe_char(handle,
+ IP_MULTICAST_LOOP,
+ IPV6_MULTICAST_LOOP,
+ on);
}
int uv_udp_set_multicast_interface(uv_udp_t* handle, const char* interface_addr) {