From aa33db32380fe05a3bc7a2e320bbf63a6adddf08 Mon Sep 17 00:00:00 2001 From: Saúl Ibarra Corretgé Date: Wed, 3 Jun 2015 21:18:55 +0200 Subject: deps: update libuv to version 1.6.0 Fixes: https://github.com/joyent/node/issues/9310 PR-URL: https://github.com/nodejs/io.js/pull/1889 Reviewed-By: Ben Noordhuis Reviewed-By: Colin Ihrig --- deps/uv/src/unix/core.c | 97 ++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 92 insertions(+), 5 deletions(-) (limited to 'deps/uv/src/unix/core.c') diff --git a/deps/uv/src/unix/core.c b/deps/uv/src/unix/core.c index 6f284ffa7a..cfb7630436 100644 --- a/deps/uv/src/unix/core.c +++ b/deps/uv/src/unix/core.c @@ -38,6 +38,7 @@ #include /* INT_MAX, PATH_MAX */ #include /* writev */ #include /* getrusage */ +#include #ifdef __linux__ # include @@ -282,6 +283,9 @@ int uv_backend_timeout(const uv_loop_t* loop) { if (!QUEUE_EMPTY(&loop->idle_handles)) return 0; + if (!QUEUE_EMPTY(&loop->pending_queue)) + return 0; + if (loop->closing_handles) return 0; @@ -696,16 +700,20 @@ int uv_fileno(const uv_handle_t* handle, uv_os_fd_t* fd) { static int uv__run_pending(uv_loop_t* loop) { QUEUE* q; + QUEUE pq; 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_INIT(&pq); + q = QUEUE_HEAD(&loop->pending_queue); + QUEUE_SPLIT(&loop->pending_queue, q, &pq); + + while (!QUEUE_EMPTY(&pq)) { + q = QUEUE_HEAD(&pq); QUEUE_REMOVE(q); QUEUE_INIT(q); - w = QUEUE_DATA(q, uv__io_t, pending_queue); w->cb(loop, w, UV__POLLOUT); } @@ -745,8 +753,8 @@ static void maybe_resize(uv_loop_t* loop, unsigned int len) { } nwatchers = next_power_of_two(len + 2) - 2; - watchers = realloc(loop->watchers, - (nwatchers + 2) * sizeof(loop->watchers[0])); + watchers = uv__realloc(loop->watchers, + (nwatchers + 2) * sizeof(loop->watchers[0])); if (watchers == NULL) abort(); @@ -983,3 +991,82 @@ int uv__dup2_cloexec(int oldfd, int newfd) { return r; } } + + +int uv_os_homedir(char* buffer, size_t* size) { + struct passwd pw; + struct passwd* result; + char* buf; + uid_t uid; + size_t bufsize; + size_t len; + int r; + + if (buffer == NULL || size == NULL || *size == 0) + return -EINVAL; + + /* Check if the HOME environment variable is set first */ + buf = getenv("HOME"); + + if (buf != NULL) { + len = strlen(buf); + + if (len >= *size) { + *size = len; + return -ENOBUFS; + } + + memcpy(buffer, buf, len + 1); + *size = len; + + return 0; + } + + /* HOME is not set, so call getpwuid() */ + bufsize = sysconf(_SC_GETPW_R_SIZE_MAX); + + if (bufsize <= 0) + return -EIO; + + uid = getuid(); + buf = NULL; + + for (;;) { + uv__free(buf); + buf = uv__malloc(bufsize); + + if (buf == NULL) + return -ENOMEM; + + r = getpwuid_r(uid, &pw, buf, bufsize, &result); + + if (r != ERANGE) + break; + + bufsize *= 2; + } + + if (r != 0) { + uv__free(buf); + return -r; + } + + if (result == NULL) { + uv__free(buf); + return -ENOENT; + } + + len = strlen(pw.pw_dir); + + if (len >= *size) { + *size = len; + uv__free(buf); + return -ENOBUFS; + } + + memcpy(buffer, pw.pw_dir, len + 1); + *size = len; + uv__free(buf); + + return 0; +} -- cgit v1.2.3