提交 af3edd14 authored 作者: Iñaki Baz Castillo's avatar Iñaki Baz Castillo

Update libuv to 1.24.0

上级 25901ad9
...@@ -351,3 +351,8 @@ Jeremiah Senkpiel <fishrock123@rocketmail.com> ...@@ -351,3 +351,8 @@ Jeremiah Senkpiel <fishrock123@rocketmail.com>
Andy Zhang <zhangyong232@gmail.com> Andy Zhang <zhangyong232@gmail.com>
dmabupt <dmabupt@gmail.com> dmabupt <dmabupt@gmail.com>
Ryan Liptak <squeek502@hotmail.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() ...@@ -13,6 +13,7 @@ endif()
set(uv_sources set(uv_sources
src/fs-poll.c src/fs-poll.c
src/idna.c
src/inet.c src/inet.c
src/threadpool.c src/threadpool.c
src/timer.c src/timer.c
...@@ -64,6 +65,7 @@ set(uv_test_sources ...@@ -64,6 +65,7 @@ set(uv_test_sources
test/test-homedir.c test/test-homedir.c
test/test-hrtime.c test/test-hrtime.c
test/test-idle.c test/test-idle.c
test/test-idna.c
test/test-ip4-addr.c test/test-ip4-addr.c
test/test-ip6-addr.c test/test-ip6-addr.c
test/test-ip6-addr.c test/test-ip6-addr.c
...@@ -193,7 +195,6 @@ if(WIN32) ...@@ -193,7 +195,6 @@ if(WIN32)
src/win/poll.c src/win/poll.c
src/win/process.c src/win/process.c
src/win/process-stdio.c src/win/process-stdio.c
src/win/req.c
src/win/signal.c src/win/signal.c
src/win/snprintf.c src/win/snprintf.c
src/win/stream.c src/win/stream.c
...@@ -261,7 +262,7 @@ if(CMAKE_SYSTEM_NAME MATCHES "DragonFly|FreeBSD") ...@@ -261,7 +262,7 @@ if(CMAKE_SYSTEM_NAME MATCHES "DragonFly|FreeBSD")
endif() endif()
if(CMAKE_SYSTEM_NAME MATCHES "DragonFly|FreeBSD|NetBSD|OpenBSD") 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) list(APPEND uv_libraries kvm)
endif() endif()
......
2018.09.22, Version 1.23.1 (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:
* unix: return 0 retrieving rss on cygwin (cjihrig)
* unix: initialize uv_interface_address_t.phys_addr (cjihrig)
* test: handle uv_os_setpriority() windows edge case (cjihrig)
* tty, win: fix read stop for raw mode (Bartosz Sosnowski)
* Revert "Revert "unix,fs: fix for potential partial reads/writes"" (Jameson
Nash)
* unix,readv: always permit partial reads to return (Jameson Nash)
* win,tty: fix uv_tty_close() (Bartosz Sosnowski)
* doc: remove extraneous "on" (Ben Noordhuis)
* unix,win: fix threadpool race condition (Anna Henningsen)
* unix: rework thread barrier implementation (Ben Noordhuis)
* aix: switch to libuv's own thread barrier impl (Ben Noordhuis)
* unix: signal done to last thread barrier waiter (Ben Noordhuis)
* test: add uv_barrier_wait serial thread test (Ali Ijaz Sheikh)
* unix: optimize uv_fs_readlink() memory allocation (Ben Noordhuis)
* win: remove req.c and other cleanup (Carlo Marcelo Arenas Belón)
* aix: don't EISDIR on read from directory fd (Ben Noordhuis)
2018.09.22, Version 1.23.1 (Stable), d2282b3d67821dc53c907c2155fa8c5c6ce25180
Changes since version 1.23.0: Changes since version 1.23.0:
......
...@@ -15,6 +15,7 @@ libuv is currently managed by the following individuals: ...@@ -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) - GPG key: AF2E EA41 EC34 47BF DD86 FED9 D706 3CCE 19B7 E890 (pubkey-indutny)
* **Imran Iqbal** ([@imran-iq](https://github.com/imran-iq)) * **Imran Iqbal** ([@imran-iq](https://github.com/imran-iq))
- GPG key: 9DFE AA5F 481B BF77 2D90 03CE D592 4925 2F8E C41A (pubkey-iwuzhere) - 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)) * **John Barboza** ([@jbarz](https://github.com/jbarz))
* **Santiago Gimeno** ([@santigimeno](https://github.com/santigimeno)) * **Santiago Gimeno** ([@santigimeno](https://github.com/santigimeno))
- GPG key: 612F 0EAD 9401 6223 79DF 4402 F28C 3C8D A33C 03BE (pubkey-santigimeno) - GPG key: 612F 0EAD 9401 6223 79DF 4402 F28C 3C8D A33C 03BE (pubkey-santigimeno)
......
...@@ -29,6 +29,7 @@ libuv_la_CFLAGS = @CFLAGS@ ...@@ -29,6 +29,7 @@ libuv_la_CFLAGS = @CFLAGS@
libuv_la_LDFLAGS = -no-undefined -version-info 1:0:0 libuv_la_LDFLAGS = -no-undefined -version-info 1:0:0
libuv_la_SOURCES = src/fs-poll.c \ libuv_la_SOURCES = src/fs-poll.c \
src/heap-inl.h \ src/heap-inl.h \
src/idna.c \
src/inet.c \ src/inet.c \
src/queue.h \ src/queue.h \
src/threadpool.c \ src/threadpool.c \
...@@ -68,7 +69,6 @@ libuv_la_SOURCES += src/win/async.c \ ...@@ -68,7 +69,6 @@ libuv_la_SOURCES += src/win/async.c \
src/win/poll.c \ src/win/poll.c \
src/win/process-stdio.c \ src/win/process-stdio.c \
src/win/process.c \ src/win/process.c \
src/win/req.c \
src/win/req-inl.h \ src/win/req-inl.h \
src/win/signal.c \ src/win/signal.c \
src/win/stream.c \ src/win/stream.c \
...@@ -190,6 +190,7 @@ test_run_tests_SOURCES = test/blackhole-server.c \ ...@@ -190,6 +190,7 @@ test_run_tests_SOURCES = test/blackhole-server.c \
test/test-homedir.c \ test/test-homedir.c \
test/test-hrtime.c \ test/test-hrtime.c \
test/test-idle.c \ test/test-idle.c \
test/test-idna.c \
test/test-ip4-addr.c \ test/test-ip4-addr.c \
test/test-ip6-addr.c \ test/test-ip6-addr.c \
test/test-ipc-heavy-traffic-deadlock-bug.c \ test/test-ipc-heavy-traffic-deadlock-bug.c \
...@@ -340,8 +341,7 @@ libuv_la_SOURCES += src/unix/aix.c src/unix/aix-common.c ...@@ -340,8 +341,7 @@ libuv_la_SOURCES += src/unix/aix.c src/unix/aix-common.c
endif endif
if ANDROID if ANDROID
uvinclude_HEADERS += include/uv/android-ifaddrs.h \ uvinclude_HEADERS += include/uv/android-ifaddrs.h
include/uv/pthread-barrier.h
libuv_la_SOURCES += src/unix/android-ifaddrs.c \ libuv_la_SOURCES += src/unix/android-ifaddrs.c \
src/unix/pthread-fixes.c src/unix/pthread-fixes.c
endif endif
...@@ -361,8 +361,7 @@ libuv_la_SOURCES += src/unix/cygwin.c \ ...@@ -361,8 +361,7 @@ libuv_la_SOURCES += src/unix/cygwin.c \
endif endif
if DARWIN if DARWIN
uvinclude_HEADERS += include/uv/darwin.h \ uvinclude_HEADERS += include/uv/darwin.h
include/uv/pthread-barrier.h
libuv_la_CFLAGS += -D_DARWIN_USE_64_BIT_INODE=1 libuv_la_CFLAGS += -D_DARWIN_USE_64_BIT_INODE=1
libuv_la_CFLAGS += -D_DARWIN_UNLIMITED_SELECT=1 libuv_la_CFLAGS += -D_DARWIN_UNLIMITED_SELECT=1
libuv_la_SOURCES += src/unix/bsd-ifaddrs.c \ libuv_la_SOURCES += src/unix/bsd-ifaddrs.c \
...@@ -377,6 +376,7 @@ endif ...@@ -377,6 +376,7 @@ endif
if DRAGONFLY if DRAGONFLY
uvinclude_HEADERS += include/uv/bsd.h uvinclude_HEADERS += include/uv/bsd.h
libuv_la_SOURCES += src/unix/bsd-ifaddrs.c \ libuv_la_SOURCES += src/unix/bsd-ifaddrs.c \
src/unix/bsd-proctitle.c \
src/unix/freebsd.c \ src/unix/freebsd.c \
src/unix/kqueue.c \ src/unix/kqueue.c \
src/unix/posix-hrtime.c src/unix/posix-hrtime.c
...@@ -386,12 +386,20 @@ endif ...@@ -386,12 +386,20 @@ endif
if FREEBSD if FREEBSD
uvinclude_HEADERS += include/uv/bsd.h uvinclude_HEADERS += include/uv/bsd.h
libuv_la_SOURCES += src/unix/bsd-ifaddrs.c \ libuv_la_SOURCES += src/unix/bsd-ifaddrs.c \
src/unix/bsd-proctitle.c \
src/unix/freebsd.c \ src/unix/freebsd.c \
src/unix/kqueue.c \ src/unix/kqueue.c \
src/unix/posix-hrtime.c src/unix/posix-hrtime.c
test_run_tests_LDFLAGS += -lutil test_run_tests_LDFLAGS += -lutil
endif 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 if LINUX
uvinclude_HEADERS += include/uv/linux.h uvinclude_HEADERS += include/uv/linux.h
libuv_la_CFLAGS += -D_GNU_SOURCE libuv_la_CFLAGS += -D_GNU_SOURCE
...@@ -422,6 +430,7 @@ endif ...@@ -422,6 +430,7 @@ endif
if NETBSD if NETBSD
uvinclude_HEADERS += include/uv/bsd.h uvinclude_HEADERS += include/uv/bsd.h
libuv_la_SOURCES += src/unix/bsd-ifaddrs.c \ libuv_la_SOURCES += src/unix/bsd-ifaddrs.c \
src/unix/bsd-proctitle.c \
src/unix/kqueue.c \ src/unix/kqueue.c \
src/unix/netbsd.c \ src/unix/netbsd.c \
src/unix/posix-hrtime.c src/unix/posix-hrtime.c
...@@ -431,6 +440,7 @@ endif ...@@ -431,6 +440,7 @@ endif
if OPENBSD if OPENBSD
uvinclude_HEADERS += include/uv/bsd.h uvinclude_HEADERS += include/uv/bsd.h
libuv_la_SOURCES += src/unix/bsd-ifaddrs.c \ libuv_la_SOURCES += src/unix/bsd-ifaddrs.c \
src/unix/bsd-proctitle.c \
src/unix/kqueue.c \ src/unix/kqueue.c \
src/unix/openbsd.c \ src/unix/openbsd.c \
src/unix/posix-hrtime.c src/unix/posix-hrtime.c
...@@ -445,7 +455,6 @@ libuv_la_SOURCES += src/unix/no-proctitle.c \ ...@@ -445,7 +455,6 @@ libuv_la_SOURCES += src/unix/no-proctitle.c \
endif endif
if OS390 if OS390
uvinclude_HEADERS += include/uv/pthread-barrier.h
libuv_la_CFLAGS += -D_UNIX03_THREADS \ libuv_la_CFLAGS += -D_UNIX03_THREADS \
-D_UNIX03_SOURCE \ -D_UNIX03_SOURCE \
-D_OPEN_SYS_IF_EXT=1 \ -D_OPEN_SYS_IF_EXT=1 \
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
AC_PREREQ(2.57) AC_PREREQ(2.57)
AC_INIT([libuv], [1.23.1], [https://github.com/libuv/libuv/issues]) AC_INIT([libuv], [1.24.0], [https://github.com/libuv/libuv/issues])
AC_CONFIG_MACRO_DIR([m4]) AC_CONFIG_MACRO_DIR([m4])
m4_include([m4/libuv-extra-automake-flags.m4]) m4_include([m4/libuv-extra-automake-flags.m4])
m4_include([m4/as_case.m4]) m4_include([m4/as_case.m4])
...@@ -56,6 +56,7 @@ AM_CONDITIONAL([CYGWIN], [AS_CASE([$host_os],[cygwin*], [true], [false]) ...@@ -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([DARWIN], [AS_CASE([$host_os],[darwin*], [true], [false])])
AM_CONDITIONAL([DRAGONFLY],[AS_CASE([$host_os],[dragonfly*], [true], [false])]) AM_CONDITIONAL([DRAGONFLY],[AS_CASE([$host_os],[dragonfly*], [true], [false])])
AM_CONDITIONAL([FREEBSD], [AS_CASE([$host_os],[*freebsd*], [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([LINUX], [AS_CASE([$host_os],[linux*], [true], [false])])
AM_CONDITIONAL([MSYS], [AS_CASE([$host_os],[msys*], [true], [false])]) AM_CONDITIONAL([MSYS], [AS_CASE([$host_os],[msys*], [true], [false])])
AM_CONDITIONAL([NETBSD], [AS_CASE([$host_os],[netbsd*], [true], [false])]) AM_CONDITIONAL([NETBSD], [AS_CASE([$host_os],[netbsd*], [true], [false])])
...@@ -67,6 +68,9 @@ AS_CASE([$host_os],[mingw*], [ ...@@ -67,6 +68,9 @@ AS_CASE([$host_os],[mingw*], [
LIBS="$LIBS -lws2_32 -lpsapi -liphlpapi -lshell32 -luserenv -luser32" LIBS="$LIBS -lws2_32 -lpsapi -liphlpapi -lshell32 -luserenv -luser32"
]) ])
AS_CASE([$host_os], [netbsd*], [AC_CHECK_LIB([kvm], [kvm_open])]) 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_CHECK_HEADERS([sys/ahafs_evProds.h])
AC_CONFIG_FILES([Makefile libuv.pc]) AC_CONFIG_FILES([Makefile libuv.pc])
AC_OUTPUT AC_OUTPUT
...@@ -126,7 +126,7 @@ so the current approach is to run blocking file I/O operations in a thread pool. ...@@ -126,7 +126,7 @@ so the current approach is to run blocking file I/O operations in a thread pool.
For a thorough explanation of the cross-platform file I/O landscape, checkout For a thorough explanation of the cross-platform file I/O landscape, checkout
`this post <http://blog.libtorrent.org/2012/10/asynchronous-disk-io/>`_. `this post <http://blog.libtorrent.org/2012/10/asynchronous-disk-io/>`_.
libuv currently uses a global thread pool on which all loops can queue work on. 3 types of libuv currently uses a global thread pool on which all loops can queue work. 3 types of
operations are currently run on this pool: operations are currently run on this pool:
* File system operations * File system operations
......
...@@ -12,6 +12,8 @@ otherwise it will be performed asynchronously. ...@@ -12,6 +12,8 @@ otherwise it will be performed asynchronously.
All file operations are run on the threadpool. See :ref:`threadpool` for information All file operations are run on the threadpool. See :ref:`threadpool` for information
on the threadpool size. on the threadpool size.
.. note::
On Windows `uv_fs_*` functions use utf-8 encoding.
Data types Data types
---------- ----------
...@@ -231,6 +233,15 @@ API ...@@ -231,6 +233,15 @@ API
Equivalent to :man:`rename(2)`. Equivalent to :man:`rename(2)`.
.. note::
On Windows if this function fails with ``UV_EBUSY``, ``UV_EPERM`` or
``UV_EACCES``, it will retry to rename the file up to four times with
250ms wait between attempts before giving up. If both `path` and
`new_path` are existing directories this function will work only if
target directory is empty.
.. versionchanged:: 1.24.0 Added retrying and directory move support on Windows.
.. c:function:: int uv_fs_fsync(uv_loop_t* loop, uv_fs_t* req, uv_file file, uv_fs_cb cb) .. c:function:: int uv_fs_fsync(uv_loop_t* loop, uv_fs_t* req, uv_file file, uv_fs_cb cb)
Equivalent to :man:`fsync(2)`. Equivalent to :man:`fsync(2)`.
......
...@@ -70,11 +70,22 @@ Data types ...@@ -70,11 +70,22 @@ Data types
*/ */
UV_PROCESS_DETACHED = (1 << 3), 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 * option is only meaningful on Windows systems. On Unix it is silently
* ignored. * ignored.
*/ */
UV_PROCESS_WINDOWS_HIDE = (1 << 4) UV_PROCESS_WINDOWS_HIDE_GUI = (1 << 6)
}; };
.. c:type:: uv_stdio_container_t .. c:type:: uv_stdio_container_t
...@@ -217,6 +228,9 @@ API ...@@ -217,6 +228,9 @@ API
setgid specified, or not having enough memory to allocate for the new setgid specified, or not having enough memory to allocate for the new
process. process.
.. versionchanged:: 1.24.0 Added `UV_PROCESS_WINDOWS_HIDE_CONSOLE` and
`UV_PROCESS_WINDOWS_HIDE_GUI` flags.
.. c:function:: int uv_process_kill(uv_process_t* handle, int signum) .. c:function:: int uv_process_kill(uv_process_t* handle, int signum)
Sends the specified signal to the given process handle. Check the documentation Sends the specified signal to the given process handle. Check the documentation
......
...@@ -963,11 +963,22 @@ enum uv_process_flags { ...@@ -963,11 +963,22 @@ enum uv_process_flags {
*/ */
UV_PROCESS_DETACHED = (1 << 3), 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 * option is only meaningful on Windows systems. On Unix it is silently
* ignored. * ignored.
*/ */
UV_PROCESS_WINDOWS_HIDE = (1 << 4) UV_PROCESS_WINDOWS_HIDE_GUI = (1 << 6)
}; };
/* /*
......
/*
Copyright (c) 2016, Kari Tristan Helgason <kthelgason@gmail.com>
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_PTHREAD_BARRIER_
#define _UV_PTHREAD_BARRIER_
#include <errno.h>
#include <pthread.h>
#if !defined(__MVS__)
#include <semaphore.h> /* sem_t */
#endif
#define PTHREAD_BARRIER_SERIAL_THREAD 0x12345
#define UV__PTHREAD_BARRIER_FALLBACK 1
/*
* To maintain ABI compatibility with
* libuv v1.x struct is padded according
* to target platform
*/
#if defined(__ANDROID__)
# define UV_BARRIER_STRUCT_PADDING \
sizeof(pthread_mutex_t) + \
sizeof(pthread_cond_t) + \
sizeof(unsigned int) - \
sizeof(void *)
#elif defined(__APPLE__)
# define UV_BARRIER_STRUCT_PADDING \
sizeof(pthread_mutex_t) + \
2 * sizeof(sem_t) + \
2 * sizeof(unsigned int) - \
sizeof(void *)
#else
# define UV_BARRIER_STRUCT_PADDING 0
#endif
typedef struct {
pthread_mutex_t mutex;
pthread_cond_t cond;
unsigned threshold;
unsigned in;
unsigned out;
} _uv_barrier;
typedef struct {
_uv_barrier* b;
char _pad[UV_BARRIER_STRUCT_PADDING];
} pthread_barrier_t;
int pthread_barrier_init(pthread_barrier_t* barrier,
const void* barrier_attr,
unsigned count);
int pthread_barrier_wait(pthread_barrier_t* barrier);
int pthread_barrier_destroy(pthread_barrier_t *barrier);
#endif /* _UV_PTHREAD_BARRIER_ */
...@@ -64,10 +64,8 @@ ...@@ -64,10 +64,8 @@
# include "uv/bsd.h" # include "uv/bsd.h"
#elif defined(__CYGWIN__) || defined(__MSYS__) #elif defined(__CYGWIN__) || defined(__MSYS__)
# include "uv/posix.h" # include "uv/posix.h"
#endif #elif defined(__GNU__)
# include "uv/posix.h"
#ifndef PTHREAD_BARRIER_SERIAL_THREAD
# include "uv/pthread-barrier.h"
#endif #endif
#ifndef NI_MAXHOST #ifndef NI_MAXHOST
...@@ -136,8 +134,28 @@ typedef pthread_rwlock_t uv_rwlock_t; ...@@ -136,8 +134,28 @@ typedef pthread_rwlock_t uv_rwlock_t;
typedef UV_PLATFORM_SEM_T uv_sem_t; typedef UV_PLATFORM_SEM_T uv_sem_t;
typedef pthread_cond_t uv_cond_t; typedef pthread_cond_t uv_cond_t;
typedef pthread_key_t uv_key_t; typedef pthread_key_t uv_key_t;
typedef pthread_barrier_t uv_barrier_t;
/* Note: guard clauses should match uv_barrier_init's in src/unix/thread.c. */
#if defined(_AIX) || !defined(PTHREAD_BARRIER_SERIAL_THREAD)
/* TODO(bnoordhuis) Merge into uv_barrier_t in v2. */
struct _uv_barrier {
uv_mutex_t mutex;
uv_cond_t cond;
unsigned threshold;
unsigned in;
unsigned out;
};
typedef struct {
struct _uv_barrier* b;
# if defined(PTHREAD_BARRIER_SERIAL_THREAD)
/* TODO(bnoordhuis) Remove padding in v2. */
char pad[sizeof(pthread_barrier_t) - sizeof(struct _uv_barrier*)];
# endif
} uv_barrier_t;
#else
typedef pthread_barrier_t uv_barrier_t;
#endif
/* Platform-specific definitions for uv_spawn support. */ /* Platform-specific definitions for uv_spawn support. */
typedef gid_t uv_gid_t; typedef gid_t uv_gid_t;
......
...@@ -31,8 +31,8 @@ ...@@ -31,8 +31,8 @@
*/ */
#define UV_VERSION_MAJOR 1 #define UV_VERSION_MAJOR 1
#define UV_VERSION_MINOR 23 #define UV_VERSION_MINOR 24
#define UV_VERSION_PATCH 1 #define UV_VERSION_PATCH 0
#define UV_VERSION_IS_RELEASE 1 #define UV_VERSION_IS_RELEASE 1
#define UV_VERSION_SUFFIX "" #define UV_VERSION_SUFFIX ""
......
...@@ -86,6 +86,14 @@ typedef struct pollfd { ...@@ -86,6 +86,14 @@ typedef struct pollfd {
#define SIGKILL 9 #define SIGKILL 9
#define SIGWINCH 28 #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 /* The CRT defines SIGABRT_COMPAT as 6, which equals SIGABRT on many unix-like
* platforms. However MinGW doesn't define it, so we do. */ * platforms. However MinGW doesn't define it, so we do. */
#ifndef SIGABRT_COMPAT #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_ */
...@@ -62,10 +62,10 @@ static void worker(void* arg) { ...@@ -62,10 +62,10 @@ static void worker(void* arg) {
uv_sem_post((uv_sem_t*) arg); uv_sem_post((uv_sem_t*) arg);
arg = NULL; arg = NULL;
uv_mutex_lock(&mutex);
for (;;) { for (;;) {
uv_mutex_lock(&mutex); /* `mutex` should always be locked at this point. */
wait_for_work:
/* Keep waiting while either no work is present or only slow I/O /* Keep waiting while either no work is present or only slow I/O
and we're at the threshold for that. */ and we're at the threshold for that. */
while (QUEUE_EMPTY(&wq) || while (QUEUE_EMPTY(&wq) ||
...@@ -93,13 +93,13 @@ static void worker(void* arg) { ...@@ -93,13 +93,13 @@ static void worker(void* arg) {
other work in the queue is done. */ other work in the queue is done. */
if (slow_io_work_running >= slow_work_thread_threshold()) { if (slow_io_work_running >= slow_work_thread_threshold()) {
QUEUE_INSERT_TAIL(&wq, q); QUEUE_INSERT_TAIL(&wq, q);
goto wait_for_work; continue;
} }
/* If we encountered a request to run slow I/O work but there is none /* If we encountered a request to run slow I/O work but there is none
to run, that means it's cancelled => Start over. */ to run, that means it's cancelled => Start over. */
if (QUEUE_EMPTY(&slow_io_pending_wq)) if (QUEUE_EMPTY(&slow_io_pending_wq))
goto wait_for_work; continue;
is_slow_work = 1; is_slow_work = 1;
slow_io_work_running++; slow_io_work_running++;
...@@ -122,13 +122,19 @@ static void worker(void* arg) { ...@@ -122,13 +122,19 @@ static void worker(void* arg) {
w->work(w); w->work(w);
uv_mutex_lock(&w->loop->wq_mutex); uv_mutex_lock(&w->loop->wq_mutex);
if (is_slow_work)
slow_io_work_running--;
w->work = NULL; /* Signal uv_cancel() that the work req is done w->work = NULL; /* Signal uv_cancel() that the work req is done
executing. */ executing. */
QUEUE_INSERT_TAIL(&w->loop->wq, &w->wq); QUEUE_INSERT_TAIL(&w->loop->wq, &w->wq);
uv_async_send(&w->loop->wq_async); uv_async_send(&w->loop->wq_async);
uv_mutex_unlock(&w->loop->wq_mutex); uv_mutex_unlock(&w->loop->wq_mutex);
/* Lock `mutex` since that is expected at the start of the next
* iteration. */
uv_mutex_lock(&mutex);
if (is_slow_work) {
/* `slow_io_work_running` is protected by `mutex`. */
slow_io_work_running--;
}
} }
} }
......
...@@ -166,8 +166,7 @@ void uv_free_cpu_info(uv_cpu_info_t* cpu_infos, int count) { ...@@ -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 uv_interface_addresses(uv_interface_address_t** addresses, int* count) {
int* count) {
uv_interface_address_t* address; uv_interface_address_t* address;
int sockfd, inet6, size = 1; int sockfd, inet6, size = 1;
struct ifconf ifc; struct ifconf ifc;
...@@ -175,6 +174,7 @@ int uv_interface_addresses(uv_interface_address_t** addresses, ...@@ -175,6 +174,7 @@ int uv_interface_addresses(uv_interface_address_t** addresses,
struct sockaddr_dl* sa_addr; struct sockaddr_dl* sa_addr;
*count = 0; *count = 0;
*addresses = NULL;
if (0 > (sockfd = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP))) { if (0 > (sockfd = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP))) {
return UV__ERR(errno); return UV__ERR(errno);
...@@ -217,6 +217,11 @@ int uv_interface_addresses(uv_interface_address_t** addresses, ...@@ -217,6 +217,11 @@ int uv_interface_addresses(uv_interface_address_t** addresses,
(*count)++; (*count)++;
} }
if (*count == 0) {
uv__close(sockfd);
return 0;
}
/* Alloc the return interface structs */ /* Alloc the return interface structs */
*addresses = uv__malloc(*count * sizeof(uv_interface_address_t)); *addresses = uv__malloc(*count * sizeof(uv_interface_address_t));
if (!(*addresses)) { if (!(*addresses)) {
...@@ -289,4 +294,4 @@ void uv_free_interface_addresses(uv_interface_address_t* addresses, ...@@ -289,4 +294,4 @@ void uv_free_interface_addresses(uv_interface_address_t* addresses,
} }
uv__free(addresses); uv__free(addresses);
} }
\ No newline at end of file
...@@ -886,16 +886,20 @@ int uv_set_process_title(const char* title) { ...@@ -886,16 +886,20 @@ int uv_set_process_title(const char* title) {
int uv_get_process_title(char* buffer, size_t size) { int uv_get_process_title(char* buffer, size_t size) {
size_t len; size_t len;
len = strlen(process_argv[0]);
if (buffer == NULL || size == 0) if (buffer == NULL || size == 0)
return UV_EINVAL; return UV_EINVAL;
else if (size <= len)
return UV_ENOBUFS;
uv_once(&process_title_mutex_once, init_process_title_mutex_once); uv_once(&process_title_mutex_once, init_process_title_mutex_once);
uv_mutex_lock(&process_title_mutex); 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); uv_mutex_unlock(&process_title_mutex);
......
...@@ -69,11 +69,12 @@ int uv_interface_addresses(uv_interface_address_t** addresses, int* count) { ...@@ -69,11 +69,12 @@ int uv_interface_addresses(uv_interface_address_t** addresses, int* count) {
uv_interface_address_t* address; uv_interface_address_t* address;
int i; int i;
*count = 0;
*addresses = NULL;
if (getifaddrs(&addrs) != 0) if (getifaddrs(&addrs) != 0)
return UV__ERR(errno); return UV__ERR(errno);
*count = 0;
/* Count the number of interfaces */ /* Count the number of interfaces */
for (ent = addrs; ent != NULL; ent = ent->ifa_next) { for (ent = addrs; ent != NULL; ent = ent->ifa_next) {
if (uv__ifaddr_exclude(ent, UV__EXCLUDE_IFADDR)) if (uv__ifaddr_exclude(ent, UV__EXCLUDE_IFADDR))
...@@ -81,6 +82,11 @@ int uv_interface_addresses(uv_interface_address_t** addresses, int* count) { ...@@ -81,6 +82,11 @@ int uv_interface_addresses(uv_interface_address_t** addresses, int* count) {
(*count)++; (*count)++;
} }
if (*count == 0) {
freeifaddrs(addrs);
return 0;
}
*addresses = uv__malloc(*count * sizeof(**addresses)); *addresses = uv__malloc(*count * sizeof(**addresses));
if (*addresses == NULL) { if (*addresses == NULL) {
...@@ -121,15 +127,17 @@ int uv_interface_addresses(uv_interface_address_t** addresses, int* count) { ...@@ -121,15 +127,17 @@ int uv_interface_addresses(uv_interface_address_t** addresses, int* count) {
address = *addresses; address = *addresses;
for (i = 0; i < *count; i++) { for (i = 0; i < *count; i++) {
if (strcmp(address->name, ent->ifa_name) == 0) {
#if defined(__CYGWIN__) || defined(__MSYS__) #if defined(__CYGWIN__) || defined(__MSYS__)
memset(address->phys_addr, 0, sizeof(address->phys_addr)); memset(address->phys_addr, 0, sizeof(address->phys_addr));
#else #else
if (strcmp(address->name, ent->ifa_name) == 0) {
struct sockaddr_dl* sa_addr; struct sockaddr_dl* sa_addr;
sa_addr = (struct sockaddr_dl*)(ent->ifa_addr); sa_addr = (struct sockaddr_dl*)(ent->ifa_addr);
memcpy(address->phys_addr, LLADDR(sa_addr), sizeof(address->phys_addr)); memcpy(address->phys_addr, LLADDR(sa_addr), sizeof(address->phys_addr));
#endif } else {
memset(address->phys_addr, 0, sizeof(address->phys_addr));
} }
#endif
address++; address++;
} }
} }
......
/* Copyright Joyent, Inc. and other Node contributors. All rights reserved. /* Copyright libuv project contributors. All rights reserved.
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to * of this software and associated documentation files (the "Software"), to
...@@ -19,7 +19,75 @@ ...@@ -19,7 +19,75 @@
* IN THE SOFTWARE. * IN THE SOFTWARE.
*/ */
#include <assert.h>
#include "uv.h" #include "uv.h"
#include "internal.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) { ...@@ -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) { ssize_t uv__recvmsg(int fd, struct msghdr* msg, int flags) {
struct cmsghdr* cmsg; struct cmsghdr* cmsg;
ssize_t rc; ssize_t rc;
......
...@@ -38,7 +38,7 @@ int uv_uptime(double* uptime) { ...@@ -38,7 +38,7 @@ int uv_uptime(double* uptime) {
int uv_resident_set_memory(size_t* rss) { int uv_resident_set_memory(size_t* rss) {
/* FIXME: read /proc/meminfo? */ /* FIXME: read /proc/meminfo? */
*rss = 0; *rss = 0;
return UV_ENOSYS; return 0;
} }
int uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) { int uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) {
......
...@@ -33,61 +33,56 @@ ...@@ -33,61 +33,56 @@
# include <ApplicationServices/ApplicationServices.h> # include <ApplicationServices/ApplicationServices.h>
#endif #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); static int (*dynamic_pthread_setname_np)(const char* name);
if (err) #if !TARGET_OS_IPHONE
return UV__ERR(err); 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) { void uv__set_process_title_platform_init(void) {
#if TARGET_OS_IPHONE /* pthread_setname_np() first appeared in OS X 10.6 and iOS 3.2. */
return uv__pthread_setname_np(title); *(void **)(&dynamic_pthread_setname_np) =
#else dlsym(RTLD_DEFAULT, "pthread_setname_np");
CFStringRef (*pCFStringCreateWithCString)(CFAllocatorRef,
const char*, #if !TARGET_OS_IPHONE
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;
application_services_handle = dlopen("/System/Library/Frameworks/" application_services_handle = dlopen("/System/Library/Frameworks/"
"ApplicationServices.framework/" "ApplicationServices.framework/"
"Versions/A/ApplicationServices", "Versions/A/ApplicationServices",
...@@ -116,8 +111,6 @@ int uv__set_process_title(const char* title) { ...@@ -116,8 +111,6 @@ int uv__set_process_title(const char* title) {
goto out; goto out;
} }
#define S(s) pCFStringCreateWithCString(NULL, (s), kCFStringEncodingUTF8)
launch_services_bundle = launch_services_bundle =
pCFBundleGetBundleWithIdentifier(S("com.apple.LaunchServices")); pCFBundleGetBundleWithIdentifier(S("com.apple.LaunchServices"));
...@@ -148,13 +141,14 @@ int uv__set_process_title(const char* title) { ...@@ -148,13 +141,14 @@ int uv__set_process_title(const char* title) {
"CFBundleGetInfoDictionary"); "CFBundleGetInfoDictionary");
*(void **)(&pCFBundleGetMainBundle) = dlsym(core_foundation_handle, *(void **)(&pCFBundleGetMainBundle) = dlsym(core_foundation_handle,
"CFBundleGetMainBundle"); "CFBundleGetMainBundle");
if (pCFBundleGetInfoDictionary == NULL || pCFBundleGetMainBundle == NULL) if (pCFBundleGetInfoDictionary == NULL || pCFBundleGetMainBundle == NULL)
goto out; goto out;
/* Black 10.9 magic, to remove (Not responding) mark in Activity Monitor */ /* Black 10.9 magic, to remove (Not responding) mark in Activity Monitor */
hi_services_bundle = hi_services_bundle =
pCFBundleGetBundleWithIdentifier(S("com.apple.HIServices")); pCFBundleGetBundleWithIdentifier(S("com.apple.HIServices"));
err = UV_ENOENT;
if (hi_services_bundle == NULL) if (hi_services_bundle == NULL)
goto out; goto out;
...@@ -168,42 +162,38 @@ int uv__set_process_title(const char* title) { ...@@ -168,42 +162,38 @@ int uv__set_process_title(const char* title) {
pCFBundleGetFunctionPointerForName( pCFBundleGetFunctionPointerForName(
launch_services_bundle, launch_services_bundle,
S("_LSSetApplicationLaunchServicesServerConnectionStatus")); S("_LSSetApplicationLaunchServicesServerConnectionStatus"));
if (pSetApplicationIsDaemon == NULL || if (pSetApplicationIsDaemon == NULL ||
pLSApplicationCheckIn == NULL || pLSApplicationCheckIn == NULL ||
pLSSetApplicationLaunchServicesServerConnectionStatus == NULL) { pLSSetApplicationLaunchServicesServerConnectionStatus == NULL) {
goto out; goto out;
} }
if (pSetApplicationIsDaemon(1) != noErr) return;
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;
out: out:
if (core_foundation_handle != NULL) uv__set_process_title_platform_fini();
dlclose(core_foundation_handle); #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 */ #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 @@ ...@@ -47,15 +47,6 @@
# define CP_INTR 4 # define CP_INTR 4
#endif #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) { int uv__platform_loop_init(uv_loop_t* loop) {
return uv__kqueue_init(loop); return uv__kqueue_init(loop);
...@@ -159,76 +150,6 @@ void uv_loadavg(double avg[3]) { ...@@ -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) { int uv_resident_set_memory(size_t* rss) {
struct kinfo_proc kinfo; struct kinfo_proc kinfo;
size_t page_size; size_t page_size;
......
...@@ -262,17 +262,13 @@ static ssize_t uv__fs_read(uv_fs_t* req) { ...@@ -262,17 +262,13 @@ static ssize_t uv__fs_read(uv_fs_t* req) {
#if defined(__linux__) #if defined(__linux__)
static int no_preadv; static int no_preadv;
#endif #endif
unsigned int iovmax;
ssize_t result; ssize_t result;
#if defined(_AIX) iovmax = uv__getiovmax();
struct stat buf; if (req->nbufs > iovmax)
if(fstat(req->file, &buf)) req->nbufs = iovmax;
return -1;
if(S_ISDIR(buf.st_mode)) {
errno = EISDIR;
return -1;
}
#endif /* defined(_AIX) */
if (req->off < 0) { if (req->off < 0) {
if (req->nbufs == 1) if (req->nbufs == 1)
result = read(req->file, req->bufs[0].base, req->bufs[0].len); result = read(req->file, req->bufs[0].base, req->bufs[0].len);
...@@ -291,25 +287,7 @@ static ssize_t uv__fs_read(uv_fs_t* req) { ...@@ -291,25 +287,7 @@ static ssize_t uv__fs_read(uv_fs_t* req) {
if (no_preadv) retry: if (no_preadv) retry:
# endif # endif
{ {
off_t nread; result = pread(req->file, req->bufs[0].base, req->bufs[0].len, req->off);
size_t index;
nread = 0;
index = 0;
result = 1;
do {
if (req->bufs[index].len > 0) {
result = pread(req->file,
req->bufs[index].base,
req->bufs[index].len,
req->off + nread);
if (result > 0)
nread += result;
}
index++;
} while (index < req->nbufs && result > 0);
if (nread > 0)
result = nread;
} }
# if defined(__linux__) # if defined(__linux__)
else { else {
...@@ -327,6 +305,13 @@ static ssize_t uv__fs_read(uv_fs_t* req) { ...@@ -327,6 +305,13 @@ static ssize_t uv__fs_read(uv_fs_t* req) {
} }
done: done:
/* Early cleanup of bufs allocation, since we're done with it. */
if (req->bufs != req->bufsml)
uv__free(req->bufs);
req->bufs = NULL;
req->nbufs = 0;
return result; return result;
} }
...@@ -373,29 +358,55 @@ static ssize_t uv__fs_scandir(uv_fs_t* req) { ...@@ -373,29 +358,55 @@ static ssize_t uv__fs_scandir(uv_fs_t* req) {
return n; 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) { static ssize_t uv__fs_pathmax_size(const char* path) {
ssize_t pathmax; ssize_t pathmax;
pathmax = pathconf(path, _PC_PATH_MAX); pathmax = pathconf(path, _PC_PATH_MAX);
if (pathmax == -1) { if (pathmax == -1)
#if defined(PATH_MAX) pathmax = UV__FS_PATH_MAX;
return PATH_MAX;
#else
#error "PATH_MAX undefined in the current platform"
#endif
}
return pathmax; return pathmax;
} }
static ssize_t uv__fs_readlink(uv_fs_t* req) { static ssize_t uv__fs_readlink(uv_fs_t* req) {
ssize_t maxlen;
ssize_t len; ssize_t len;
char* buf; char* buf;
char* newbuf;
len = uv__fs_pathmax_size(req->path); #if defined(UV__FS_PATH_MAX_FALLBACK)
buf = uv__malloc(len + 1); /* 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) { if (buf == NULL) {
errno = ENOMEM; errno = ENOMEM;
...@@ -403,17 +414,28 @@ static ssize_t uv__fs_readlink(uv_fs_t* req) { ...@@ -403,17 +414,28 @@ static ssize_t uv__fs_readlink(uv_fs_t* req) {
} }
#if defined(__MVS__) #if defined(__MVS__)
len = os390_readlink(req->path, buf, len); len = os390_readlink(req->path, buf, maxlen);
#else #else
len = readlink(req->path, buf, len); len = readlink(req->path, buf, maxlen);
#endif #endif
if (len == -1) { if (len == -1) {
uv__free(buf); uv__free(buf);
return -1; return -1;
} }
/* Uncommon case: resize to make room for the trailing nul byte. */
if (len == maxlen) {
newbuf = uv__realloc(buf, len + 1);
if (newbuf == NULL) {
uv__free(buf);
return -1;
}
buf = newbuf;
}
buf[len] = '\0'; buf[len] = '\0';
req->ptr = buf; req->ptr = buf;
...@@ -421,9 +443,15 @@ static ssize_t uv__fs_readlink(uv_fs_t* req) { ...@@ -421,9 +443,15 @@ static ssize_t uv__fs_readlink(uv_fs_t* req) {
} }
static ssize_t uv__fs_realpath(uv_fs_t* req) { static ssize_t uv__fs_realpath(uv_fs_t* req) {
ssize_t len;
char* buf; 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); len = uv__fs_pathmax_size(req->path);
buf = uv__malloc(len + 1); buf = uv__malloc(len + 1);
...@@ -436,6 +464,7 @@ static ssize_t uv__fs_realpath(uv_fs_t* req) { ...@@ -436,6 +464,7 @@ static ssize_t uv__fs_realpath(uv_fs_t* req) {
uv__free(buf); uv__free(buf);
return -1; return -1;
} }
#endif
req->ptr = buf; req->ptr = buf;
...@@ -735,25 +764,7 @@ static ssize_t uv__fs_write(uv_fs_t* req) { ...@@ -735,25 +764,7 @@ static ssize_t uv__fs_write(uv_fs_t* req) {
if (no_pwritev) retry: if (no_pwritev) retry:
# endif # endif
{ {
off_t written; r = pwrite(req->file, req->bufs[0].base, req->bufs[0].len, req->off);
size_t index;
written = 0;
index = 0;
r = 0;
do {
if (req->bufs[index].len > 0) {
r = pwrite(req->file,
req->bufs[index].base,
req->bufs[index].len,
req->off + written);
if (r > 0)
written += r;
}
index++;
} while (index < req->nbufs && r >= 0);
if (written > 0)
r = written;
} }
# if defined(__linux__) # if defined(__linux__)
else { else {
...@@ -1045,9 +1056,21 @@ static int uv__fs_fstat(int fd, uv_stat_t *buf) { ...@@ -1045,9 +1056,21 @@ static int uv__fs_fstat(int fd, uv_stat_t *buf) {
return ret; return ret;
} }
static size_t uv__fs_buf_offset(uv_buf_t* bufs, size_t size) {
size_t offset;
/* Figure out which bufs are done */
for (offset = 0; size > 0 && bufs[offset].len <= size; ++offset)
size -= bufs[offset].len;
typedef ssize_t (*uv__fs_buf_iter_processor)(uv_fs_t* req); /* Fix a partial read/write */
static ssize_t uv__fs_buf_iter(uv_fs_t* req, uv__fs_buf_iter_processor process) { if (size > 0) {
bufs[offset].base += size;
bufs[offset].len -= size;
}
return offset;
}
static ssize_t uv__fs_write_all(uv_fs_t* req) {
unsigned int iovmax; unsigned int iovmax;
unsigned int nbufs; unsigned int nbufs;
uv_buf_t* bufs; uv_buf_t* bufs;
...@@ -1064,7 +1087,10 @@ static ssize_t uv__fs_buf_iter(uv_fs_t* req, uv__fs_buf_iter_processor process) ...@@ -1064,7 +1087,10 @@ static ssize_t uv__fs_buf_iter(uv_fs_t* req, uv__fs_buf_iter_processor process)
if (req->nbufs > iovmax) if (req->nbufs > iovmax)
req->nbufs = iovmax; req->nbufs = iovmax;
result = process(req); do
result = uv__fs_write(req);
while (result < 0 && errno == EINTR);
if (result <= 0) { if (result <= 0) {
if (total == 0) if (total == 0)
total = result; total = result;
...@@ -1074,14 +1100,12 @@ static ssize_t uv__fs_buf_iter(uv_fs_t* req, uv__fs_buf_iter_processor process) ...@@ -1074,14 +1100,12 @@ static ssize_t uv__fs_buf_iter(uv_fs_t* req, uv__fs_buf_iter_processor process)
if (req->off >= 0) if (req->off >= 0)
req->off += result; req->off += result;
req->nbufs = uv__fs_buf_offset(req->bufs, result);
req->bufs += req->nbufs; req->bufs += req->nbufs;
nbufs -= req->nbufs; nbufs -= req->nbufs;
total += result; total += result;
} }
if (errno == EINTR && total == -1)
return total;
if (bufs != req->bufsml) if (bufs != req->bufsml)
uv__free(bufs); uv__free(bufs);
...@@ -1098,7 +1122,8 @@ static void uv__fs_work(struct uv__work* w) { ...@@ -1098,7 +1122,8 @@ static void uv__fs_work(struct uv__work* w) {
ssize_t r; ssize_t r;
req = container_of(w, uv_fs_t, work_req); req = container_of(w, uv_fs_t, work_req);
retry_on_eintr = !(req->fs_type == UV_FS_CLOSE); retry_on_eintr = !(req->fs_type == UV_FS_CLOSE ||
req->fs_type == UV_FS_READ);
do { do {
errno = 0; errno = 0;
...@@ -1127,7 +1152,7 @@ static void uv__fs_work(struct uv__work* w) { ...@@ -1127,7 +1152,7 @@ static void uv__fs_work(struct uv__work* w) {
X(MKDIR, mkdir(req->path, req->mode)); X(MKDIR, mkdir(req->path, req->mode));
X(MKDTEMP, uv__fs_mkdtemp(req)); X(MKDTEMP, uv__fs_mkdtemp(req));
X(OPEN, uv__fs_open(req)); X(OPEN, uv__fs_open(req));
X(READ, uv__fs_buf_iter(req, uv__fs_read)); X(READ, uv__fs_read(req));
X(SCANDIR, uv__fs_scandir(req)); X(SCANDIR, uv__fs_scandir(req));
X(READLINK, uv__fs_readlink(req)); X(READLINK, uv__fs_readlink(req));
X(REALPATH, uv__fs_realpath(req)); X(REALPATH, uv__fs_realpath(req));
...@@ -1138,7 +1163,7 @@ static void uv__fs_work(struct uv__work* w) { ...@@ -1138,7 +1163,7 @@ static void uv__fs_work(struct uv__work* w) {
X(SYMLINK, symlink(req->path, req->new_path)); X(SYMLINK, symlink(req->path, req->new_path));
X(UNLINK, unlink(req->path)); X(UNLINK, unlink(req->path));
X(UTIME, uv__fs_utime(req)); X(UTIME, uv__fs_utime(req));
X(WRITE, uv__fs_buf_iter(req, uv__fs_write)); X(WRITE, uv__fs_write_all(req));
default: abort(); default: abort();
} }
#undef X #undef X
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#include "uv.h" #include "uv.h"
#include "internal.h" #include "internal.h"
#include "idna.h"
#include <errno.h> #include <errno.h>
#include <stddef.h> /* NULL */ #include <stddef.h> /* NULL */
...@@ -141,15 +142,34 @@ int uv_getaddrinfo(uv_loop_t* loop, ...@@ -141,15 +142,34 @@ int uv_getaddrinfo(uv_loop_t* loop,
const char* hostname, const char* hostname,
const char* service, const char* service,
const struct addrinfo* hints) { const struct addrinfo* hints) {
char hostname_ascii[256];
size_t hostname_len; size_t hostname_len;
size_t service_len; size_t service_len;
size_t hints_len; size_t hints_len;
size_t len; size_t len;
char* buf; char* buf;
long rc;
if (req == NULL || (hostname == NULL && service == NULL)) if (req == NULL || (hostname == NULL && service == NULL))
return UV_EINVAL; 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; hostname_len = hostname ? strlen(hostname) + 1 : 0;
service_len = service ? strlen(service) + 1 : 0; service_len = service ? strlen(service) + 1 : 0;
hints_len = hints ? sizeof(*hints) : 0; hints_len = hints ? sizeof(*hints) : 0;
......
...@@ -185,7 +185,6 @@ int uv__nonblock_fcntl(int fd, int set); ...@@ -185,7 +185,6 @@ int uv__nonblock_fcntl(int fd, int set);
int uv__close(int fd); /* preserves errno */ int uv__close(int fd); /* preserves errno */
int uv__close_nocheckstdio(int fd); int uv__close_nocheckstdio(int fd);
int uv__socket(int domain, int type, int protocol); 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); ssize_t uv__recvmsg(int fd, struct msghdr *msg, int flags);
void uv__make_close_pending(uv_handle_t* handle); void uv__make_close_pending(uv_handle_t* handle);
int uv__getiovmax(void); int uv__getiovmax(void);
......
...@@ -826,9 +826,10 @@ static int uv__ifaddr_exclude(struct ifaddrs *ent, int exclude_type) { ...@@ -826,9 +826,10 @@ static int uv__ifaddr_exclude(struct ifaddrs *ent, int exclude_type) {
return !exclude_type; return !exclude_type;
} }
int uv_interface_addresses(uv_interface_address_t** addresses, int uv_interface_addresses(uv_interface_address_t** addresses, int* count) {
int* count) {
#ifndef HAVE_IFADDRS_H #ifndef HAVE_IFADDRS_H
*count = 0;
*addresses = NULL;
return UV_ENOSYS; return UV_ENOSYS;
#else #else
struct ifaddrs *addrs, *ent; struct ifaddrs *addrs, *ent;
...@@ -836,12 +837,12 @@ int uv_interface_addresses(uv_interface_address_t** addresses, ...@@ -836,12 +837,12 @@ int uv_interface_addresses(uv_interface_address_t** addresses,
int i; int i;
struct sockaddr_ll *sll; struct sockaddr_ll *sll;
if (getifaddrs(&addrs))
return UV__ERR(errno);
*count = 0; *count = 0;
*addresses = NULL; *addresses = NULL;
if (getifaddrs(&addrs))
return UV__ERR(errno);
/* Count the number of interfaces */ /* Count the number of interfaces */
for (ent = addrs; ent != NULL; ent = ent->ifa_next) { for (ent = addrs; ent != NULL; ent = ent->ifa_next) {
if (uv__ifaddr_exclude(ent, UV__EXCLUDE_IFADDR)) if (uv__ifaddr_exclude(ent, UV__EXCLUDE_IFADDR))
...@@ -850,8 +851,10 @@ int uv_interface_addresses(uv_interface_address_t** addresses, ...@@ -850,8 +851,10 @@ int uv_interface_addresses(uv_interface_address_t** addresses,
(*count)++; (*count)++;
} }
if (*count == 0) if (*count == 0) {
freeifaddrs(addrs);
return 0; return 0;
}
*addresses = uv__malloc(*count * sizeof(**addresses)); *addresses = uv__malloc(*count * sizeof(**addresses));
if (!(*addresses)) { if (!(*addresses)) {
...@@ -895,6 +898,8 @@ int uv_interface_addresses(uv_interface_address_t** addresses, ...@@ -895,6 +898,8 @@ int uv_interface_addresses(uv_interface_address_t** addresses,
if (strcmp(address->name, ent->ifa_name) == 0) { if (strcmp(address->name, ent->ifa_name) == 0) {
sll = (struct sockaddr_ll*)ent->ifa_addr; sll = (struct sockaddr_ll*)ent->ifa_addr;
memcpy(address->phys_addr, sll->sll_addr, sizeof(address->phys_addr)); memcpy(address->phys_addr, sll->sll_addr, sizeof(address->phys_addr));
} else {
memset(address->phys_addr, 0, sizeof(address->phys_addr));
} }
address++; address++;
} }
......
...@@ -40,15 +40,6 @@ ...@@ -40,15 +40,6 @@
#include <unistd.h> #include <unistd.h>
#include <time.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) { int uv__platform_loop_init(uv_loop_t* loop) {
return uv__kqueue_init(loop); return uv__kqueue_init(loop);
...@@ -134,65 +125,6 @@ uint64_t uv_get_total_memory(void) { ...@@ -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) { int uv_resident_set_memory(size_t* rss) {
kvm_t *kd = NULL; kvm_t *kd = NULL;
struct kinfo_proc2 *kinfo = NULL; struct kinfo_proc2 *kinfo = NULL;
......
...@@ -36,16 +36,6 @@ ...@@ -36,16 +36,6 @@
#include <unistd.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) {
uv_mutex_init(&process_title_mutex);
}
int uv__platform_loop_init(uv_loop_t* loop) { int uv__platform_loop_init(uv_loop_t* loop) {
return uv__kqueue_init(loop); return uv__kqueue_init(loop);
} }
...@@ -146,65 +136,6 @@ uint64_t uv_get_total_memory(void) { ...@@ -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) { int uv_resident_set_memory(size_t* rss) {
struct kinfo_proc kinfo; struct kinfo_proc kinfo;
size_t page_size = getpagesize(); size_t page_size = getpagesize();
......
...@@ -357,13 +357,11 @@ uint64_t uv_get_total_memory(void) { ...@@ -357,13 +357,11 @@ uint64_t uv_get_total_memory(void) {
int uv_resident_set_memory(size_t* rss) { int uv_resident_set_memory(size_t* rss) {
char* psa;
char* ascb; char* ascb;
char* rax; char* rax;
size_t nframes; size_t nframes;
psa = PSA_PTR; ascb = *(char* __ptr32 *)(PSA_PTR + PSAAOLD);
ascb = *(char* __ptr32 *)(psa + PSAAOLD);
rax = *(char* __ptr32 *)(ascb + ASCBRSME); rax = *(char* __ptr32 *)(ascb + ASCBRSME);
nframes = *(unsigned int*)(rax + RAXFMCT); nframes = *(unsigned int*)(rax + RAXFMCT);
...@@ -512,7 +510,7 @@ static int uv__interface_addresses_v6(uv_interface_address_t** addresses, ...@@ -512,7 +510,7 @@ static int uv__interface_addresses_v6(uv_interface_address_t** addresses,
/* TODO: Retrieve netmask using SIOCGIFNETMASK ioctl */ /* TODO: Retrieve netmask using SIOCGIFNETMASK ioctl */
address->is_internal = flg.__nif6e_flags & _NIF6E_FLAGS_LOOPBACK ? 1 : 0; address->is_internal = flg.__nif6e_flags & _NIF6E_FLAGS_LOOPBACK ? 1 : 0;
memset(address->phys_addr, 0, sizeof(address->phys_addr));
address++; address++;
} }
...@@ -531,12 +529,14 @@ int uv_interface_addresses(uv_interface_address_t** addresses, int* count) { ...@@ -531,12 +529,14 @@ int uv_interface_addresses(uv_interface_address_t** addresses, int* count) {
struct ifreq* p; struct ifreq* p;
int count_v6; int count_v6;
*count = 0;
*addresses = NULL;
/* get the ipv6 addresses first */ /* get the ipv6 addresses first */
uv_interface_address_t* addresses_v6; uv_interface_address_t* addresses_v6;
uv__interface_addresses_v6(&addresses_v6, &count_v6); uv__interface_addresses_v6(&addresses_v6, &count_v6);
/* now get the ipv4 addresses */ /* now get the ipv4 addresses */
*count = 0;
/* Assume maximum buffer size allowable */ /* Assume maximum buffer size allowable */
maxsize = 16384; maxsize = 16384;
...@@ -578,6 +578,11 @@ int uv_interface_addresses(uv_interface_address_t** addresses, int* count) { ...@@ -578,6 +578,11 @@ int uv_interface_addresses(uv_interface_address_t** addresses, int* count) {
(*count)++; (*count)++;
} }
if (*count == 0) {
uv__close(sockfd);
return 0;
}
/* Alloc the return interface structs */ /* Alloc the return interface structs */
*addresses = uv__malloc((*count + count_v6) * *addresses = uv__malloc((*count + count_v6) *
sizeof(uv_interface_address_t)); sizeof(uv_interface_address_t));
...@@ -624,6 +629,7 @@ int uv_interface_addresses(uv_interface_address_t** addresses, int* count) { ...@@ -624,6 +629,7 @@ int uv_interface_addresses(uv_interface_address_t** addresses, int* count) {
} }
address->is_internal = flg.ifr_flags & IFF_LOOPBACK ? 1 : 0; address->is_internal = flg.ifr_flags & IFF_LOOPBACK ? 1 : 0;
memset(address->phys_addr, 0, sizeof(address->phys_addr));
address++; address++;
} }
...@@ -751,7 +757,7 @@ int uv_fs_event_stop(uv_fs_event_t* handle) { ...@@ -751,7 +757,7 @@ int uv_fs_event_stop(uv_fs_event_t* handle) {
memcpy(reg_struct.__rfis_rftok, handle->rfis_rftok, memcpy(reg_struct.__rfis_rftok, handle->rfis_rftok,
sizeof(handle->rfis_rftok)); sizeof(handle->rfis_rftok));
/* /*
* This call will take "/" as the path argument in case we * This call will take "/" as the path argument in case we
* don't care to supply the correct path. The system will simply * don't care to supply the correct path. The system will simply
* ignore it. * ignore it.
...@@ -987,7 +993,7 @@ void uv__set_process_title(const char* title) { ...@@ -987,7 +993,7 @@ void uv__set_process_title(const char* title) {
} }
int uv__io_fork(uv_loop_t* loop) { int uv__io_fork(uv_loop_t* loop) {
/* /*
Nullify the msg queue but don't close it because Nullify the msg queue but don't close it because
it is still being used by the parent. it is still being used by the parent.
*/ */
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
extern void uv__set_process_title_platform_init(void);
extern void uv__set_process_title(const char* title); extern void uv__set_process_title(const char* title);
static uv_mutex_t process_title_mutex; static uv_mutex_t process_title_mutex;
...@@ -38,6 +39,9 @@ static struct { ...@@ -38,6 +39,9 @@ static struct {
static void init_process_title_mutex_once(void) { static void init_process_title_mutex_once(void) {
uv_mutex_init(&process_title_mutex); 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) { ...@@ -692,6 +692,8 @@ void uv_free_cpu_info(uv_cpu_info_t* cpu_infos, int count) {
#ifdef SUNOS_NO_IFADDRS #ifdef SUNOS_NO_IFADDRS
int uv_interface_addresses(uv_interface_address_t** addresses, int* count) { int uv_interface_addresses(uv_interface_address_t** addresses, int* count) {
*count = 0;
*addresses = NULL;
return UV_ENOSYS; return UV_ENOSYS;
} }
#else /* SUNOS_NO_IFADDRS */ #else /* SUNOS_NO_IFADDRS */
...@@ -758,11 +760,12 @@ int uv_interface_addresses(uv_interface_address_t** addresses, int* count) { ...@@ -758,11 +760,12 @@ int uv_interface_addresses(uv_interface_address_t** addresses, int* count) {
struct ifaddrs* addrs; struct ifaddrs* addrs;
struct ifaddrs* ent; struct ifaddrs* ent;
*count = 0;
*addresses = NULL;
if (getifaddrs(&addrs)) if (getifaddrs(&addrs))
return UV__ERR(errno); return UV__ERR(errno);
*count = 0;
/* Count the number of interfaces */ /* Count the number of interfaces */
for (ent = addrs; ent != NULL; ent = ent->ifa_next) { for (ent = addrs; ent != NULL; ent = ent->ifa_next) {
if (uv__ifaddr_exclude(ent)) if (uv__ifaddr_exclude(ent))
...@@ -770,6 +773,11 @@ int uv_interface_addresses(uv_interface_address_t** addresses, int* count) { ...@@ -770,6 +773,11 @@ int uv_interface_addresses(uv_interface_address_t** addresses, int* count) {
(*count)++; (*count)++;
} }
if (*count == 0) {
freeifaddrs(addrs);
return 0;
}
*addresses = uv__malloc(*count * sizeof(**addresses)); *addresses = uv__malloc(*count * sizeof(**addresses));
if (!(*addresses)) { if (!(*addresses)) {
freeifaddrs(addrs); freeifaddrs(addrs);
......
...@@ -44,108 +44,119 @@ ...@@ -44,108 +44,119 @@
#undef NANOSEC #undef NANOSEC
#define NANOSEC ((uint64_t) 1e9) #define NANOSEC ((uint64_t) 1e9)
#if defined(PTHREAD_BARRIER_SERIAL_THREAD)
STATIC_ASSERT(sizeof(uv_barrier_t) == sizeof(pthread_barrier_t));
#endif
#if defined(UV__PTHREAD_BARRIER_FALLBACK) /* Note: guard clauses should match uv_barrier_t's in include/uv/uv-unix.h. */
/* TODO: support barrier_attr */ #if defined(_AIX) || !defined(PTHREAD_BARRIER_SERIAL_THREAD)
int pthread_barrier_init(pthread_barrier_t* barrier, int uv_barrier_init(uv_barrier_t* barrier, unsigned int count) {
const void* barrier_attr, struct _uv_barrier* b;
unsigned count) {
int rc; int rc;
_uv_barrier* b;
if (barrier == NULL || count == 0) if (barrier == NULL || count == 0)
return EINVAL; return UV_EINVAL;
if (barrier_attr != NULL)
return ENOTSUP;
b = uv__malloc(sizeof(*b)); b = uv__malloc(sizeof(*b));
if (b == NULL) if (b == NULL)
return ENOMEM; return UV_ENOMEM;
b->in = 0; b->in = 0;
b->out = 0; b->out = 0;
b->threshold = count; b->threshold = count;
if ((rc = pthread_mutex_init(&b->mutex, NULL)) != 0) rc = uv_mutex_init(&b->mutex);
if (rc != 0)
goto error2; goto error2;
if ((rc = pthread_cond_init(&b->cond, NULL)) != 0)
rc = uv_cond_init(&b->cond);
if (rc != 0)
goto error; goto error;
barrier->b = b; barrier->b = b;
return 0; return 0;
error: error:
pthread_mutex_destroy(&b->mutex); uv_mutex_destroy(&b->mutex);
error2: error2:
uv__free(b); uv__free(b);
return rc; return rc;
} }
int pthread_barrier_wait(pthread_barrier_t* barrier) {
int rc; int uv_barrier_wait(uv_barrier_t* barrier) {
_uv_barrier* b; struct _uv_barrier* b;
int last;
if (barrier == NULL || barrier->b == NULL) if (barrier == NULL || barrier->b == NULL)
return EINVAL; return UV_EINVAL;
b = barrier->b; b = barrier->b;
/* Lock the mutex*/ uv_mutex_lock(&b->mutex);
if ((rc = pthread_mutex_lock(&b->mutex)) != 0)
return rc;
/* Increment the count. If this is the first thread to reach the threshold,
wake up waiters, unlock the mutex, then return
PTHREAD_BARRIER_SERIAL_THREAD. */
if (++b->in == b->threshold) { if (++b->in == b->threshold) {
b->in = 0; b->in = 0;
b->out = b->threshold - 1; b->out = b->threshold;
rc = pthread_cond_signal(&b->cond); uv_cond_signal(&b->cond);
assert(rc == 0); } else {
do
pthread_mutex_unlock(&b->mutex); uv_cond_wait(&b->cond, &b->mutex);
return PTHREAD_BARRIER_SERIAL_THREAD; while (b->in != 0);
} }
/* Otherwise, wait for other threads until in is set to 0,
then return 0 to indicate this is not the first thread. */ last = (--b->out == 0);
do { if (!last)
if ((rc = pthread_cond_wait(&b->cond, &b->mutex)) != 0) uv_cond_signal(&b->cond); /* Not needed for last thread. */
break;
} while (b->in != 0); uv_mutex_unlock(&b->mutex);
return last;
/* mark thread exit */
b->out--;
pthread_cond_signal(&b->cond);
pthread_mutex_unlock(&b->mutex);
return rc;
} }
int pthread_barrier_destroy(pthread_barrier_t* barrier) {
int rc;
_uv_barrier* b;
if (barrier == NULL || barrier->b == NULL) void uv_barrier_destroy(uv_barrier_t* barrier) {
return EINVAL; struct _uv_barrier* b;
b = barrier->b; b = barrier->b;
uv_mutex_lock(&b->mutex);
if ((rc = pthread_mutex_lock(&b->mutex)) != 0) assert(b->in == 0);
return rc; assert(b->out == 0);
if (b->in > 0 || b->out > 0) if (b->in != 0 || b->out != 0)
rc = EBUSY; abort();
pthread_mutex_unlock(&b->mutex);
if (rc) uv_mutex_unlock(&b->mutex);
return rc; uv_mutex_destroy(&b->mutex);
uv_cond_destroy(&b->cond);
pthread_cond_destroy(&b->cond);
pthread_mutex_destroy(&b->mutex);
uv__free(barrier->b); uv__free(barrier->b);
barrier->b = NULL; barrier->b = NULL;
return 0;
} }
#else
int uv_barrier_init(uv_barrier_t* barrier, unsigned int count) {
return UV__ERR(pthread_barrier_init(barrier, NULL, count));
}
int uv_barrier_wait(uv_barrier_t* barrier) {
int rc;
rc = pthread_barrier_wait(barrier);
if (rc != 0)
if (rc != PTHREAD_BARRIER_SERIAL_THREAD)
abort();
return rc == PTHREAD_BARRIER_SERIAL_THREAD;
}
void uv_barrier_destroy(uv_barrier_t* barrier) {
if (pthread_barrier_destroy(barrier))
abort();
}
#endif #endif
...@@ -771,25 +782,6 @@ int uv_cond_timedwait(uv_cond_t* cond, uv_mutex_t* mutex, uint64_t timeout) { ...@@ -771,25 +782,6 @@ int uv_cond_timedwait(uv_cond_t* cond, uv_mutex_t* mutex, uint64_t timeout) {
} }
int uv_barrier_init(uv_barrier_t* barrier, unsigned int count) {
return UV__ERR(pthread_barrier_init(barrier, NULL, count));
}
void uv_barrier_destroy(uv_barrier_t* barrier) {
if (pthread_barrier_destroy(barrier))
abort();
}
int uv_barrier_wait(uv_barrier_t* barrier) {
int r = pthread_barrier_wait(barrier);
if (r && r != PTHREAD_BARRIER_SERIAL_THREAD)
abort();
return r == PTHREAD_BARRIER_SERIAL_THREAD;
}
int uv_key_create(uv_key_t* key) { int uv_key_create(uv_key_t* key) {
return UV__ERR(pthread_key_create(key, NULL)); return UV__ERR(pthread_key_create(key, NULL));
} }
......
...@@ -72,7 +72,9 @@ char* uv__strndup(const char* s, size_t n) { ...@@ -72,7 +72,9 @@ char* uv__strndup(const char* s, size_t n) {
} }
void* uv__malloc(size_t size) { 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) { void uv__free(void* ptr) {
...@@ -91,7 +93,10 @@ void* uv__calloc(size_t count, size_t size) { ...@@ -91,7 +93,10 @@ void* uv__calloc(size_t count, size_t size) {
} }
void* uv__realloc(void* ptr, 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, 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) { ...@@ -107,7 +107,8 @@ static int uv__dlerror(uv_lib_t* lib, const char* filename, DWORD errorno) {
MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US),
(LPSTR) &lib->errmsg, 0, NULL); (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 | res = FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS, NULL, errorno, FORMAT_MESSAGE_IGNORE_INSERTS, NULL, errorno,
......
...@@ -83,7 +83,7 @@ static void uv_relative_path(const WCHAR* filename, ...@@ -83,7 +83,7 @@ static void uv_relative_path(const WCHAR* filename,
static int uv_split_path(const WCHAR* filename, WCHAR** dir, static int uv_split_path(const WCHAR* filename, WCHAR** dir,
WCHAR** file) { WCHAR** file) {
size_t len, i; size_t len, i;
if (filename == NULL) { if (filename == NULL) {
if (dir != NULL) if (dir != NULL)
*dir = NULL; *dir = NULL;
......
...@@ -42,6 +42,8 @@ ...@@ -42,6 +42,8 @@
#define UV_FS_FREE_PTR 0x0008 #define UV_FS_FREE_PTR 0x0008
#define UV_FS_CLEANEDUP 0x0010 #define UV_FS_CLEANEDUP 0x0010
#define UV__RENAME_RETRIES 4
#define UV__RENAME_WAIT 250
#define INIT(subtype) \ #define INIT(subtype) \
do { \ do { \
...@@ -1329,12 +1331,78 @@ static void fs__fstat(uv_fs_t* req) { ...@@ -1329,12 +1331,78 @@ static void fs__fstat(uv_fs_t* req) {
static void fs__rename(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()); SET_REQ_WIN32_ERROR(req, GetLastError());
return; 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;
} }
...@@ -1517,10 +1585,10 @@ static void fs__fchmod(uv_fs_t* req) { ...@@ -1517,10 +1585,10 @@ static void fs__fchmod(uv_fs_t* req) {
SET_REQ_WIN32_ERROR(req, pRtlNtStatusToDosError(nt_status)); SET_REQ_WIN32_ERROR(req, pRtlNtStatusToDosError(nt_status));
goto fchmod_cleanup; goto fchmod_cleanup;
} }
/* Test if the Archive attribute is cleared */ /* Test if the Archive attribute is cleared */
if ((file_info.FileAttributes & FILE_ATTRIBUTE_ARCHIVE) == 0) { if ((file_info.FileAttributes & FILE_ATTRIBUTE_ARCHIVE) == 0) {
/* Set Archive flag, otherwise setting or clearing the read-only /* Set Archive flag, otherwise setting or clearing the read-only
flag will not work */ flag will not work */
file_info.FileAttributes |= FILE_ATTRIBUTE_ARCHIVE; file_info.FileAttributes |= FILE_ATTRIBUTE_ARCHIVE;
nt_status = pNtSetInformationFile(handle, nt_status = pNtSetInformationFile(handle,
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include "uv.h" #include "uv.h"
#include "internal.h" #include "internal.h"
#include "req-inl.h" #include "req-inl.h"
#include "idna.h"
/* EAI_* constants. */ /* EAI_* constants. */
#include <winsock2.h> #include <winsock2.h>
...@@ -259,11 +260,13 @@ int uv_getaddrinfo(uv_loop_t* loop, ...@@ -259,11 +260,13 @@ int uv_getaddrinfo(uv_loop_t* loop,
const char* node, const char* node,
const char* service, const char* service,
const struct addrinfo* hints) { const struct addrinfo* hints) {
char hostname_ascii[256];
int nodesize = 0; int nodesize = 0;
int servicesize = 0; int servicesize = 0;
int hintssize = 0; int hintssize = 0;
char* alloc_ptr = NULL; char* alloc_ptr = NULL;
int err; int err;
long rc;
if (req == NULL || (node == NULL && service == NULL)) { if (req == NULL || (node == NULL && service == NULL)) {
return UV_EINVAL; return UV_EINVAL;
...@@ -277,12 +280,19 @@ int uv_getaddrinfo(uv_loop_t* loop, ...@@ -277,12 +280,19 @@ int uv_getaddrinfo(uv_loop_t* loop,
/* calculate required memory size for all input values */ /* calculate required memory size for all input values */
if (node != NULL) { if (node != NULL) {
nodesize = ALIGNED_SIZE(MultiByteToWideChar(CP_UTF8, 0, node, -1, NULL, 0) * rc = uv__idna_toascii(node,
sizeof(WCHAR)); 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) { if (nodesize == 0) {
err = GetLastError(); err = GetLastError();
goto error; goto error;
} }
node = hostname_ascii;
} }
if (service != NULL) { if (service != NULL) {
......
...@@ -2347,7 +2347,7 @@ int uv_pipe_chmod(uv_pipe_t* handle, int mode) { ...@@ -2347,7 +2347,7 @@ int uv_pipe_chmod(uv_pipe_t* handle, int mode) {
error = GetLastError(); error = GetLastError();
goto clean_sid; goto clean_sid;
} }
memset(&ea, 0, sizeof(EXPLICIT_ACCESS)); memset(&ea, 0, sizeof(EXPLICIT_ACCESS));
if (mode & UV_READABLE) if (mode & UV_READABLE)
ea.grfAccessPermissions |= GENERIC_READ | FILE_WRITE_ATTRIBUTES; ea.grfAccessPermissions |= GENERIC_READ | FILE_WRITE_ATTRIBUTES;
......
...@@ -964,6 +964,8 @@ int uv_spawn(uv_loop_t* loop, ...@@ -964,6 +964,8 @@ int uv_spawn(uv_loop_t* loop,
UV_PROCESS_SETGID | UV_PROCESS_SETGID |
UV_PROCESS_SETUID | UV_PROCESS_SETUID |
UV_PROCESS_WINDOWS_HIDE | UV_PROCESS_WINDOWS_HIDE |
UV_PROCESS_WINDOWS_HIDE_CONSOLE |
UV_PROCESS_WINDOWS_HIDE_GUI |
UV_PROCESS_WINDOWS_VERBATIM_ARGUMENTS))); UV_PROCESS_WINDOWS_VERBATIM_ARGUMENTS)));
err = uv_utf8_to_utf16_alloc(options->file, &application); err = uv_utf8_to_utf16_alloc(options->file, &application);
...@@ -1065,7 +1067,8 @@ int uv_spawn(uv_loop_t* loop, ...@@ -1065,7 +1067,8 @@ int uv_spawn(uv_loop_t* loop,
process_flags = CREATE_UNICODE_ENVIRONMENT; 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. */ /* Avoid creating console window if stdio is not inherited. */
for (i = 0; i < options->stdio_count; i++) { for (i = 0; i < options->stdio_count; i++) {
if (options->stdio[i].flags & UV_INHERIT_FD) if (options->stdio[i].flags & UV_INHERIT_FD)
...@@ -1073,7 +1076,9 @@ int uv_spawn(uv_loop_t* loop, ...@@ -1073,7 +1076,9 @@ int uv_spawn(uv_loop_t* loop,
if (i == options->stdio_count - 1) if (i == options->stdio_count - 1)
process_flags |= CREATE_NO_WINDOW; 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. */ /* Use SW_HIDE to avoid any potential process window. */
startup.wShowWindow = SW_HIDE; startup.wShowWindow = SW_HIDE;
} else { } else {
......
...@@ -190,7 +190,7 @@ int uv__signal_start(uv_signal_t* handle, ...@@ -190,7 +190,7 @@ int uv__signal_start(uv_signal_t* handle,
int signum, int signum,
int oneshot) { int oneshot) {
/* Test for invalid signal values. */ /* Test for invalid signal values. */
if (signum != SIGWINCH && (signum <= 0 || signum >= NSIG)) if (signum <= 0 || signum >= NSIG)
return UV_EINVAL; return UV_EINVAL;
/* Short circuit: if the signal watcher is already watching {signum} don't go /* 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, ...@@ -945,6 +945,7 @@ void uv_process_tcp_read_req(uv_loop_t* loop, uv_tcp_t* handle,
uv_req_t* req) { uv_req_t* req) {
DWORD bytes, flags, err; DWORD bytes, flags, err;
uv_buf_t buf; uv_buf_t buf;
int count;
assert(handle->type == UV_TCP); assert(handle->type == UV_TCP);
...@@ -999,7 +1000,8 @@ void uv_process_tcp_read_req(uv_loop_t* loop, uv_tcp_t* handle, ...@@ -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 */ /* 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); buf = uv_buf_init(NULL, 0);
handle->alloc_cb((uv_handle_t*) handle, 65536, &buf); handle->alloc_cb((uv_handle_t*) handle, 65536, &buf);
if (buf.base == NULL || buf.len == 0) { if (buf.base == NULL || buf.len == 0) {
......
...@@ -118,7 +118,7 @@ int uv_thread_create(uv_thread_t *tid, void (*entry)(void *arg), void *arg) { ...@@ -118,7 +118,7 @@ int uv_thread_create(uv_thread_t *tid, void (*entry)(void *arg), void *arg) {
ctx->arg = arg; ctx->arg = arg;
/* Create the thread in suspended state so we have a chance to pass /* Create the thread in suspended state so we have a chance to pass
* its own creation handle to it */ * its own creation handle to it */
thread = (HANDLE) _beginthreadex(NULL, thread = (HANDLE) _beginthreadex(NULL,
0, 0,
uv__thread_start, uv__thread_start,
......
...@@ -941,20 +941,15 @@ void uv_process_tty_read_line_req(uv_loop_t* loop, uv_tty_t* handle, ...@@ -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, handle->read_cb((uv_stream_t*) handle,
uv_translate_sys_error(GET_REQ_ERROR(req)), uv_translate_sys_error(GET_REQ_ERROR(req)),
&buf); &buf);
} else {
/* The read was cancelled, or whatever we don't care */
handle->read_cb((uv_stream_t*) handle, 0, &buf);
} }
} else { } 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 */ /* Read successful. TODO: read unicode, convert to utf-8 */
DWORD bytes = req->u.io.overlapped.InternalHigh; DWORD bytes = req->u.io.overlapped.InternalHigh;
handle->read_cb((uv_stream_t*) handle, bytes, &buf); 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. */ /* Wait for more input events. */
...@@ -1033,6 +1028,7 @@ int uv_tty_read_stop(uv_tty_t* handle) { ...@@ -1033,6 +1028,7 @@ int uv_tty_read_stop(uv_tty_t* handle) {
/* Cancel raw read. Write some bullshit event to force the console wait to /* Cancel raw read. Write some bullshit event to force the console wait to
* return. */ * return. */
memset(&record, 0, sizeof record); memset(&record, 0, sizeof record);
record.EventType = FOCUS_EVENT;
if (!WriteConsoleInputW(handle->handle, &record, 1, &written)) { if (!WriteConsoleInputW(handle->handle, &record, 1, &written)) {
return GetLastError(); return GetLastError();
} }
...@@ -2179,14 +2175,14 @@ void uv_process_tty_write_req(uv_loop_t* loop, uv_tty_t* handle, ...@@ -2179,14 +2175,14 @@ void uv_process_tty_write_req(uv_loop_t* loop, uv_tty_t* handle,
void uv_tty_close(uv_tty_t* handle) { void uv_tty_close(uv_tty_t* handle) {
assert(handle->u.fd == -1 || handle->u.fd > 2); assert(handle->u.fd == -1 || handle->u.fd > 2);
if (handle->flags & UV_HANDLE_READING)
uv_tty_read_stop(handle);
if (handle->u.fd == -1) if (handle->u.fd == -1)
CloseHandle(handle->handle); CloseHandle(handle->handle);
else else
close(handle->u.fd); close(handle->u.fd);
if (handle->flags & UV_HANDLE_READING)
uv_tty_read_stop(handle);
handle->u.fd = -1; handle->u.fd = -1;
handle->handle = INVALID_HANDLE_VALUE; handle->handle = INVALID_HANDLE_VALUE;
handle->flags &= ~(UV_HANDLE_READABLE | UV_HANDLE_WRITABLE); handle->flags &= ~(UV_HANDLE_READABLE | UV_HANDLE_WRITABLE);
......
...@@ -816,6 +816,9 @@ int uv_interface_addresses(uv_interface_address_t** addresses_ptr, ...@@ -816,6 +816,9 @@ int uv_interface_addresses(uv_interface_address_t** addresses_ptr,
int is_vista_or_greater; int is_vista_or_greater;
ULONG flags; ULONG flags;
*addresses_ptr = NULL;
*count_ptr = 0;
is_vista_or_greater = is_windows_version_or_greater(6, 0, 0, 0); is_vista_or_greater = is_windows_version_or_greater(6, 0, 0, 0);
if (is_vista_or_greater) { if (is_vista_or_greater) {
flags = GAA_FLAG_SKIP_ANYCAST | GAA_FLAG_SKIP_MULTICAST | flags = GAA_FLAG_SKIP_ANYCAST | GAA_FLAG_SKIP_MULTICAST |
......
...@@ -340,6 +340,7 @@ HELPER_IMPL(tcp4_echo_server) { ...@@ -340,6 +340,7 @@ HELPER_IMPL(tcp4_echo_server) {
if (tcp4_echo_start(TEST_PORT)) if (tcp4_echo_start(TEST_PORT))
return 1; return 1;
notify_parent_process();
uv_run(loop, UV_RUN_DEFAULT); uv_run(loop, UV_RUN_DEFAULT);
return 0; return 0;
} }
...@@ -351,6 +352,7 @@ HELPER_IMPL(tcp6_echo_server) { ...@@ -351,6 +352,7 @@ HELPER_IMPL(tcp6_echo_server) {
if (tcp6_echo_start(TEST_PORT)) if (tcp6_echo_start(TEST_PORT))
return 1; return 1;
notify_parent_process();
uv_run(loop, UV_RUN_DEFAULT); uv_run(loop, UV_RUN_DEFAULT);
return 0; return 0;
} }
...@@ -362,6 +364,7 @@ HELPER_IMPL(pipe_echo_server) { ...@@ -362,6 +364,7 @@ HELPER_IMPL(pipe_echo_server) {
if (pipe_echo_start(TEST_PIPENAME)) if (pipe_echo_start(TEST_PIPENAME))
return 1; return 1;
notify_parent_process();
uv_run(loop, UV_RUN_DEFAULT); uv_run(loop, UV_RUN_DEFAULT);
return 0; return 0;
} }
...@@ -373,6 +376,7 @@ HELPER_IMPL(udp4_echo_server) { ...@@ -373,6 +376,7 @@ HELPER_IMPL(udp4_echo_server) {
if (udp4_echo_start(TEST_PORT)) if (udp4_echo_start(TEST_PORT))
return 1; return 1;
notify_parent_process();
uv_run(loop, UV_RUN_DEFAULT); uv_run(loop, UV_RUN_DEFAULT);
return 0; return 0;
} }
...@@ -109,20 +109,24 @@ static int maybe_run_test(int argc, char **argv) { ...@@ -109,20 +109,24 @@ static int maybe_run_test(int argc, char **argv) {
} }
if (strcmp(argv[1], "spawn_helper1") == 0) { if (strcmp(argv[1], "spawn_helper1") == 0) {
notify_parent_process();
return 1; return 1;
} }
if (strcmp(argv[1], "spawn_helper2") == 0) { if (strcmp(argv[1], "spawn_helper2") == 0) {
notify_parent_process();
printf("hello world\n"); printf("hello world\n");
return 1; return 1;
} }
if (strcmp(argv[1], "spawn_tcp_server_helper") == 0) { if (strcmp(argv[1], "spawn_tcp_server_helper") == 0) {
notify_parent_process();
return spawn_tcp_server_helper(); return spawn_tcp_server_helper();
} }
if (strcmp(argv[1], "spawn_helper3") == 0) { if (strcmp(argv[1], "spawn_helper3") == 0) {
char buffer[256]; char buffer[256];
notify_parent_process();
ASSERT(buffer == fgets(buffer, sizeof(buffer) - 1, stdin)); ASSERT(buffer == fgets(buffer, sizeof(buffer) - 1, stdin));
buffer[sizeof(buffer) - 1] = '\0'; buffer[sizeof(buffer) - 1] = '\0';
fputs(buffer, stdout); fputs(buffer, stdout);
...@@ -130,12 +134,14 @@ static int maybe_run_test(int argc, char **argv) { ...@@ -130,12 +134,14 @@ static int maybe_run_test(int argc, char **argv) {
} }
if (strcmp(argv[1], "spawn_helper4") == 0) { if (strcmp(argv[1], "spawn_helper4") == 0) {
notify_parent_process();
/* Never surrender, never return! */ /* Never surrender, never return! */
while (1) uv_sleep(10000); while (1) uv_sleep(10000);
} }
if (strcmp(argv[1], "spawn_helper5") == 0) { if (strcmp(argv[1], "spawn_helper5") == 0) {
const char out[] = "fourth stdio!\n"; const char out[] = "fourth stdio!\n";
notify_parent_process();
#ifdef _WIN32 #ifdef _WIN32
DWORD bytes; DWORD bytes;
WriteFile((HANDLE) _get_osfhandle(3), out, sizeof(out) - 1, &bytes, NULL); WriteFile((HANDLE) _get_osfhandle(3), out, sizeof(out) - 1, &bytes, NULL);
...@@ -156,6 +162,8 @@ static int maybe_run_test(int argc, char **argv) { ...@@ -156,6 +162,8 @@ static int maybe_run_test(int argc, char **argv) {
if (strcmp(argv[1], "spawn_helper6") == 0) { if (strcmp(argv[1], "spawn_helper6") == 0) {
int r; int r;
notify_parent_process();
r = fprintf(stdout, "hello world\n"); r = fprintf(stdout, "hello world\n");
ASSERT(r > 0); ASSERT(r > 0);
...@@ -168,6 +176,9 @@ static int maybe_run_test(int argc, char **argv) { ...@@ -168,6 +176,9 @@ static int maybe_run_test(int argc, char **argv) {
if (strcmp(argv[1], "spawn_helper7") == 0) { if (strcmp(argv[1], "spawn_helper7") == 0) {
int r; int r;
char *test; char *test;
notify_parent_process();
/* Test if the test value from the parent is still set */ /* Test if the test value from the parent is still set */
test = getenv("ENV_TEST"); test = getenv("ENV_TEST");
ASSERT(test != NULL); ASSERT(test != NULL);
...@@ -181,6 +192,8 @@ static int maybe_run_test(int argc, char **argv) { ...@@ -181,6 +192,8 @@ static int maybe_run_test(int argc, char **argv) {
#ifndef _WIN32 #ifndef _WIN32
if (strcmp(argv[1], "spawn_helper8") == 0) { if (strcmp(argv[1], "spawn_helper8") == 0) {
int fd; int fd;
notify_parent_process();
ASSERT(sizeof(fd) == read(0, &fd, sizeof(fd))); ASSERT(sizeof(fd) == read(0, &fd, sizeof(fd)));
ASSERT(fd > 2); ASSERT(fd > 2);
ASSERT(-1 == write(fd, "x", 1)); ASSERT(-1 == write(fd, "x", 1));
...@@ -190,6 +203,7 @@ static int maybe_run_test(int argc, char **argv) { ...@@ -190,6 +203,7 @@ static int maybe_run_test(int argc, char **argv) {
#endif /* !_WIN32 */ #endif /* !_WIN32 */
if (strcmp(argv[1], "spawn_helper9") == 0) { if (strcmp(argv[1], "spawn_helper9") == 0) {
notify_parent_process();
return spawn_stdin_stdout(); return spawn_stdin_stdout();
} }
...@@ -200,6 +214,7 @@ static int maybe_run_test(int argc, char **argv) { ...@@ -200,6 +214,7 @@ static int maybe_run_test(int argc, char **argv) {
ASSERT(uid == getuid()); ASSERT(uid == getuid());
ASSERT(gid == getgid()); ASSERT(gid == getgid());
notify_parent_process();
return 1; return 1;
} }
......
...@@ -40,6 +40,31 @@ ...@@ -40,6 +40,31 @@
#include <sys/time.h> #include <sys/time.h>
#include <pthread.h> #include <pthread.h>
extern char** environ;
static void closefd(int fd) {
if (close(fd) == 0 || errno == EINTR || errno == EINPROGRESS)
return;
perror("close");
abort();
}
void notify_parent_process(void) {
char* arg;
int fd;
arg = getenv("UV_TEST_RUNNER_FD");
if (arg == NULL)
return;
fd = atoi(arg);
assert(fd > STDERR_FILENO);
unsetenv("UV_TEST_RUNNER_FD");
closefd(fd);
}
/* Do platform-specific initialization. */ /* Do platform-specific initialization. */
int platform_init(int argc, char **argv) { int platform_init(int argc, char **argv) {
...@@ -64,9 +89,31 @@ int process_start(char* name, char* part, process_info_t* p, int is_helper) { ...@@ -64,9 +89,31 @@ int process_start(char* name, char* part, process_info_t* p, int is_helper) {
int stdout_fd; int stdout_fd;
const char* arg; const char* arg;
char* args[16]; char* args[16];
int pipefd[2];
char fdstr[8];
ssize_t rc;
int n; int n;
pid_t pid; pid_t pid;
arg = getenv("UV_USE_VALGRIND");
n = 0;
/* Disable valgrind for helpers, it complains about helpers leaking memory.
* They're killed after the test and as such never get a chance to clean up.
*/
if (is_helper == 0 && arg != NULL && atoi(arg) != 0) {
args[n++] = "valgrind";
args[n++] = "--quiet";
args[n++] = "--leak-check=full";
args[n++] = "--show-reachable=yes";
args[n++] = "--error-exitcode=125";
}
args[n++] = executable_path;
args[n++] = name;
args[n++] = part;
args[n++] = NULL;
stdout_file = tmpfile(); stdout_file = tmpfile();
stdout_fd = fileno(stdout_file); stdout_fd = fileno(stdout_file);
if (!stdout_file) { if (!stdout_file) {
...@@ -74,6 +121,19 @@ int process_start(char* name, char* part, process_info_t* p, int is_helper) { ...@@ -74,6 +121,19 @@ int process_start(char* name, char* part, process_info_t* p, int is_helper) {
return -1; return -1;
} }
if (is_helper) {
if (pipe(pipefd)) {
perror("pipe");
return -1;
}
snprintf(fdstr, sizeof(fdstr), "%d", pipefd[1]);
if (setenv("UV_TEST_RUNNER_FD", fdstr, /* overwrite */ 1)) {
perror("setenv");
return -1;
}
}
p->terminated = 0; p->terminated = 0;
p->status = 0; p->status = 0;
...@@ -86,29 +146,12 @@ int process_start(char* name, char* part, process_info_t* p, int is_helper) { ...@@ -86,29 +146,12 @@ int process_start(char* name, char* part, process_info_t* p, int is_helper) {
if (pid == 0) { if (pid == 0) {
/* child */ /* child */
arg = getenv("UV_USE_VALGRIND"); if (is_helper)
n = 0; closefd(pipefd[0]);
/* Disable valgrind for helpers, it complains about helpers leaking memory.
* They're killed after the test and as such never get a chance to clean up.
*/
if (is_helper == 0 && arg != NULL && atoi(arg) != 0) {
args[n++] = "valgrind";
args[n++] = "--quiet";
args[n++] = "--leak-check=full";
args[n++] = "--show-reachable=yes";
args[n++] = "--error-exitcode=125";
}
args[n++] = executable_path;
args[n++] = name;
args[n++] = part;
args[n++] = NULL;
dup2(stdout_fd, STDOUT_FILENO); dup2(stdout_fd, STDOUT_FILENO);
dup2(stdout_fd, STDERR_FILENO); dup2(stdout_fd, STDERR_FILENO);
execvp(args[0], args); execve(args[0], args, environ);
perror("execvp()"); perror("execve()");
_exit(127); _exit(127);
} }
...@@ -117,6 +160,28 @@ int process_start(char* name, char* part, process_info_t* p, int is_helper) { ...@@ -117,6 +160,28 @@ int process_start(char* name, char* part, process_info_t* p, int is_helper) {
p->name = strdup(name); p->name = strdup(name);
p->stdout_file = stdout_file; p->stdout_file = stdout_file;
if (!is_helper)
return 0;
closefd(pipefd[1]);
unsetenv("UV_TEST_RUNNER_FD");
do
rc = read(pipefd[0], &n, 1);
while (rc == -1 && errno == EINTR);
closefd(pipefd[0]);
if (rc == -1) {
perror("read");
return -1;
}
if (rc > 0) {
fprintf(stderr, "EOF expected but got data.\n");
return -1;
}
return 0; return 0;
} }
......
...@@ -76,6 +76,11 @@ int process_start(char *name, char *part, process_info_t *p, int is_helper) { ...@@ -76,6 +76,11 @@ int process_start(char *name, char *part, process_info_t *p, int is_helper) {
PROCESS_INFORMATION pi; PROCESS_INFORMATION pi;
DWORD result; DWORD result;
if (!is_helper) {
/* Give the helpers time to settle. Race-y, fix this. */
uv_sleep(250);
}
if (GetTempPathW(sizeof(path) / sizeof(WCHAR), (WCHAR*)&path) == 0) if (GetTempPathW(sizeof(path) / sizeof(WCHAR), (WCHAR*)&path) == 0)
goto error; goto error;
if (GetTempFileNameW((WCHAR*)&path, L"uv", 0, (WCHAR*)&filename) == 0) if (GetTempFileNameW((WCHAR*)&path, L"uv", 0, (WCHAR*)&filename) == 0)
...@@ -228,7 +233,7 @@ int process_copy_output(process_info_t* p, FILE* stream) { ...@@ -228,7 +233,7 @@ int process_copy_output(process_info_t* p, FILE* stream) {
while (fgets(buf, sizeof(buf), f) != NULL) while (fgets(buf, sizeof(buf), f) != NULL)
print_lines(buf, strlen(buf), stream); print_lines(buf, strlen(buf), stream);
if (ferror(f)) if (ferror(f))
return -1; return -1;
......
...@@ -215,9 +215,6 @@ int run_test(const char* test, ...@@ -215,9 +215,6 @@ int run_test(const char* test,
process_count++; process_count++;
} }
/* Give the helpers time to settle. Race-y, fix this. */
uv_sleep(250);
/* Now start the test itself. */ /* Now start the test itself. */
for (task = TASKS; task->main; task++) { for (task = TASKS; task->main; task++) {
if (strcmp(test, task->task_name) != 0) { if (strcmp(test, task->task_name) != 0) {
......
...@@ -181,6 +181,12 @@ extern int snprintf(char*, size_t, const char*, ...); ...@@ -181,6 +181,12 @@ extern int snprintf(char*, size_t, const char*, ...);
# define UNUSED # define UNUSED
#endif #endif
#if defined(_WIN32)
#define notify_parent_process() ((void) 0)
#else
extern void notify_parent_process(void);
#endif
/* Fully close a loop */ /* Fully close a loop */
static void close_walk_cb(uv_handle_t* handle, void* arg) { static void close_walk_cb(uv_handle_t* handle, void* arg) {
if (!uv_is_closing(handle)) if (!uv_is_closing(handle))
......
...@@ -104,3 +104,45 @@ TEST_IMPL(barrier_3) { ...@@ -104,3 +104,45 @@ TEST_IMPL(barrier_3) {
return 0; return 0;
} }
static void serial_worker(void* data) {
uv_barrier_t* barrier;
barrier = data;
if (uv_barrier_wait(barrier) > 0)
uv_barrier_destroy(barrier);
uv_sleep(100); /* Wait a bit before terminating. */
}
/* Ensure that uv_barrier_wait returns positive only after all threads have
* exited the barrier. If this value is returned too early and the barrier is
* destroyed prematurely, then this test may see a crash. */
TEST_IMPL(barrier_serial_thread) {
uv_thread_t threads[4];
uv_barrier_t barrier;
unsigned i;
ASSERT(0 == uv_barrier_init(&barrier, ARRAY_SIZE(threads) + 1));
for (i = 0; i < ARRAY_SIZE(threads); ++i)
ASSERT(0 == uv_thread_create(&threads[i], serial_worker, &barrier));
if (uv_barrier_wait(&barrier) > 0)
uv_barrier_destroy(&barrier);
for (i = 0; i < ARRAY_SIZE(threads); ++i)
ASSERT(0 == uv_thread_join(&threads[i]));
return 0;
}
/* Single thread uv_barrier_wait should return correct return value. */
TEST_IMPL(barrier_serial_thread_single) {
uv_barrier_t barrier;
ASSERT(0 == uv_barrier_init(&barrier, 1));
ASSERT(0 < uv_barrier_wait(&barrier));
uv_barrier_destroy(&barrier);
return 0;
}
/* Copyright The libuv project and 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 "task.h"
#include "../src/idna.c"
#include <string.h>
TEST_IMPL(utf8_decode1) {
const char* p;
char b[32];
int i;
/* ASCII. */
p = b;
snprintf(b, sizeof(b), "%c\x7F", 0x00);
ASSERT(0 == uv__utf8_decode1(&p, b + sizeof(b)));
ASSERT(p == b + 1);
ASSERT(127 == uv__utf8_decode1(&p, b + sizeof(b)));
ASSERT(p == b + 2);
/* Two-byte sequences. */
p = b;
snprintf(b, sizeof(b), "\xC2\x80\xDF\xBF");
ASSERT(128 == uv__utf8_decode1(&p, b + sizeof(b)));
ASSERT(p == b + 2);
ASSERT(0x7FF == uv__utf8_decode1(&p, b + sizeof(b)));
ASSERT(p == b + 4);
/* Three-byte sequences. */
p = b;
snprintf(b, sizeof(b), "\xE0\xA0\x80\xEF\xBF\xBF");
ASSERT(0x800 == uv__utf8_decode1(&p, b + sizeof(b)));
ASSERT(p == b + 3);
ASSERT(0xFFFF == uv__utf8_decode1(&p, b + sizeof(b)));
ASSERT(p == b + 6);
/* Four-byte sequences. */
p = b;
snprintf(b, sizeof(b), "\xF0\x90\x80\x80\xF4\x8F\xBF\xBF");
ASSERT(0x10000 == uv__utf8_decode1(&p, b + sizeof(b)));
ASSERT(p == b + 4);
ASSERT(0x10FFFF == uv__utf8_decode1(&p, b + sizeof(b)));
ASSERT(p == b + 8);
/* Four-byte sequences > U+10FFFF; disallowed. */
p = b;
snprintf(b, sizeof(b), "\xF4\x90\xC0\xC0\xF7\xBF\xBF\xBF");
ASSERT((unsigned) -1 == uv__utf8_decode1(&p, b + sizeof(b)));
ASSERT(p == b + 4);
ASSERT((unsigned) -1 == uv__utf8_decode1(&p, b + sizeof(b)));
ASSERT(p == b + 8);
/* Overlong; disallowed. */
p = b;
snprintf(b, sizeof(b), "\xC0\x80\xC1\x80");
ASSERT((unsigned) -1 == uv__utf8_decode1(&p, b + sizeof(b)));
ASSERT(p == b + 2);
ASSERT((unsigned) -1 == uv__utf8_decode1(&p, b + sizeof(b)));
ASSERT(p == b + 4);
/* Surrogate pairs; disallowed. */
p = b;
snprintf(b, sizeof(b), "\xED\xA0\x80\xED\xA3\xBF");
ASSERT((unsigned) -1 == uv__utf8_decode1(&p, b + sizeof(b)));
ASSERT(p == b + 3);
ASSERT((unsigned) -1 == uv__utf8_decode1(&p, b + sizeof(b)));
ASSERT(p == b + 6);
/* Simply illegal. */
p = b;
snprintf(b, sizeof(b), "\xF8\xF9\xFA\xFB\xFC\xFD\xFE\xFF");
for (i = 1; i <= 8; i++) {
ASSERT((unsigned) -1 == uv__utf8_decode1(&p, b + sizeof(b)));
ASSERT(p == b + i);
}
return 0;
}
/* Doesn't work on z/OS because that platform uses EBCDIC, not ASCII. */
#ifndef __MVS__
#define F(input, err) \
do { \
char d[256] = {0}; \
static const char s[] = "" input ""; \
ASSERT(err == uv__idna_toascii(s, s + sizeof(s) - 1, d, d + sizeof(d))); \
} while (0)
#define T(input, expected) \
do { \
long n; \
char d1[256] = {0}; \
char d2[256] = {0}; \
static const char s[] = "" input ""; \
n = uv__idna_toascii(s, s + sizeof(s) - 1, d1, d1 + sizeof(d1)); \
ASSERT(n == sizeof(expected)); \
ASSERT(0 == memcmp(d1, expected, n)); \
/* Sanity check: encoding twice should not change the output. */ \
n = uv__idna_toascii(d1, d1 + strlen(d1), d2, d2 + sizeof(d2)); \
ASSERT(n == sizeof(expected)); \
ASSERT(0 == memcmp(d2, expected, n)); \
ASSERT(0 == memcmp(d1, d2, sizeof(d2))); \
} while (0)
TEST_IMPL(idna_toascii) {
/* Illegal inputs. */
F("\xC0\x80\xC1\x80", UV_EINVAL); /* Overlong UTF-8 sequence. */
F("\xC0\x80\xC1\x80.com", UV_EINVAL); /* Overlong UTF-8 sequence. */
/* No conversion. */
T("", "");
T(".", ".");
T(".com", ".com");
T("example", "example");
T("example-", "example-");
T("straße.de", "xn--strae-oqa.de");
/* Test cases adapted from punycode.js. Most are from RFC 3492. */
T("foo.bar", "foo.bar");
T("mañana.com", "xn--maana-pta.com");
T("example.com.", "example.com.");
T("bücher.com", "xn--bcher-kva.com");
T("café.com", "xn--caf-dma.com");
T("café.café.com", "xn--caf-dma.xn--caf-dma.com");
T("☃-⌘.com", "xn----dqo34k.com");
T("퐀☃-⌘.com", "xn----dqo34kn65z.com");
T("💩.la", "xn--ls8h.la");
T("mañana.com", "xn--maana-pta.com");
T("mañana。com", "xn--maana-pta.com");
T("mañana.com", "xn--maana-pta.com");
T("mañana。com", "xn--maana-pta.com");
T("ü", "xn--tda");
T(".ü", ".xn--tda");
T("ü.ü", "xn--tda.xn--tda");
T("ü.ü.", "xn--tda.xn--tda.");
T("üëäö♥", "xn--4can8av2009b");
T("Willst du die Blüthe des frühen, die Früchte des späteren Jahres",
"xn--Willst du die Blthe des frhen, "
"die Frchte des spteren Jahres-x9e96lkal");
T("ليهمابتكلموشعربي؟", "xn--egbpdaj6bu4bxfgehfvwxn");
T("他们为什么不说中文", "xn--ihqwcrb4cv8a8dqg056pqjye");
T("他們爲什麽不說中文", "xn--ihqwctvzc91f659drss3x8bo0yb");
T("Pročprostěnemluvíčesky", "xn--Proprostnemluvesky-uyb24dma41a");
T("למההםפשוטלאמדבריםעברית", "xn--4dbcagdahymbxekheh6e0a7fei0b");
T("यहलोगहिन्दीक्योंनहींबोलसकतेहैं",
"xn--i1baa7eci9glrd9b2ae1bj0hfcgg6iyaf8o0a1dig0cd");
T("なぜみんな日本語を話してくれないのか",
"xn--n8jok5ay5dzabd5bym9f0cm5685rrjetr6pdxa");
T("세계의모든사람들이한국어를이해한다면얼마나좋을까",
"xn--989aomsvi5e83db1d2a355cv1e0vak1d"
"wrv93d5xbh15a0dt30a5jpsd879ccm6fea98c");
T("почемужеонинеговорятпорусски", "xn--b1abfaaepdrnnbgefbadotcwatmq2g4l");
T("PorquénopuedensimplementehablarenEspañol",
"xn--PorqunopuedensimplementehablarenEspaol-fmd56a");
T("TạisaohọkhôngthểchỉnóitiếngViệt",
"xn--TisaohkhngthchnitingVit-kjcr8268qyxafd2f1b9g");
T("3年B組金八先生", "xn--3B-ww4c5e180e575a65lsy2b");
T("安室奈美恵-with-SUPER-MONKEYS",
"xn---with-SUPER-MONKEYS-pc58ag80a8qai00g7n9n");
T("Hello-Another-Way-それぞれの場所",
"xn--Hello-Another-Way--fc4qua05auwb3674vfr0b");
T("ひとつ屋根の下2", "xn--2-u9tlzr9756bt3uc0v");
T("MajiでKoiする5秒前", "xn--MajiKoi5-783gue6qz075azm5e");
T("パフィーdeルンバ", "xn--de-jg4avhby1noc0d");
T("そのスピードで", "xn--d9juau41awczczp");
T("-> $1.00 <-", "-> $1.00 <-");
/* Test cases from https://unicode.org/reports/tr46/ */
T("faß.de", "xn--fa-hia.de");
T("βόλος.com", "xn--nxasmm1c.com");
T("ශ්‍රී.com", "xn--10cl1a0b660p.com");
T("نامه‌ای.com", "xn--mgba3gch31f060k.com");
return 0;
}
#undef T
#endif /* __MVS__ */
...@@ -150,6 +150,7 @@ int ipc_helper_heavy_traffic_deadlock_bug(void) { ...@@ -150,6 +150,7 @@ int ipc_helper_heavy_traffic_deadlock_bug(void) {
r = uv_pipe_open(&pipe, 0); r = uv_pipe_open(&pipe, 0);
ASSERT(r == 0); ASSERT(r == 0);
notify_parent_process();
do_writes_and_reads((uv_stream_t*) &pipe); do_writes_and_reads((uv_stream_t*) &pipe);
uv_sleep(100); uv_sleep(100);
......
...@@ -397,6 +397,7 @@ int run_ipc_send_recv_helper(uv_loop_t* loop, int inprocess) { ...@@ -397,6 +397,7 @@ int run_ipc_send_recv_helper(uv_loop_t* loop, int inprocess) {
send_recv_start(); send_recv_start();
} }
notify_parent_process();
r = uv_run(loop, UV_RUN_DEFAULT); r = uv_run(loop, UV_RUN_DEFAULT);
ASSERT(r == 0); ASSERT(r == 0);
......
...@@ -724,6 +724,7 @@ int ipc_helper(int listen_after_write) { ...@@ -724,6 +724,7 @@ int ipc_helper(int listen_after_write) {
ASSERT(r == 0); ASSERT(r == 0);
} }
notify_parent_process();
r = uv_run(uv_default_loop(), UV_RUN_DEFAULT); r = uv_run(uv_default_loop(), UV_RUN_DEFAULT);
ASSERT(r == 0); ASSERT(r == 0);
......
...@@ -37,6 +37,8 @@ TEST_DECLARE (default_loop_close) ...@@ -37,6 +37,8 @@ TEST_DECLARE (default_loop_close)
TEST_DECLARE (barrier_1) TEST_DECLARE (barrier_1)
TEST_DECLARE (barrier_2) TEST_DECLARE (barrier_2)
TEST_DECLARE (barrier_3) TEST_DECLARE (barrier_3)
TEST_DECLARE (barrier_serial_thread)
TEST_DECLARE (barrier_serial_thread_single)
TEST_DECLARE (condvar_1) TEST_DECLARE (condvar_1)
TEST_DECLARE (condvar_2) TEST_DECLARE (condvar_2)
TEST_DECLARE (condvar_3) TEST_DECLARE (condvar_3)
...@@ -50,6 +52,7 @@ TEST_DECLARE (tty) ...@@ -50,6 +52,7 @@ TEST_DECLARE (tty)
TEST_DECLARE (tty_raw) TEST_DECLARE (tty_raw)
TEST_DECLARE (tty_empty_write) TEST_DECLARE (tty_empty_write)
TEST_DECLARE (tty_large_write) TEST_DECLARE (tty_large_write)
TEST_DECLARE (tty_raw_cancel)
#endif #endif
TEST_DECLARE (tty_file) TEST_DECLARE (tty_file)
TEST_DECLARE (tty_pty) TEST_DECLARE (tty_pty)
...@@ -339,8 +342,11 @@ TEST_DECLARE (get_osfhandle_valid_handle) ...@@ -339,8 +342,11 @@ TEST_DECLARE (get_osfhandle_valid_handle)
TEST_DECLARE (open_osfhandle_valid_handle) TEST_DECLARE (open_osfhandle_valid_handle)
TEST_DECLARE (fs_write_alotof_bufs) TEST_DECLARE (fs_write_alotof_bufs)
TEST_DECLARE (fs_write_alotof_bufs_with_offset) TEST_DECLARE (fs_write_alotof_bufs_with_offset)
TEST_DECLARE (fs_partial_read)
TEST_DECLARE (fs_partial_write)
TEST_DECLARE (fs_file_pos_after_op_with_offset) TEST_DECLARE (fs_file_pos_after_op_with_offset)
TEST_DECLARE (fs_null_req) TEST_DECLARE (fs_null_req)
TEST_DECLARE (fs_read_dir)
#ifdef _WIN32 #ifdef _WIN32
TEST_DECLARE (fs_exclusive_sharing_mode) TEST_DECLARE (fs_exclusive_sharing_mode)
TEST_DECLARE (fs_open_readonly_acl) TEST_DECLARE (fs_open_readonly_acl)
...@@ -436,6 +442,9 @@ TEST_DECLARE (fork_threadpool_queue_work_simple) ...@@ -436,6 +442,9 @@ TEST_DECLARE (fork_threadpool_queue_work_simple)
#endif #endif
#endif #endif
TEST_DECLARE (idna_toascii)
TEST_DECLARE (utf8_decode1)
TASK_LIST_START TASK_LIST_START
TEST_ENTRY_CUSTOM (platform_output, 0, 1, 5000) TEST_ENTRY_CUSTOM (platform_output, 0, 1, 5000)
...@@ -456,6 +465,8 @@ TASK_LIST_START ...@@ -456,6 +465,8 @@ TASK_LIST_START
TEST_ENTRY (barrier_1) TEST_ENTRY (barrier_1)
TEST_ENTRY (barrier_2) TEST_ENTRY (barrier_2)
TEST_ENTRY (barrier_3) TEST_ENTRY (barrier_3)
TEST_ENTRY (barrier_serial_thread)
TEST_ENTRY (barrier_serial_thread_single)
TEST_ENTRY (condvar_1) TEST_ENTRY (condvar_1)
TEST_ENTRY (condvar_2) TEST_ENTRY (condvar_2)
TEST_ENTRY (condvar_3) TEST_ENTRY (condvar_3)
...@@ -480,6 +491,7 @@ TASK_LIST_START ...@@ -480,6 +491,7 @@ TASK_LIST_START
TEST_ENTRY (tty_raw) TEST_ENTRY (tty_raw)
TEST_ENTRY (tty_empty_write) TEST_ENTRY (tty_empty_write)
TEST_ENTRY (tty_large_write) TEST_ENTRY (tty_large_write)
TEST_ENTRY (tty_raw_cancel)
#endif #endif
TEST_ENTRY (tty_file) TEST_ENTRY (tty_file)
TEST_ENTRY (tty_pty) TEST_ENTRY (tty_pty)
...@@ -884,9 +896,12 @@ TASK_LIST_START ...@@ -884,9 +896,12 @@ TASK_LIST_START
TEST_ENTRY (fs_write_multiple_bufs) TEST_ENTRY (fs_write_multiple_bufs)
TEST_ENTRY (fs_write_alotof_bufs) TEST_ENTRY (fs_write_alotof_bufs)
TEST_ENTRY (fs_write_alotof_bufs_with_offset) TEST_ENTRY (fs_write_alotof_bufs_with_offset)
TEST_ENTRY (fs_partial_read)
TEST_ENTRY (fs_partial_write)
TEST_ENTRY (fs_read_write_null_arguments) TEST_ENTRY (fs_read_write_null_arguments)
TEST_ENTRY (fs_file_pos_after_op_with_offset) TEST_ENTRY (fs_file_pos_after_op_with_offset)
TEST_ENTRY (fs_null_req) TEST_ENTRY (fs_null_req)
TEST_ENTRY (fs_read_dir)
#ifdef _WIN32 #ifdef _WIN32
TEST_ENTRY (fs_exclusive_sharing_mode) TEST_ENTRY (fs_exclusive_sharing_mode)
TEST_ENTRY (fs_open_readonly_acl) TEST_ENTRY (fs_open_readonly_acl)
...@@ -934,6 +949,13 @@ TASK_LIST_START ...@@ -934,6 +949,13 @@ TASK_LIST_START
#endif #endif
#endif #endif
TEST_ENTRY (utf8_decode1)
/* Doesn't work on z/OS because that platform uses EBCDIC, not ASCII. */
#ifndef __MVS__
TEST_ENTRY (idna_toascii)
#endif
#if 0 #if 0
/* These are for testing the test runner. */ /* These are for testing the test runner. */
TEST_ENTRY (fail_always) TEST_ENTRY (fail_always)
......
...@@ -54,8 +54,10 @@ TEST_IMPL(process_priority) { ...@@ -54,8 +54,10 @@ TEST_IMPL(process_priority) {
#ifndef _WIN32 #ifndef _WIN32
ASSERT(priority == i); ASSERT(priority == i);
#else #else
/* On Windows, only elevated users can set UV_PRIORITY_HIGHEST. Other
users will silently be set to UV_PRIORITY_HIGH. */
if (i < UV_PRIORITY_HIGH) if (i < UV_PRIORITY_HIGH)
ASSERT(priority == UV_PRIORITY_HIGHEST); ASSERT(priority == UV_PRIORITY_HIGHEST || priority == UV_PRIORITY_HIGH);
else if (i < UV_PRIORITY_ABOVE_NORMAL) else if (i < UV_PRIORITY_ABOVE_NORMAL)
ASSERT(priority == UV_PRIORITY_HIGH); ASSERT(priority == UV_PRIORITY_HIGH);
else if (i < UV_PRIORITY_NORMAL) else if (i < UV_PRIORITY_NORMAL)
......
...@@ -25,11 +25,7 @@ ...@@ -25,11 +25,7 @@
#include <string.h> #include <string.h>
#ifdef __APPLE__ #define NUM_ITERATIONS 50
# define NUM_ITERATIONS 10
#else
# define NUM_ITERATIONS 50
#endif
static const char* titles[] = { static const char* titles[] = {
"8L2NY0Kdj0XyNFZnmUZigIOfcWjyNr0SkMmUhKw99VLUsZFrvCQQC3XIRfNR8pjyMjXObllled", "8L2NY0Kdj0XyNFZnmUZigIOfcWjyNr0SkMmUhKw99VLUsZFrvCQQC3XIRfNR8pjyMjXObllled",
......
...@@ -1172,6 +1172,7 @@ TEST_IMPL(argument_escaping) { ...@@ -1172,6 +1172,7 @@ TEST_IMPL(argument_escaping) {
for (i = 0; i < count; ++i) { for (i = 0; i < count; ++i) {
free(test_output[i]); free(test_output[i]);
} }
free(test_output);
result = make_program_args(verbatim, 1, &verbatim_output); result = make_program_args(verbatim, 1, &verbatim_output);
ASSERT(result == 0); ASSERT(result == 0);
......
...@@ -232,6 +232,7 @@ int stdio_over_pipes_helper(void) { ...@@ -232,6 +232,7 @@ int stdio_over_pipes_helper(void) {
ASSERT(r == 0); ASSERT(r == 0);
} }
notify_parent_process();
uv_run(loop, UV_RUN_DEFAULT); uv_run(loop, UV_RUN_DEFAULT);
ASSERT(after_write_called == 7); ASSERT(after_write_called == 7);
......
...@@ -310,6 +310,41 @@ TEST_IMPL(tty_large_write) { ...@@ -310,6 +310,41 @@ TEST_IMPL(tty_large_write) {
MAKE_VALGRIND_HAPPY(); MAKE_VALGRIND_HAPPY();
return 0; return 0;
} }
TEST_IMPL(tty_raw_cancel) {
int r;
int ttyin_fd;
uv_tty_t tty_in;
uv_loop_t* loop;
HANDLE handle;
loop = uv_default_loop();
/* Make sure we have an FD that refers to a tty */
handle = CreateFileA("conin$",
GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL);
ASSERT(handle != INVALID_HANDLE_VALUE);
ttyin_fd = _open_osfhandle((intptr_t) handle, 0);
ASSERT(ttyin_fd >= 0);
ASSERT(UV_TTY == uv_guess_handle(ttyin_fd));
r = uv_tty_init(uv_default_loop(), &tty_in, ttyin_fd, 1); /* Readable. */
ASSERT(r == 0);
r = uv_tty_set_mode(&tty_in, UV_TTY_MODE_RAW);
ASSERT(r == 0);
r = uv_read_start((uv_stream_t*)&tty_in, tty_raw_alloc, tty_raw_read);
ASSERT(r == 0);
r = uv_read_stop((uv_stream_t*) &tty_in);
ASSERT(r == 0);
MAKE_VALGRIND_HAPPY();
return 0;
}
#endif #endif
......
...@@ -46,6 +46,7 @@ ...@@ -46,6 +46,7 @@
'test-homedir.c', 'test-homedir.c',
'test-hrtime.c', 'test-hrtime.c',
'test-idle.c', 'test-idle.c',
'test-idna.c',
'test-ip6-addr.c', 'test-ip6-addr.c',
'test-ipc-heavy-traffic-deadlock-bug.c', 'test-ipc-heavy-traffic-deadlock-bug.c',
'test-ipc-send-recv.c', 'test-ipc-send-recv.c',
......
...@@ -70,6 +70,8 @@ ...@@ -70,6 +70,8 @@
'include/uv/version.h', 'include/uv/version.h',
'src/fs-poll.c', 'src/fs-poll.c',
'src/heap-inl.h', 'src/heap-inl.h',
'src/idna.c',
'src/idna.h',
'src/inet.c', 'src/inet.c',
'src/queue.h', 'src/queue.h',
'src/threadpool.c', 'src/threadpool.c',
...@@ -116,7 +118,6 @@ ...@@ -116,7 +118,6 @@
'src/win/poll.c', 'src/win/poll.c',
'src/win/process.c', 'src/win/process.c',
'src/win/process-stdio.c', 'src/win/process-stdio.c',
'src/win/req.c',
'src/win/req-inl.h', 'src/win/req-inl.h',
'src/win/signal.c', 'src/win/signal.c',
'src/win/snprintf.c', 'src/win/snprintf.c',
...@@ -327,7 +328,10 @@ ...@@ -327,7 +328,10 @@
'sources': [ 'src/unix/netbsd.c' ], 'sources': [ 'src/unix/netbsd.c' ],
}], }],
[ 'OS in "freebsd dragonflybsd openbsd netbsd".split()', { [ '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()', { [ 'OS in "ios mac freebsd dragonflybsd openbsd netbsd".split()', {
'sources': [ 'sources': [
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论