Commit 340a3625 authored by Jason Madden's avatar Jason Madden Committed by GitHub

Merge pull request #1328 from gevent/libuv-1,24

Upgrade libuv to 1.24.0
parents 836bf7ef f0a7dccc
......@@ -71,6 +71,8 @@
been `IOError` on Python 2. Reported by, and PR by, Ricardo Kirkner.
See :issue:`1323`.
- Upgrade libuv from 1.23.2 to 1.24.0.
1.3.7 (2018-10-12)
==================
......
......@@ -12,13 +12,13 @@
Updating libuv
==============
- Clean up the libuv tree:
- rm -rf libuv/.github
- rm -rf libuv/docs
- rm -rf libuv/samples
- rm -rf libuv/test
- rm -rf libuv/tools
- rm -f libuv/android-configure*
- Clean up the libuv tree, and apply the patches to libuv (this whole
sequence is meant to be copied and pasted into the terminal)::
- Apply the patches to libuv:
- git apply libuv-win-binary.patch
rm -rf libuv/.github
rm -rf libuv/docs
rm -rf libuv/samples
rm -rf libuv/test
rm -rf libuv/tools
rm -f libuv/android-configure*
git apply libuv-win-binary.patch
......@@ -352,3 +352,7 @@ Andy Zhang <zhangyong232@gmail.com>
dmabupt <dmabupt@gmail.com>
Ryan Liptak <squeek502@hotmail.com>
Ali Ijaz Sheikh <ofrobots@google.com>
hitesh <sainihitesh.scientist@gmail.com>
Svante Signell <svante.signell@gmail.com>
Samuel Thibault <sthibault@debian.org>
Jeremy Studer <studerj1.mail@gmail.com>
......@@ -13,6 +13,7 @@ endif()
set(uv_sources
src/fs-poll.c
src/idna.c
src/inet.c
src/threadpool.c
src/timer.c
......@@ -64,6 +65,7 @@ set(uv_test_sources
test/test-homedir.c
test/test-hrtime.c
test/test-idle.c
test/test-idna.c
test/test-ip4-addr.c
test/test-ip6-addr.c
test/test-ip6-addr.c
......@@ -260,7 +262,7 @@ if(CMAKE_SYSTEM_NAME MATCHES "DragonFly|FreeBSD")
endif()
if(CMAKE_SYSTEM_NAME MATCHES "DragonFly|FreeBSD|NetBSD|OpenBSD")
list(APPEND uv_sources src/unix/posix-hrtime.c)
list(APPEND uv_sources src/unix/posix-hrtime.c src/unix/bsd-proctitle.c)
list(APPEND uv_libraries kvm)
endif()
......
2018.10.09, Version 1.23.2 (Stable)
2018.11.14, Version 1.24.0 (Stable)
Changes since version 1.23.2:
* unix: do not require PATH_MAX to be defined (Brad King)
* win,doc: path encoding in uv_fs_XX is UTF-8 (hitesh)
* unix: add missing link dependency on kFreeBSD (Svante Signell)
* unix: add support for GNU/Hurd (Samuel Thibault)
* test: avoid memory leak for test_output (Carlo Marcelo Arenas Belón)
* zos: avoid UB with NULL pointer arithmetic (Carlo Marcelo Arenas Belón)
* doc: add vtjnash to maintainers (Jameson Nash)
* unix: restore skipping of phys_addr copy (cjihrig)
* unix,win: make uv_interface_addresses() consistent (cjihrig)
* unix: remove unnecessary linebreaks (cjihrig)
* unix,win: handle zero-sized allocations uniformly (Ben Noordhuis)
* unix: remove unused uv__dup() function (Ben Noordhuis)
* core,bsd: refactor process_title functions (Santiago Gimeno)
* win: Redefine NSIG to consider SIGWINCH (Jeremy Studer)
* test: make sure that reading a directory fails (Sakthipriyan Vairamani)
* win, tty: remove zero-size read callbacks (Bartosz Sosnowski)
* test: fix test runner getenv async-signal-safety (Ben Noordhuis)
* test: fix test runner execvp async-signal-safety (Ben Noordhuis)
* test,unix: fix race in test runner (Ben Noordhuis)
* unix,win: support IDNA 2008 in uv_getaddrinfo() (Ben Noordhuis)
* win, tcp: avoid starving the loop (Bartosz Sosnowski)
* win, dl: proper error messages on some systems (Bartosz Sosnowski)
* win,fs: retry if uv_fs_rename fails (Bartosz Sosnowski)
* darwin: speed up uv_set_process_title() (Ben Noordhuis)
* aix: fix race in uv_get_process_title() (Gireesh Punathil)
* win: support more fine-grained windows hiding (Bartosz Sosnowski)
2018.10.09, Version 1.23.2 (Stable), 34c12788d2e7308f3ac506c0abcbf74c0d6abd20
Changes since version 1.23.1:
......
......@@ -15,6 +15,7 @@ libuv is currently managed by the following individuals:
- GPG key: AF2E EA41 EC34 47BF DD86 FED9 D706 3CCE 19B7 E890 (pubkey-indutny)
* **Imran Iqbal** ([@imran-iq](https://github.com/imran-iq))
- GPG key: 9DFE AA5F 481B BF77 2D90 03CE D592 4925 2F8E C41A (pubkey-iwuzhere)
* **Jameson Nash** ([@vtjnash](https://github.com/vtjnash))
* **John Barboza** ([@jbarz](https://github.com/jbarz))
* **Santiago Gimeno** ([@santigimeno](https://github.com/santigimeno))
- GPG key: 612F 0EAD 9401 6223 79DF 4402 F28C 3C8D A33C 03BE (pubkey-santigimeno)
......
......@@ -29,6 +29,7 @@ libuv_la_CFLAGS = @CFLAGS@
libuv_la_LDFLAGS = -no-undefined -version-info 1:0:0
libuv_la_SOURCES = src/fs-poll.c \
src/heap-inl.h \
src/idna.c \
src/inet.c \
src/queue.h \
src/threadpool.c \
......@@ -189,6 +190,7 @@ test_run_tests_SOURCES = test/blackhole-server.c \
test/test-homedir.c \
test/test-hrtime.c \
test/test-idle.c \
test/test-idna.c \
test/test-ip4-addr.c \
test/test-ip6-addr.c \
test/test-ipc-heavy-traffic-deadlock-bug.c \
......@@ -374,6 +376,7 @@ endif
if DRAGONFLY
uvinclude_HEADERS += include/uv/bsd.h
libuv_la_SOURCES += src/unix/bsd-ifaddrs.c \
src/unix/bsd-proctitle.c \
src/unix/freebsd.c \
src/unix/kqueue.c \
src/unix/posix-hrtime.c
......@@ -383,12 +386,20 @@ endif
if FREEBSD
uvinclude_HEADERS += include/uv/bsd.h
libuv_la_SOURCES += src/unix/bsd-ifaddrs.c \
src/unix/bsd-proctitle.c \
src/unix/freebsd.c \
src/unix/kqueue.c \
src/unix/posix-hrtime.c
test_run_tests_LDFLAGS += -lutil
endif
if HURD
uvinclude_HEADERS += include/uv/posix.h
libuv_la_SOURCES += src/unix/no-fsevents.c \
src/unix/posix-hrtime.c \
src/unix/posix-poll.c
endif
if LINUX
uvinclude_HEADERS += include/uv/linux.h
libuv_la_CFLAGS += -D_GNU_SOURCE
......@@ -419,6 +430,7 @@ endif
if NETBSD
uvinclude_HEADERS += include/uv/bsd.h
libuv_la_SOURCES += src/unix/bsd-ifaddrs.c \
src/unix/bsd-proctitle.c \
src/unix/kqueue.c \
src/unix/netbsd.c \
src/unix/posix-hrtime.c
......@@ -428,6 +440,7 @@ endif
if OPENBSD
uvinclude_HEADERS += include/uv/bsd.h
libuv_la_SOURCES += src/unix/bsd-ifaddrs.c \
src/unix/bsd-proctitle.c \
src/unix/kqueue.c \
src/unix/openbsd.c \
src/unix/posix-hrtime.c
......
......@@ -13,7 +13,7 @@
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
AC_PREREQ(2.57)
AC_INIT([libuv], [1.23.2], [https://github.com/libuv/libuv/issues])
AC_INIT([libuv], [1.24.0], [https://github.com/libuv/libuv/issues])
AC_CONFIG_MACRO_DIR([m4])
m4_include([m4/libuv-extra-automake-flags.m4])
m4_include([m4/as_case.m4])
......@@ -56,6 +56,7 @@ AM_CONDITIONAL([CYGWIN], [AS_CASE([$host_os],[cygwin*], [true], [false])
AM_CONDITIONAL([DARWIN], [AS_CASE([$host_os],[darwin*], [true], [false])])
AM_CONDITIONAL([DRAGONFLY],[AS_CASE([$host_os],[dragonfly*], [true], [false])])
AM_CONDITIONAL([FREEBSD], [AS_CASE([$host_os],[*freebsd*], [true], [false])])
AM_CONDITIONAL([HURD], [AS_CASE([$host_os],[gnu*], [true], [false])])
AM_CONDITIONAL([LINUX], [AS_CASE([$host_os],[linux*], [true], [false])])
AM_CONDITIONAL([MSYS], [AS_CASE([$host_os],[msys*], [true], [false])])
AM_CONDITIONAL([NETBSD], [AS_CASE([$host_os],[netbsd*], [true], [false])])
......@@ -67,6 +68,9 @@ AS_CASE([$host_os],[mingw*], [
LIBS="$LIBS -lws2_32 -lpsapi -liphlpapi -lshell32 -luserenv -luser32"
])
AS_CASE([$host_os], [netbsd*], [AC_CHECK_LIB([kvm], [kvm_open])])
AS_CASE([$host_os], [kfreebsd*], [
LIBS="$LIBS -lfreebsd-glue"
])
AC_CHECK_HEADERS([sys/ahafs_evProds.h])
AC_CONFIG_FILES([Makefile libuv.pc])
AC_OUTPUT
......@@ -963,11 +963,22 @@ enum uv_process_flags {
*/
UV_PROCESS_DETACHED = (1 << 3),
/*
* Hide the subprocess console window that would normally be created. This
* Hide the subprocess window that would normally be created. This option is
* only meaningful on Windows systems. On Unix it is silently ignored.
*/
UV_PROCESS_WINDOWS_HIDE = (1 << 4),
/*
* Hide the subprocess console window that would normally be created. This
* option is only meaningful on Windows systems. On Unix it is silently
* ignored.
*/
UV_PROCESS_WINDOWS_HIDE_CONSOLE = (1 << 5),
/*
* Hide the subprocess GUI window that would normally be created. This
* option is only meaningful on Windows systems. On Unix it is silently
* ignored.
*/
UV_PROCESS_WINDOWS_HIDE = (1 << 4)
UV_PROCESS_WINDOWS_HIDE_GUI = (1 << 6)
};
/*
......
......@@ -64,6 +64,8 @@
# include "uv/bsd.h"
#elif defined(__CYGWIN__) || defined(__MSYS__)
# include "uv/posix.h"
#elif defined(__GNU__)
# include "uv/posix.h"
#endif
#ifndef NI_MAXHOST
......
......@@ -31,8 +31,8 @@
*/
#define UV_VERSION_MAJOR 1
#define UV_VERSION_MINOR 23
#define UV_VERSION_PATCH 2
#define UV_VERSION_MINOR 24
#define UV_VERSION_PATCH 0
#define UV_VERSION_IS_RELEASE 1
#define UV_VERSION_SUFFIX ""
......
......@@ -86,6 +86,14 @@ typedef struct pollfd {
#define SIGKILL 9
#define SIGWINCH 28
/* Redefine NSIG to take SIGWINCH into consideration */
#if defined(NSIG) && NSIG <= SIGWINCH
# undef NSIG
#endif
#ifndef NSIG
# define NSIG SIGWINCH + 1
#endif
/* The CRT defines SIGABRT_COMPAT as 6, which equals SIGABRT on many unix-like
* platforms. However MinGW doesn't define it, so we do. */
#ifndef SIGABRT_COMPAT
......
/* Copyright (c) 2011, 2018 Ben Noordhuis <info@bnoordhuis.nl>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/* Derived from https://github.com/bnoordhuis/punycode
* but updated to support IDNA 2008.
*/
#include "uv.h"
#include "idna.h"
#include <string.h>
static unsigned uv__utf8_decode1_slow(const char** p,
const char* pe,
unsigned a) {
unsigned b;
unsigned c;
unsigned d;
unsigned min;
if (a > 0xF7)
return -1;
switch (*p - pe) {
default:
if (a > 0xEF) {
min = 0x10000;
a = a & 7;
b = (unsigned char) *(*p)++;
c = (unsigned char) *(*p)++;
d = (unsigned char) *(*p)++;
break;
}
/* Fall through. */
case 2:
if (a > 0xDF) {
min = 0x800;
b = 0x80 | (a & 15);
c = (unsigned char) *(*p)++;
d = (unsigned char) *(*p)++;
a = 0;
break;
}
/* Fall through. */
case 1:
if (a > 0xBF) {
min = 0x80;
b = 0x80;
c = 0x80 | (a & 31);
d = (unsigned char) *(*p)++;
a = 0;
break;
}
return -1; /* Invalid continuation byte. */
}
if (0x80 != (0xC0 & (b ^ c ^ d)))
return -1; /* Invalid sequence. */
b &= 63;
c &= 63;
d &= 63;
a = (a << 18) | (b << 12) | (c << 6) | d;
if (a < min)
return -1; /* Overlong sequence. */
if (a > 0x10FFFF)
return -1; /* Four-byte sequence > U+10FFFF. */
if (a >= 0xD800 && a <= 0xDFFF)
return -1; /* Surrogate pair. */
return a;
}
unsigned uv__utf8_decode1(const char** p, const char* pe) {
unsigned a;
a = (unsigned char) *(*p)++;
if (a < 128)
return a; /* ASCII, common case. */
return uv__utf8_decode1_slow(p, pe, a);
}
#define foreach_codepoint(c, p, pe) \
for (; (void) (*p <= pe && (c = uv__utf8_decode1(p, pe))), *p <= pe;)
static int uv__idna_toascii_label(const char* s, const char* se,
char** d, char* de) {
static const char alphabet[] = "abcdefghijklmnopqrstuvwxyz0123456789";
const char* ss;
unsigned c;
unsigned h;
unsigned k;
unsigned n;
unsigned m;
unsigned q;
unsigned t;
unsigned x;
unsigned y;
unsigned bias;
unsigned delta;
unsigned todo;
int first;
h = 0;
ss = s;
todo = 0;
foreach_codepoint(c, &s, se) {
if (c < 128)
h++;
else if (c == (unsigned) -1)
return UV_EINVAL;
else
todo++;
}
if (todo > 0) {
if (*d < de) *(*d)++ = 'x';
if (*d < de) *(*d)++ = 'n';
if (*d < de) *(*d)++ = '-';
if (*d < de) *(*d)++ = '-';
}
x = 0;
s = ss;
foreach_codepoint(c, &s, se) {
if (c > 127)
continue;
if (*d < de)
*(*d)++ = c;
if (++x == h)
break; /* Visited all ASCII characters. */
}
if (todo == 0)
return h;
/* Only write separator when we've written ASCII characters first. */
if (h > 0)
if (*d < de)
*(*d)++ = '-';
n = 128;
bias = 72;
delta = 0;
first = 1;
while (todo > 0) {
m = -1;
s = ss;
foreach_codepoint(c, &s, se)
if (c >= n)
if (c < m)
m = c;
x = m - n;
y = h + 1;
if (x > ~delta / y)
return UV_E2BIG; /* Overflow. */
delta += x * y;
n = m;
s = ss;
foreach_codepoint(c, &s, se) {
if (c < n)
if (++delta == 0)
return UV_E2BIG; /* Overflow. */
if (c != n)
continue;
for (k = 36, q = delta; /* empty */; k += 36) {
t = 1;
if (k > bias)
t = k - bias;
if (t > 26)
t = 26;
if (q < t)
break;
/* TODO(bnoordhuis) Since 1 <= t <= 26 and therefore
* 10 <= y <= 35, we can optimize the long division
* into a table-based reciprocal multiplication.
*/
x = q - t;
y = 36 - t; /* 10 <= y <= 35 since 1 <= t <= 26. */
q = x / y;
t = t + x % y; /* 1 <= t <= 35 because of y. */
if (*d < de)
*(*d)++ = alphabet[t];
}
if (*d < de)
*(*d)++ = alphabet[q];
delta /= 2;
if (first) {
delta /= 350;
first = 0;
}
/* No overflow check is needed because |delta| was just
* divided by 2 and |delta+delta >= delta + delta/h|.
*/
h++;
delta += delta / h;
for (bias = 0; delta > 35 * 26 / 2; bias += 36)
delta /= 35;
bias += 36 * delta / (delta + 38);
delta = 0;
todo--;
}
delta++;
n++;
}
return 0;
}
#undef foreach_codepoint
long uv__idna_toascii(const char* s, const char* se, char* d, char* de) {
const char* si;
const char* st;
unsigned c;
char* ds;
int rc;
ds = d;
for (si = s; si < se; /* empty */) {
st = si;
c = uv__utf8_decode1(&si, se);
if (c != '.')
if (c != 0x3002) /* 。 */
if (c != 0xFF0E) /* . */
if (c != 0xFF61) /* 。 */
continue;
rc = uv__idna_toascii_label(s, st, &d, de);
if (rc < 0)
return rc;
if (d < de)
*d++ = '.';
s = si;
}
if (s < se) {
rc = uv__idna_toascii_label(s, se, &d, de);
if (rc < 0)
return rc;
}
if (d < de)
*d++ = '\0';
return d - ds; /* Number of bytes written. */
}
/* Copyright (c) 2011, 2018 Ben Noordhuis <info@bnoordhuis.nl>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#ifndef UV_SRC_IDNA_H_
#define UV_SRC_IDNA_H_
/* Decode a single codepoint. Returns the codepoint or UINT32_MAX on error.
* |p| is updated on success _and_ error, i.e., bad multi-byte sequences are
* skipped in their entirety, not just the first bad byte.
*/
unsigned uv__utf8_decode1(const char** p, const char* pe);
/* Convert a UTF-8 domain name to IDNA 2008 / Punycode. A return value >= 0
* is the number of bytes written to |d|, including the trailing nul byte.
* A return value < 0 is a libuv error code. |s| and |d| can not overlap.
*/
long uv__idna_toascii(const char* s, const char* se, char* d, char* de);
#endif /* UV_SRC_IDNA_H_ */
......@@ -166,8 +166,7 @@ void uv_free_cpu_info(uv_cpu_info_t* cpu_infos, int count) {
}
int uv_interface_addresses(uv_interface_address_t** addresses,
int* count) {
int uv_interface_addresses(uv_interface_address_t** addresses, int* count) {
uv_interface_address_t* address;
int sockfd, inet6, size = 1;
struct ifconf ifc;
......@@ -175,6 +174,7 @@ int uv_interface_addresses(uv_interface_address_t** addresses,
struct sockaddr_dl* sa_addr;
*count = 0;
*addresses = NULL;
if (0 > (sockfd = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP))) {
return UV__ERR(errno);
......@@ -217,6 +217,11 @@ int uv_interface_addresses(uv_interface_address_t** addresses,
(*count)++;
}
if (*count == 0) {
uv__close(sockfd);
return 0;
}
/* Alloc the return interface structs */
*addresses = uv__malloc(*count * sizeof(uv_interface_address_t));
if (!(*addresses)) {
......@@ -289,4 +294,4 @@ void uv_free_interface_addresses(uv_interface_address_t* addresses,
}
uv__free(addresses);
}
\ No newline at end of file
}
......@@ -886,16 +886,20 @@ int uv_set_process_title(const char* title) {
int uv_get_process_title(char* buffer, size_t size) {
size_t len;
len = strlen(process_argv[0]);
if (buffer == NULL || size == 0)
return UV_EINVAL;
else if (size <= len)
return UV_ENOBUFS;
uv_once(&process_title_mutex_once, init_process_title_mutex_once);
uv_mutex_lock(&process_title_mutex);
memcpy(buffer, process_argv[0], len + 1);
len = strlen(process_argv[0]);
if (size <= len) {
uv_mutex_unlock(&process_title_mutex);
return UV_ENOBUFS;
}
memcpy(buffer, process_argv[0], len);
buffer[len] = '\0';
uv_mutex_unlock(&process_title_mutex);
......
......@@ -69,11 +69,12 @@ int uv_interface_addresses(uv_interface_address_t** addresses, int* count) {
uv_interface_address_t* address;
int i;
*count = 0;
*addresses = NULL;
if (getifaddrs(&addrs) != 0)
return UV__ERR(errno);
*count = 0;
/* Count the number of interfaces */
for (ent = addrs; ent != NULL; ent = ent->ifa_next) {
if (uv__ifaddr_exclude(ent, UV__EXCLUDE_IFADDR))
......@@ -81,6 +82,11 @@ int uv_interface_addresses(uv_interface_address_t** addresses, int* count) {
(*count)++;
}
if (*count == 0) {
freeifaddrs(addrs);
return 0;
}
*addresses = uv__malloc(*count * sizeof(**addresses));
if (*addresses == NULL) {
......@@ -119,14 +125,19 @@ int uv_interface_addresses(uv_interface_address_t** addresses, int* count) {
continue;
address = *addresses;
memset(address->phys_addr, 0, sizeof(address->phys_addr));
for (i = 0; i < *count; i++) {
#if defined(__CYGWIN__) || defined(__MSYS__)
memset(address->phys_addr, 0, sizeof(address->phys_addr));
#else
if (strcmp(address->name, ent->ifa_name) == 0) {
struct sockaddr_dl* sa_addr;
sa_addr = (struct sockaddr_dl*)(ent->ifa_addr);
memcpy(address->phys_addr, LLADDR(sa_addr), sizeof(address->phys_addr));
} else {
memset(address->phys_addr, 0, sizeof(address->phys_addr));
}
#endif
address++;
}
}
......
/* Copyright libuv project contributors. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
#include "uv.h"
#include "internal.h"
#include <sys/types.h>
#include <unistd.h>
static uv_mutex_t process_title_mutex;
static uv_once_t process_title_mutex_once = UV_ONCE_INIT;
static char* process_title;
static void init_process_title_mutex_once(void) {
if (uv_mutex_init(&process_title_mutex))
abort();
}
char** uv_setup_args(int argc, char** argv) {
process_title = argc > 0 ? uv__strdup(argv[0]) : NULL;
return argv;
}
int uv_set_process_title(const char* title) {
char* new_title;
new_title = uv__strdup(title);
if (new_title == NULL)
return UV_ENOMEM;
uv_once(&process_title_mutex_once, init_process_title_mutex_once);
uv_mutex_lock(&process_title_mutex);
uv__free(process_title);
process_title = new_title;
setproctitle("%s", title);
uv_mutex_unlock(&process_title_mutex);
return 0;
}
int uv_get_process_title(char* buffer, size_t size) {
size_t len;
if (buffer == NULL || size == 0)
return UV_EINVAL;
uv_once(&process_title_mutex_once, init_process_title_mutex_once);
uv_mutex_lock(&process_title_mutex);
if (process_title != NULL) {
len = strlen(process_title) + 1;
if (size < len) {
uv_mutex_unlock(&process_title_mutex);
return UV_ENOBUFS;
}
memcpy(buffer, process_title, len);
} else {
len = 0;
}
uv_mutex_unlock(&process_title_mutex);
buffer[len] = '\0';
return 0;
}
......@@ -636,27 +636,6 @@ int uv__cloexec_fcntl(int fd, int set) {
}
/* This function is not execve-safe, there is a race window
* between the call to dup() and fcntl(FD_CLOEXEC).
*/
int uv__dup(int fd) {
int err;
fd = dup(fd);
if (fd == -1)
return UV__ERR(errno);
err = uv__cloexec(fd, 1);
if (err) {
uv__close(fd);
return err;
}
return fd;
}
ssize_t uv__recvmsg(int fd, struct msghdr* msg, int flags) {
struct cmsghdr* cmsg;
ssize_t rc;
......
......@@ -33,61 +33,56 @@
# include <ApplicationServices/ApplicationServices.h>
#endif
#define S(s) pCFStringCreateWithCString(NULL, (s), kCFStringEncodingUTF8)
static int uv__pthread_setname_np(const char* name) {
int (*dynamic_pthread_setname_np)(const char* name);
char namebuf[64]; /* MAXTHREADNAMESIZE */
int err;
/* pthread_setname_np() first appeared in OS X 10.6 and iOS 3.2. */
*(void **)(&dynamic_pthread_setname_np) =
dlsym(RTLD_DEFAULT, "pthread_setname_np");
if (dynamic_pthread_setname_np == NULL)
return UV_ENOSYS;
strncpy(namebuf, name, sizeof(namebuf) - 1);
namebuf[sizeof(namebuf) - 1] = '\0';
err = dynamic_pthread_setname_np(namebuf);
if (err)
return UV__ERR(err);
static int (*dynamic_pthread_setname_np)(const char* name);
#if !TARGET_OS_IPHONE
static CFStringRef (*pCFStringCreateWithCString)(CFAllocatorRef,
const char*,
CFStringEncoding);
static CFBundleRef (*pCFBundleGetBundleWithIdentifier)(CFStringRef);
static void *(*pCFBundleGetDataPointerForName)(CFBundleRef, CFStringRef);
static void *(*pCFBundleGetFunctionPointerForName)(CFBundleRef, CFStringRef);
static CFTypeRef (*pLSGetCurrentApplicationASN)(void);
static OSStatus (*pLSSetApplicationInformationItem)(int,
CFTypeRef,
CFStringRef,
CFStringRef,
CFDictionaryRef*);
static void* application_services_handle;
static void* core_foundation_handle;
static CFBundleRef launch_services_bundle;
static CFStringRef* display_name_key;
static CFDictionaryRef (*pCFBundleGetInfoDictionary)(CFBundleRef);
static CFBundleRef (*pCFBundleGetMainBundle)(void);
static CFBundleRef hi_services_bundle;
static OSStatus (*pSetApplicationIsDaemon)(int);
static CFDictionaryRef (*pLSApplicationCheckIn)(int, CFDictionaryRef);
static void (*pLSSetApplicationLaunchServicesServerConnectionStatus)(uint64_t,
void*);
UV_DESTRUCTOR(static void uv__set_process_title_platform_fini(void)) {
if (core_foundation_handle != NULL) {
dlclose(core_foundation_handle);
core_foundation_handle = NULL;
}
return 0;
if (application_services_handle != NULL) {
dlclose(application_services_handle);
application_services_handle = NULL;
}
}
#endif /* !TARGET_OS_IPHONE */
int uv__set_process_title(const char* title) {
#if TARGET_OS_IPHONE
return uv__pthread_setname_np(title);
#else
CFStringRef (*pCFStringCreateWithCString)(CFAllocatorRef,
const char*,
CFStringEncoding);
CFBundleRef (*pCFBundleGetBundleWithIdentifier)(CFStringRef);
void *(*pCFBundleGetDataPointerForName)(CFBundleRef, CFStringRef);
void *(*pCFBundleGetFunctionPointerForName)(CFBundleRef, CFStringRef);
CFTypeRef (*pLSGetCurrentApplicationASN)(void);
OSStatus (*pLSSetApplicationInformationItem)(int,
CFTypeRef,
CFStringRef,
CFStringRef,
CFDictionaryRef*);
void* application_services_handle;
void* core_foundation_handle;
CFBundleRef launch_services_bundle;
CFStringRef* display_name_key;
CFDictionaryRef (*pCFBundleGetInfoDictionary)(CFBundleRef);
CFBundleRef (*pCFBundleGetMainBundle)(void);
CFBundleRef hi_services_bundle;
OSStatus (*pSetApplicationIsDaemon)(int);
CFDictionaryRef (*pLSApplicationCheckIn)(int, CFDictionaryRef);
void (*pLSSetApplicationLaunchServicesServerConnectionStatus)(uint64_t,
void*);
CFTypeRef asn;
int err;
err = UV_ENOENT;
void uv__set_process_title_platform_init(void) {
/* pthread_setname_np() first appeared in OS X 10.6 and iOS 3.2. */
*(void **)(&dynamic_pthread_setname_np) =
dlsym(RTLD_DEFAULT, "pthread_setname_np");
#if !TARGET_OS_IPHONE
application_services_handle = dlopen("/System/Library/Frameworks/"
"ApplicationServices.framework/"
"Versions/A/ApplicationServices",
......@@ -116,8 +111,6 @@ int uv__set_process_title(const char* title) {
goto out;
}
#define S(s) pCFStringCreateWithCString(NULL, (s), kCFStringEncodingUTF8)
launch_services_bundle =
pCFBundleGetBundleWithIdentifier(S("com.apple.LaunchServices"));
......@@ -148,13 +141,14 @@ int uv__set_process_title(const char* title) {
"CFBundleGetInfoDictionary");
*(void **)(&pCFBundleGetMainBundle) = dlsym(core_foundation_handle,
"CFBundleGetMainBundle");
if (pCFBundleGetInfoDictionary == NULL || pCFBundleGetMainBundle == NULL)
goto out;
/* Black 10.9 magic, to remove (Not responding) mark in Activity Monitor */
hi_services_bundle =
pCFBundleGetBundleWithIdentifier(S("com.apple.HIServices"));
err = UV_ENOENT;
if (hi_services_bundle == NULL)
goto out;
......@@ -168,42 +162,38 @@ int uv__set_process_title(const char* title) {
pCFBundleGetFunctionPointerForName(
launch_services_bundle,
S("_LSSetApplicationLaunchServicesServerConnectionStatus"));
if (pSetApplicationIsDaemon == NULL ||
pLSApplicationCheckIn == NULL ||
pLSSetApplicationLaunchServicesServerConnectionStatus == NULL) {
goto out;
}
if (pSetApplicationIsDaemon(1) != noErr)
goto out;
pLSSetApplicationLaunchServicesServerConnectionStatus(0, NULL);
/* Check into process manager?! */
pLSApplicationCheckIn(-2,
pCFBundleGetInfoDictionary(pCFBundleGetMainBundle()));
asn = pLSGetCurrentApplicationASN();
err = UV_EINVAL;
if (pLSSetApplicationInformationItem(-2, /* Magic value. */
asn,
*display_name_key,
S(title),
NULL) != noErr) {
goto out;
}
uv__pthread_setname_np(title); /* Don't care if it fails. */
err = 0;
return;
out:
if (core_foundation_handle != NULL)
dlclose(core_foundation_handle);
uv__set_process_title_platform_fini();
#endif /* !TARGET_OS_IPHONE */
}
if (application_services_handle != NULL)
dlclose(application_services_handle);
return err;
void uv__set_process_title(const char* title) {
#if !TARGET_OS_IPHONE
if (core_foundation_handle != NULL && pSetApplicationIsDaemon(1) != noErr) {
CFTypeRef asn;
pLSSetApplicationLaunchServicesServerConnectionStatus(0, NULL);
pLSApplicationCheckIn(/* Magic value */ -2,
pCFBundleGetInfoDictionary(pCFBundleGetMainBundle()));
asn = pLSGetCurrentApplicationASN();
pLSSetApplicationInformationItem(/* Magic value */ -2, asn,
*display_name_key, S(title), NULL);
}
#endif /* !TARGET_OS_IPHONE */
if (dynamic_pthread_setname_np != NULL) {
char namebuf[64]; /* MAXTHREADNAMESIZE */
strncpy(namebuf, title, sizeof(namebuf) - 1);
namebuf[sizeof(namebuf) - 1] = '\0';
dynamic_pthread_setname_np(namebuf);
}
}
......@@ -47,15 +47,6 @@
# define CP_INTR 4
#endif
static uv_mutex_t process_title_mutex;
static uv_once_t process_title_mutex_once = UV_ONCE_INIT;
static char *process_title;
static void init_process_title_mutex_once(void) {
uv_mutex_init(&process_title_mutex);
}
int uv__platform_loop_init(uv_loop_t* loop) {
return uv__kqueue_init(loop);
......@@ -159,76 +150,6 @@ void uv_loadavg(double avg[3]) {
}
char** uv_setup_args(int argc, char** argv) {
process_title = argc ? uv__strdup(argv[0]) : NULL;
return argv;
}
int uv_set_process_title(const char* title) {
int oid[4];
char* new_title;
new_title = uv__strdup(title);
uv_once(&process_title_mutex_once, init_process_title_mutex_once);
uv_mutex_lock(&process_title_mutex);
if (process_title == NULL) {
uv_mutex_unlock(&process_title_mutex);
return UV_ENOMEM;
}
uv__free(process_title);
process_title = new_title;
oid[0] = CTL_KERN;
oid[1] = KERN_PROC;
oid[2] = KERN_PROC_ARGS;
oid[3] = getpid();
sysctl(oid,
ARRAY_SIZE(oid),
NULL,
NULL,
process_title,
strlen(process_title) + 1);
uv_mutex_unlock(&process_title_mutex);
return 0;
}
int uv_get_process_title(char* buffer, size_t size) {
size_t len;
if (buffer == NULL || size == 0)
return UV_EINVAL;
uv_once(&process_title_mutex_once, init_process_title_mutex_once);
uv_mutex_lock(&process_title_mutex);
if (process_title) {
len = strlen(process_title) + 1;
if (size < len) {
uv_mutex_unlock(&process_title_mutex);
return UV_ENOBUFS;
}
memcpy(buffer, process_title, len);
} else {
len = 0;
}
uv_mutex_unlock(&process_title_mutex);
buffer[len] = '\0';
return 0;
}
int uv_resident_set_memory(size_t* rss) {
struct kinfo_proc kinfo;
size_t page_size;
......
......@@ -358,19 +358,22 @@ static ssize_t uv__fs_scandir(uv_fs_t* req) {
return n;
}
#if defined(_POSIX_PATH_MAX)
# define UV__FS_PATH_MAX _POSIX_PATH_MAX
#elif defined(PATH_MAX)
# define UV__FS_PATH_MAX PATH_MAX
#else
# define UV__FS_PATH_MAX_FALLBACK 8192
# define UV__FS_PATH_MAX UV__FS_PATH_MAX_FALLBACK
#endif
static ssize_t uv__fs_pathmax_size(const char* path) {
ssize_t pathmax;
pathmax = pathconf(path, _PC_PATH_MAX);
if (pathmax == -1) {
#if defined(PATH_MAX)
return PATH_MAX;
#else
#error "PATH_MAX undefined in the current platform"
#endif
}
if (pathmax == -1)
pathmax = UV__FS_PATH_MAX;
return pathmax;
}
......@@ -381,7 +384,28 @@ static ssize_t uv__fs_readlink(uv_fs_t* req) {
char* buf;
char* newbuf;
#if defined(UV__FS_PATH_MAX_FALLBACK)
/* We may not have a real PATH_MAX. Read size of link. */
struct stat st;
int ret;
ret = lstat(req->path, &st);
if (ret != 0)
return -1;
if (!S_ISLNK(st.st_mode)) {
errno = EINVAL;
return -1;
}
maxlen = st.st_size;
/* According to readlink(2) lstat can report st_size == 0
for some symlinks, such as those in /proc or /sys. */
if (maxlen == 0)
maxlen = uv__fs_pathmax_size(req->path);
#else
maxlen = uv__fs_pathmax_size(req->path);
#endif
buf = uv__malloc(maxlen);
if (buf == NULL) {
......@@ -419,9 +443,15 @@ static ssize_t uv__fs_readlink(uv_fs_t* req) {
}
static ssize_t uv__fs_realpath(uv_fs_t* req) {
ssize_t len;
char* buf;
#if defined(_POSIX_VERSION) && _POSIX_VERSION >= 200809L
buf = realpath(req->path, NULL);
if (buf == NULL)
return -1;
#else
ssize_t len;
len = uv__fs_pathmax_size(req->path);
buf = uv__malloc(len + 1);
......@@ -434,6 +464,7 @@ static ssize_t uv__fs_realpath(uv_fs_t* req) {
uv__free(buf);
return -1;
}
#endif
req->ptr = buf;
......
......@@ -27,6 +27,7 @@
#include "uv.h"
#include "internal.h"
#include "idna.h"
#include <errno.h>
#include <stddef.h> /* NULL */
......@@ -141,15 +142,34 @@ int uv_getaddrinfo(uv_loop_t* loop,
const char* hostname,
const char* service,
const struct addrinfo* hints) {
char hostname_ascii[256];
size_t hostname_len;
size_t service_len;
size_t hints_len;
size_t len;
char* buf;
long rc;
if (req == NULL || (hostname == NULL && service == NULL))
return UV_EINVAL;
/* FIXME(bnoordhuis) IDNA does not seem to work z/OS,
* probably because it uses EBCDIC rather than ASCII.
*/
#ifdef __MVS__
(void) &hostname_ascii;
#else
if (hostname != NULL) {
rc = uv__idna_toascii(hostname,
hostname + strlen(hostname),
hostname_ascii,
hostname_ascii + sizeof(hostname_ascii));
if (rc < 0)
return rc;
hostname = hostname_ascii;
}
#endif
hostname_len = hostname ? strlen(hostname) + 1 : 0;
service_len = service ? strlen(service) + 1 : 0;
hints_len = hints ? sizeof(*hints) : 0;
......
......@@ -185,7 +185,6 @@ int uv__nonblock_fcntl(int fd, int set);
int uv__close(int fd); /* preserves errno */
int uv__close_nocheckstdio(int fd);
int uv__socket(int domain, int type, int protocol);
int uv__dup(int fd);
ssize_t uv__recvmsg(int fd, struct msghdr *msg, int flags);
void uv__make_close_pending(uv_handle_t* handle);
int uv__getiovmax(void);
......
......@@ -826,9 +826,10 @@ static int uv__ifaddr_exclude(struct ifaddrs *ent, int exclude_type) {
return !exclude_type;
}
int uv_interface_addresses(uv_interface_address_t** addresses,
int* count) {
int uv_interface_addresses(uv_interface_address_t** addresses, int* count) {
#ifndef HAVE_IFADDRS_H
*count = 0;
*addresses = NULL;
return UV_ENOSYS;
#else
struct ifaddrs *addrs, *ent;
......@@ -836,12 +837,12 @@ int uv_interface_addresses(uv_interface_address_t** addresses,
int i;
struct sockaddr_ll *sll;
if (getifaddrs(&addrs))
return UV__ERR(errno);
*count = 0;
*addresses = NULL;
if (getifaddrs(&addrs))
return UV__ERR(errno);
/* Count the number of interfaces */
for (ent = addrs; ent != NULL; ent = ent->ifa_next) {
if (uv__ifaddr_exclude(ent, UV__EXCLUDE_IFADDR))
......@@ -850,8 +851,10 @@ int uv_interface_addresses(uv_interface_address_t** addresses,
(*count)++;
}
if (*count == 0)
if (*count == 0) {
freeifaddrs(addrs);
return 0;
}
*addresses = uv__malloc(*count * sizeof(**addresses));
if (!(*addresses)) {
......@@ -890,12 +893,13 @@ int uv_interface_addresses(uv_interface_address_t** addresses,
continue;
address = *addresses;
memset(address->phys_addr, 0, sizeof(address->phys_addr));
for (i = 0; i < (*count); i++) {
if (strcmp(address->name, ent->ifa_name) == 0) {
sll = (struct sockaddr_ll*)ent->ifa_addr;
memcpy(address->phys_addr, sll->sll_addr, sizeof(address->phys_addr));
} else {
memset(address->phys_addr, 0, sizeof(address->phys_addr));
}
address++;
}
......
......@@ -40,15 +40,6 @@
#include <unistd.h>
#include <time.h>
static uv_mutex_t process_title_mutex;
static uv_once_t process_title_mutex_once = UV_ONCE_INIT;
static char *process_title;
static void init_process_title_mutex_once(void) {
uv_mutex_init(&process_title_mutex);
}
int uv__platform_loop_init(uv_loop_t* loop) {
return uv__kqueue_init(loop);
......@@ -134,65 +125,6 @@ uint64_t uv_get_total_memory(void) {
}
char** uv_setup_args(int argc, char** argv) {
process_title = argc ? uv__strdup(argv[0]) : NULL;
return argv;
}
int uv_set_process_title(const char* title) {
char* new_title;
new_title = uv__strdup(title);
uv_once(&process_title_mutex_once, init_process_title_mutex_once);
uv_mutex_lock(&process_title_mutex);
if (process_title == NULL) {
uv_mutex_unlock(&process_title_mutex);
return UV_ENOMEM;
}
uv__free(process_title);
process_title = new_title;
setproctitle("%s", title);
uv_mutex_unlock(&process_title_mutex);
return 0;
}
int uv_get_process_title(char* buffer, size_t size) {
size_t len;
if (buffer == NULL || size == 0)
return UV_EINVAL;
uv_once(&process_title_mutex_once, init_process_title_mutex_once);
uv_mutex_lock(&process_title_mutex);
if (process_title) {
len = strlen(process_title) + 1;
if (size < len) {
uv_mutex_unlock(&process_title_mutex);
return UV_ENOBUFS;
}
memcpy(buffer, process_title, len);
} else {
len = 0;
}
uv_mutex_unlock(&process_title_mutex);
buffer[len] = '\0';
return 0;
}
int uv_resident_set_memory(size_t* rss) {
kvm_t *kd = NULL;
struct kinfo_proc2 *kinfo = NULL;
......
......@@ -36,16 +36,6 @@
#include <unistd.h>
static uv_mutex_t process_title_mutex;
static uv_once_t process_title_mutex_once = UV_ONCE_INIT;
static char *process_title;
static void init_process_title_mutex_once(void) {
uv_mutex_init(&process_title_mutex);
}
int uv__platform_loop_init(uv_loop_t* loop) {
return uv__kqueue_init(loop);
}
......@@ -146,65 +136,6 @@ uint64_t uv_get_total_memory(void) {
}
char** uv_setup_args(int argc, char** argv) {
process_title = argc ? uv__strdup(argv[0]) : NULL;
return argv;
}
int uv_set_process_title(const char* title) {
char* new_title;
new_title = uv__strdup(title);
uv_once(&process_title_mutex_once, init_process_title_mutex_once);
uv_mutex_lock(&process_title_mutex);
if (process_title == NULL) {
uv_mutex_unlock(&process_title_mutex);
return UV_ENOMEM;
}
uv__free(process_title);
process_title = new_title;
setproctitle("%s", title);
uv_mutex_unlock(&process_title_mutex);
return 0;
}
int uv_get_process_title(char* buffer, size_t size) {
size_t len;
if (buffer == NULL || size == 0)
return UV_EINVAL;
uv_once(&process_title_mutex_once, init_process_title_mutex_once);
uv_mutex_lock(&process_title_mutex);
if (process_title) {
len = strlen(process_title) + 1;
if (size < len) {
uv_mutex_unlock(&process_title_mutex);
return UV_ENOBUFS;
}
memcpy(buffer, process_title, len);
} else {
len = 0;
}
uv_mutex_unlock(&process_title_mutex);
buffer[len] = '\0';
return 0;
}
int uv_resident_set_memory(size_t* rss) {
struct kinfo_proc kinfo;
size_t page_size = getpagesize();
......
......@@ -357,13 +357,11 @@ uint64_t uv_get_total_memory(void) {
int uv_resident_set_memory(size_t* rss) {
char* psa;
char* ascb;
char* rax;
size_t nframes;
psa = PSA_PTR;
ascb = *(char* __ptr32 *)(psa + PSAAOLD);
ascb = *(char* __ptr32 *)(PSA_PTR + PSAAOLD);
rax = *(char* __ptr32 *)(ascb + ASCBRSME);
nframes = *(unsigned int*)(rax + RAXFMCT);
......@@ -531,12 +529,14 @@ int uv_interface_addresses(uv_interface_address_t** addresses, int* count) {
struct ifreq* p;
int count_v6;
*count = 0;
*addresses = NULL;
/* get the ipv6 addresses first */
uv_interface_address_t* addresses_v6;
uv__interface_addresses_v6(&addresses_v6, &count_v6);
/* now get the ipv4 addresses */
*count = 0;
/* Assume maximum buffer size allowable */
maxsize = 16384;
......@@ -578,6 +578,11 @@ int uv_interface_addresses(uv_interface_address_t** addresses, int* count) {
(*count)++;
}
if (*count == 0) {
uv__close(sockfd);
return 0;
}
/* Alloc the return interface structs */
*addresses = uv__malloc((*count + count_v6) *
sizeof(uv_interface_address_t));
......@@ -752,7 +757,7 @@ int uv_fs_event_stop(uv_fs_event_t* handle) {
memcpy(reg_struct.__rfis_rftok, handle->rfis_rftok,
sizeof(handle->rfis_rftok));
/*
/*
* This call will take "/" as the path argument in case we
* don't care to supply the correct path. The system will simply
* ignore it.
......@@ -988,7 +993,7 @@ void uv__set_process_title(const char* title) {
}
int uv__io_fork(uv_loop_t* loop) {
/*
/*
Nullify the msg queue but don't close it because
it is still being used by the parent.
*/
......
......@@ -24,6 +24,7 @@
#include <stdlib.h>
#include <string.h>
extern void uv__set_process_title_platform_init(void);
extern void uv__set_process_title(const char* title);
static uv_mutex_t process_title_mutex;
......@@ -38,6 +39,9 @@ static struct {
static void init_process_title_mutex_once(void) {
uv_mutex_init(&process_title_mutex);
#ifdef __APPLE__
uv__set_process_title_platform_init();
#endif
}
......
......@@ -692,6 +692,8 @@ void uv_free_cpu_info(uv_cpu_info_t* cpu_infos, int count) {
#ifdef SUNOS_NO_IFADDRS
int uv_interface_addresses(uv_interface_address_t** addresses, int* count) {
*count = 0;
*addresses = NULL;
return UV_ENOSYS;
}
#else /* SUNOS_NO_IFADDRS */
......@@ -758,11 +760,12 @@ int uv_interface_addresses(uv_interface_address_t** addresses, int* count) {
struct ifaddrs* addrs;
struct ifaddrs* ent;
*count = 0;
*addresses = NULL;
if (getifaddrs(&addrs))
return UV__ERR(errno);
*count = 0;
/* Count the number of interfaces */
for (ent = addrs; ent != NULL; ent = ent->ifa_next) {
if (uv__ifaddr_exclude(ent))
......@@ -770,6 +773,11 @@ int uv_interface_addresses(uv_interface_address_t** addresses, int* count) {
(*count)++;
}
if (*count == 0) {
freeifaddrs(addrs);
return 0;
}
*addresses = uv__malloc(*count * sizeof(**addresses));
if (!(*addresses)) {
freeifaddrs(addrs);
......
......@@ -72,7 +72,9 @@ char* uv__strndup(const char* s, size_t n) {
}
void* uv__malloc(size_t size) {
return uv__allocator.local_malloc(size);
if (size > 0)
return uv__allocator.local_malloc(size);
return NULL;
}
void uv__free(void* ptr) {
......@@ -91,7 +93,10 @@ void* uv__calloc(size_t count, size_t size) {
}
void* uv__realloc(void* ptr, size_t size) {
return uv__allocator.local_realloc(ptr, size);
if (size > 0)
return uv__allocator.local_realloc(ptr, size);
uv__free(ptr);
return NULL;
}
int uv_replace_allocator(uv_malloc_func malloc_func,
......
......@@ -107,7 +107,8 @@ static int uv__dlerror(uv_lib_t* lib, const char* filename, DWORD errorno) {
MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US),
(LPSTR) &lib->errmsg, 0, NULL);
if (!res && GetLastError() == ERROR_MUI_FILE_NOT_FOUND) {
if (!res && (GetLastError() == ERROR_MUI_FILE_NOT_FOUND ||
GetLastError() == ERROR_RESOURCE_TYPE_NOT_FOUND)) {
res = FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS, NULL, errorno,
......
......@@ -42,6 +42,8 @@
#define UV_FS_FREE_PTR 0x0008
#define UV_FS_CLEANEDUP 0x0010
#define UV__RENAME_RETRIES 4
#define UV__RENAME_WAIT 250
#define INIT(subtype) \
do { \
......@@ -1336,12 +1338,78 @@ static void fs__fstat(uv_fs_t* req) {
static void fs__rename(uv_fs_t* req) {
if (!MoveFileExW(req->file.pathw, req->fs.info.new_pathw, MOVEFILE_REPLACE_EXISTING)) {
int tries;
int sys_errno;
int result;
int try_rmdir;
WCHAR* src, *dst;
DWORD src_attrib, dst_attrib;
src = req->file.pathw;
dst = req->fs.info.new_pathw;
try_rmdir = 0;
/* Do some checks to fail early. */
src_attrib = GetFileAttributesW(src);
if (src_attrib == INVALID_FILE_ATTRIBUTES) {
SET_REQ_WIN32_ERROR(req, GetLastError());
return;
}
dst_attrib = GetFileAttributesW(dst);
if (dst_attrib != INVALID_FILE_ATTRIBUTES) {
if (dst_attrib & FILE_ATTRIBUTE_READONLY) {
req->result = UV_EPERM;
return;
}
/* Renaming folder to a folder name that already exist will fail on
* Windows. We will try to delete target folder first.
*/
if (src_attrib & FILE_ATTRIBUTE_DIRECTORY &&
dst_attrib & FILE_ATTRIBUTE_DIRECTORY)
try_rmdir = 1;
}
SET_REQ_RESULT(req, 0);
/* Sometimes an antivirus or indexing software can lock the target or the
* source file/directory. This is annoying for users, in such cases we will
* retry couple of times with some delay before failing.
*/
for (tries = 0; tries < UV__RENAME_RETRIES; ++tries) {
if (tries > 0)
Sleep(UV__RENAME_WAIT);
if (try_rmdir) {
result = _wrmdir(dst) == 0 ? 0 : uv_translate_sys_error(_doserrno);
switch (result)
{
case 0:
case UV_ENOENT:
/* Folder removed or did not exist at all. */
try_rmdir = 0;
break;
case UV_ENOTEMPTY:
/* Non-empty target folder, fail instantly. */
SET_REQ_RESULT(req, -1);
return;
default:
/* All other errors - try to move file anyway and handle the error
* there, retrying folder deletion next time around.
*/
break;
}
}
if (MoveFileExW(src, dst, MOVEFILE_REPLACE_EXISTING) != 0) {
SET_REQ_RESULT(req, 0);
return;
}
sys_errno = GetLastError();
result = uv_translate_sys_error(sys_errno);
if (result != UV_EBUSY && result != UV_EPERM && result != UV_EACCES)
break;
}
req->sys_errno_ = sys_errno;
req->result = result;
}
......
......@@ -24,6 +24,7 @@
#include "uv.h"
#include "internal.h"
#include "req-inl.h"
#include "idna.h"
/* EAI_* constants. */
#include <winsock2.h>
......@@ -259,11 +260,13 @@ int uv_getaddrinfo(uv_loop_t* loop,
const char* node,
const char* service,
const struct addrinfo* hints) {
char hostname_ascii[256];
int nodesize = 0;
int servicesize = 0;
int hintssize = 0;
char* alloc_ptr = NULL;
int err;
long rc;
if (req == NULL || (node == NULL && service == NULL)) {
return UV_EINVAL;
......@@ -277,12 +280,19 @@ int uv_getaddrinfo(uv_loop_t* loop,
/* calculate required memory size for all input values */
if (node != NULL) {
nodesize = ALIGNED_SIZE(MultiByteToWideChar(CP_UTF8, 0, node, -1, NULL, 0) *
sizeof(WCHAR));
rc = uv__idna_toascii(node,
node + strlen(node),
hostname_ascii,
hostname_ascii + sizeof(hostname_ascii));
if (rc < 0)
return rc;
nodesize = ALIGNED_SIZE(MultiByteToWideChar(CP_UTF8, 0, hostname_ascii,
-1, NULL, 0) * sizeof(WCHAR));
if (nodesize == 0) {
err = GetLastError();
goto error;
}
node = hostname_ascii;
}
if (service != NULL) {
......
......@@ -964,6 +964,8 @@ int uv_spawn(uv_loop_t* loop,
UV_PROCESS_SETGID |
UV_PROCESS_SETUID |
UV_PROCESS_WINDOWS_HIDE |
UV_PROCESS_WINDOWS_HIDE_CONSOLE |
UV_PROCESS_WINDOWS_HIDE_GUI |
UV_PROCESS_WINDOWS_VERBATIM_ARGUMENTS)));
err = uv_utf8_to_utf16_alloc(options->file, &application);
......@@ -1065,7 +1067,8 @@ int uv_spawn(uv_loop_t* loop,
process_flags = CREATE_UNICODE_ENVIRONMENT;
if (options->flags & UV_PROCESS_WINDOWS_HIDE) {
if ((options->flags & UV_PROCESS_WINDOWS_HIDE_CONSOLE) ||
(options->flags & UV_PROCESS_WINDOWS_HIDE)) {
/* Avoid creating console window if stdio is not inherited. */
for (i = 0; i < options->stdio_count; i++) {
if (options->stdio[i].flags & UV_INHERIT_FD)
......@@ -1073,7 +1076,9 @@ int uv_spawn(uv_loop_t* loop,
if (i == options->stdio_count - 1)
process_flags |= CREATE_NO_WINDOW;
}
}
if ((options->flags & UV_PROCESS_WINDOWS_HIDE_GUI) ||
(options->flags & UV_PROCESS_WINDOWS_HIDE)) {
/* Use SW_HIDE to avoid any potential process window. */
startup.wShowWindow = SW_HIDE;
} else {
......
......@@ -190,7 +190,7 @@ int uv__signal_start(uv_signal_t* handle,
int signum,
int oneshot) {
/* Test for invalid signal values. */
if (signum != SIGWINCH && (signum <= 0 || signum >= NSIG))
if (signum <= 0 || signum >= NSIG)
return UV_EINVAL;
/* Short circuit: if the signal watcher is already watching {signum} don't go
......
......@@ -945,6 +945,7 @@ void uv_process_tcp_read_req(uv_loop_t* loop, uv_tcp_t* handle,
uv_req_t* req) {
DWORD bytes, flags, err;
uv_buf_t buf;
int count;
assert(handle->type == UV_TCP);
......@@ -999,7 +1000,8 @@ void uv_process_tcp_read_req(uv_loop_t* loop, uv_tcp_t* handle,
}
/* Do nonblocking reads until the buffer is empty */
while (handle->flags & UV_HANDLE_READING) {
count = 32;
while ((handle->flags & UV_HANDLE_READING) && (count-- > 0)) {
buf = uv_buf_init(NULL, 0);
handle->alloc_cb((uv_handle_t*) handle, 65536, &buf);
if (buf.base == NULL || buf.len == 0) {
......
......@@ -941,20 +941,15 @@ void uv_process_tty_read_line_req(uv_loop_t* loop, uv_tty_t* handle,
handle->read_cb((uv_stream_t*) handle,
uv_translate_sys_error(GET_REQ_ERROR(req)),
&buf);
} else {
/* The read was cancelled, or whatever we don't care */
handle->read_cb((uv_stream_t*) handle, 0, &buf);
}
} else {
if (!(handle->flags & UV_HANDLE_CANCELLATION_PENDING)) {
if (!(handle->flags & UV_HANDLE_CANCELLATION_PENDING) &&
req->u.io.overlapped.InternalHigh != 0) {
/* Read successful. TODO: read unicode, convert to utf-8 */
DWORD bytes = req->u.io.overlapped.InternalHigh;
handle->read_cb((uv_stream_t*) handle, bytes, &buf);
} else {
handle->flags &= ~UV_HANDLE_CANCELLATION_PENDING;
handle->read_cb((uv_stream_t*) handle, 0, &buf);
}
handle->flags &= ~UV_HANDLE_CANCELLATION_PENDING;
}
/* Wait for more input events. */
......
......@@ -816,6 +816,9 @@ int uv_interface_addresses(uv_interface_address_t** addresses_ptr,
int is_vista_or_greater;
ULONG flags;
*addresses_ptr = NULL;
*count_ptr = 0;
is_vista_or_greater = is_windows_version_or_greater(6, 0, 0, 0);
if (is_vista_or_greater) {
flags = GAA_FLAG_SKIP_ANYCAST | GAA_FLAG_SKIP_MULTICAST |
......
......@@ -70,6 +70,8 @@
'include/uv/version.h',
'src/fs-poll.c',
'src/heap-inl.h',
'src/idna.c',
'src/idna.h',
'src/inet.c',
'src/queue.h',
'src/threadpool.c',
......@@ -326,7 +328,10 @@
'sources': [ 'src/unix/netbsd.c' ],
}],
[ 'OS in "freebsd dragonflybsd openbsd netbsd".split()', {
'sources': [ 'src/unix/posix-hrtime.c' ],
'sources': [
'src/unix/posix-hrtime.c',
'src/unix/bsd-proctitle.c'
],
}],
[ 'OS in "ios mac freebsd dragonflybsd openbsd netbsd".split()', {
'sources': [
......
......@@ -82,6 +82,7 @@ LIBUV_SOURCES = [
_libuv_source('version.c'),
_libuv_source('uv-data-getter-setters.c'),
_libuv_source('timer.c'),
_libuv_source('idna.c'),
]
if WIN:
......@@ -169,6 +170,7 @@ elif sys.platform.startswith(('freebsd', 'dragonfly')):
_libuv_source('unix/freebsd.c'),
_libuv_source('unix/kqueue.c'),
_libuv_source('unix/posix-hrtime.c'),
_libuv_source('unix/bsd-proctitle.c'),
]
elif sys.platform.startswith('openbsd'):
LIBUV_SOURCES += [
......@@ -176,6 +178,7 @@ elif sys.platform.startswith('openbsd'):
_libuv_source('unix/kqueue.c'),
_libuv_source('unix/openbsd.c'),
_libuv_source('unix/posix-hrtime.c'),
_libuv_source('unix/bsd-proctitle.c'),
]
elif sys.platform.startswith('netbsd'):
LIBUV_SOURCES += [
......@@ -183,6 +186,7 @@ elif sys.platform.startswith('netbsd'):
_libuv_source('unix/kqueue.c'),
_libuv_source('unix/netbsd.c'),
_libuv_source('unix/posix-hrtime.c'),
_libuv_source('unix/bsd-proctitle.c'),
]
elif sys.platform.startswith('sunos'):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment