Commit 99fe710d authored by Jason Madden's avatar Jason Madden Committed by GitHub

Merge pull request #1164 from gevent/libuv1.19.2

Update to libuv 1.19.2. Fixes #1129.
parents c0b2f147 72b3ab32
...@@ -12,6 +12,8 @@ Dependencies ...@@ -12,6 +12,8 @@ Dependencies
- Cython 0.28.1 is now used to build gevent from a source checkout. - Cython 0.28.1 is now used to build gevent from a source checkout.
- The bundled libuv is now 1.19.2, up from 1.18.0.
Platform Support Platform Support
---------------- ----------------
......
...@@ -321,3 +321,12 @@ Pekka Nikander <pekka.nikander@iki.fi> ...@@ -321,3 +321,12 @@ Pekka Nikander <pekka.nikander@iki.fi>
Ed Schouten <ed@nuxi.nl> Ed Schouten <ed@nuxi.nl>
Xu Meng <mengxumx@cn.ibm.com> Xu Meng <mengxumx@cn.ibm.com>
Matt Harrison <hi@matt-harrison.com> Matt Harrison <hi@matt-harrison.com>
Anna Henningsen <anna@addaleax.net>
Jérémy Lal <kapouer@melix.org>
Ben Wijen <ben@wijen.net>
elephantp <elephantp@elephantp.blog>
Felix Yan <felixonmars@archlinux.org>
Mason X <me@masonx.ca>
Jesse Gorzinski <jgorzinski@gmail.com>
Ryuichi KAWAMATA <ryuichi.kawamata@dena.jp>
Joyee Cheung <joyeec9h3@gmail.com>
2017.12.02, Version 1.18.0 (Stable) 2018.02.22, Version 1.19.2 (Stable)
Changes since version 1.19.1:
* test: fix incorrect asserts (cjihrig)
* test: fix a typo in test-fork.c (Felix Yan)
* build: remove long-obsolete gyp workarounds (Ben Noordhuis)
* build: split off tests into separate gyp file (Ben Noordhuis)
* test: check uv_cond_timedwait more carefully (Jamie Davis)
* include,src: introduce UV__ERR() macro (Mason X)
* build: add url field to libuv.pc (Ben Noordhuis)
* doc: mark IBM i as Tier 3 support (Jesse Gorzinski)
* win,build: correct C2059 errors (Michael Fero)
* zos: fix timeout for condition variable (jBarz)
* win: CREATE_NO_WINDOW when stdio is not inherited (Nick Logan)
* build: fix commmon.gypi comment (Ryuichi KAWAMATA)
* doc: document uv_timer_start() on an active timer (Vladimír Čunát)
* doc: add note about handle movability (Bartosz Sosnowski)
* doc: fix syntax error in loop documentation (Bartosz Sosnowski)
* osx,stream: retry sending handle on EMSGSIZE error (Santiago Gimeno)
* unix: delay fs req register until after validation (cjihrig)
* test: add tests for bad inputs (Joyee Cheung)
* unix,win: ensure req->bufs is freed (cjihrig)
* test: add additional fs memory management checks (cjihrig)
2018.01.20, Version 1.19.1 (Stable), 8202d1751196c2374ad370f7f3779daef89befae
Changes since version 1.19.0:
* Revert "unix,tcp: avoid marking server sockets connected" (Ben Noordhuis)
* Revert "unix,fs: fix for potential partial reads/writes" (Ben Noordhuis)
* Revert "win: use RemoveDirectoryW() instead of _wmrmdir()" (Ben Noordhuis)
* cygwin: fix compilation of ifaddrs impl (Brad King)
2018.01.18, Version 1.19.0 (Stable), effbb7c9d29090b2e085a40867f8cdfa916a66df
Changes since version 1.18.0:
* core: add getter/setter functions for easier ABI compat (Anna Henningsen)
* unix: make get(set)_process_title MT-safe (Matt Harrison)
* unix,win: wait for threads to start (Ben Noordhuis)
* test: add threadpool init/teardown test (Bartosz Sosnowski)
* win, process: uv_kill improvements (Bartosz Sosnowski)
* win: set _WIN32_WINNT to 0x0600 (cjihrig)
* zos: implement uv_fs_event* functions (jBarz)
* unix,tcp: avoid marking server sockets connected (Jameson Nash)
* doc: mark Windows 7 as Tier 1 support (Bartosz Sosnowski)
* win: map 0.0.0.0 and :: addresses to localhost (Bartosz Sosnowski)
* build: install libuv.pc unconditionally (Ben Noordhuis)
* test: remove custom timeout for thread test on ppc (Ben Noordhuis)
* test: allow multicast not permitted status (Jérémy Lal)
* test: allow net unreachable status in udp test (Ben Noordhuis)
* unix: use SA_RESTART when setting our sighandler (Brad King)
* unix,fs: fix for potential partial reads/writes (Ben Wijen)
* win,build: do not build executable installer for dll (Bert Belder)
* win: allow directory symlinks to be created in a non-elevated context (Bert
Belder)
* zos,test: accept SIGKILL for flaky test (jBarz)
* win: use RemoveDirectoryW() instead of _wmrmdir() (Ben Noordhuis)
* unix: fix uv_cpu_info() error on FreeBSD (elephantp)
* zos,test: decrease pings to avoid timeout (jBarz)
2017.12.02, Version 1.18.0 (Stable), 1489c98b7fc17f1702821a269eb0c5e730c5c813
Changes since version 1.17.0: Changes since version 1.17.0:
......
...@@ -29,6 +29,7 @@ libuv_la_SOURCES = src/fs-poll.c \ ...@@ -29,6 +29,7 @@ libuv_la_SOURCES = src/fs-poll.c \
src/inet.c \ src/inet.c \
src/queue.h \ src/queue.h \
src/threadpool.c \ src/threadpool.c \
src/uv-data-getter-setters.c \
src/uv-common.c \ src/uv-common.c \
src/uv-common.h \ src/uv-common.h \
src/version.c src/version.c
...@@ -158,6 +159,7 @@ test_run_tests_SOURCES = test/blackhole-server.c \ ...@@ -158,6 +159,7 @@ test_run_tests_SOURCES = test/blackhole-server.c \
test/test-close-fd.c \ test/test-close-fd.c \
test/test-close-order.c \ test/test-close-order.c \
test/test-condvar.c \ test/test-condvar.c \
test/test-connect-unspecified.c \
test/test-connection-fail.c \ test/test-connection-fail.c \
test/test-cwd-and-chdir.c \ test/test-cwd-and-chdir.c \
test/test-default-loop-close.c \ test/test-default-loop-close.c \
...@@ -174,6 +176,7 @@ test_run_tests_SOURCES = test/blackhole-server.c \ ...@@ -174,6 +176,7 @@ test_run_tests_SOURCES = test/blackhole-server.c \
test/test-fs-poll.c \ test/test-fs-poll.c \
test/test-fs.c \ test/test-fs.c \
test/test-fork.c \ test/test-fork.c \
test/test-getters-setters.c \
test/test-get-currentexe.c \ test/test-get-currentexe.c \
test/test-get-loadavg.c \ test/test-get-loadavg.c \
test/test-get-memory.c \ test/test-get-memory.c \
...@@ -220,6 +223,7 @@ test_run_tests_SOURCES = test/blackhole-server.c \ ...@@ -220,6 +223,7 @@ test_run_tests_SOURCES = test/blackhole-server.c \
test/test-poll-closesocket.c \ test/test-poll-closesocket.c \
test/test-poll-oob.c \ test/test-poll-oob.c \
test/test-process-title.c \ test/test-process-title.c \
test/test-process-title-threadsafe.c \
test/test-queue-foreach-delete.c \ test/test-queue-foreach-delete.c \
test/test-ref.c \ test/test-ref.c \
test/test-run-nowait.c \ test/test-run-nowait.c \
...@@ -455,13 +459,10 @@ libuv_la_CFLAGS += -D_UNIX03_THREADS \ ...@@ -455,13 +459,10 @@ libuv_la_CFLAGS += -D_UNIX03_THREADS \
-qFLOAT=IEEE -qFLOAT=IEEE
libuv_la_LDFLAGS += -qXPLINK libuv_la_LDFLAGS += -qXPLINK
libuv_la_SOURCES += src/unix/pthread-fixes.c \ libuv_la_SOURCES += src/unix/pthread-fixes.c \
src/unix/no-fsevents.c \
src/unix/os390.c \ src/unix/os390.c \
src/unix/os390-syscalls.c \ src/unix/os390-syscalls.c \
src/unix/proctitle.c src/unix/proctitle.c
endif endif
if HAVE_PKG_CONFIG
pkgconfigdir = $(libdir)/pkgconfig pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = @PACKAGE_NAME@.pc pkgconfig_DATA = @PACKAGE_NAME@.pc
endif
...@@ -4,13 +4,14 @@ ...@@ -4,13 +4,14 @@
|---|---|---|---| |---|---|---|---|
| GNU/Linux | Tier 1 | Linux >= 2.6.32 with glibc >= 2.12 | | | GNU/Linux | Tier 1 | Linux >= 2.6.32 with glibc >= 2.12 | |
| macOS | Tier 1 | macOS >= 10.7 | | | macOS | Tier 1 | macOS >= 10.7 | |
| Windows | Tier 1 | Windows >= 8.1 | MSVC 2008 and later are supported | | Windows | Tier 1 | >= Windows 7 | MSVC 2008 and later are supported |
| FreeBSD | Tier 1 | >= 9 (see note) | | | FreeBSD | Tier 1 | >= 9 (see note) | |
| AIX | Tier 2 | >= 6 | Maintainers: @libuv/aix | | AIX | Tier 2 | >= 6 | Maintainers: @libuv/aix |
| z/OS | Tier 2 | >= V2R2 | Maintainers: @libuv/zos | | z/OS | Tier 2 | >= V2R2 | Maintainers: @libuv/zos |
| Linux with musl | Tier 2 | musl >= 1.0 | | | Linux with musl | Tier 2 | musl >= 1.0 | |
| SmartOS | Tier 2 | >= 14.4 | Maintainers: @libuv/smartos | | SmartOS | Tier 2 | >= 14.4 | Maintainers: @libuv/smartos |
| Android | Tier 3 | NDK >= r15b | | | Android | Tier 3 | NDK >= r15b | |
| IBM i | Tier 3 | >= IBM i 7.2 | Maintainers: @libuv/ibmi |
| MinGW | Tier 3 | MinGW32 and MinGW-w64 | | | MinGW | Tier 3 | MinGW32 and MinGW-w64 | |
| SunOS | Tier 3 | Solaris 121 and later | | | SunOS | Tier 3 | Solaris 121 and later | |
| Other | Tier 3 | N/A | | | Other | Tier 3 | N/A | |
......
...@@ -28,12 +28,5 @@ build_script: ...@@ -28,12 +28,5 @@ build_script:
- cmd: set ARCH=%platform% - cmd: set ARCH=%platform%
- cmd: vcbuild.bat release %ARCH% shared - cmd: vcbuild.bat release %ARCH% shared
after_build:
- '"%PROGRAMFILES(x86)%\NSIS\makensis" /DVERSION=%APPVEYOR_BUILD_VERSION% /DARCH=%ARCH% libuv.nsi'
artifacts:
- name: Installer
path: 'libuv-*.exe'
cache: cache:
- C:\projects\libuv\build\gyp - C:\projects\libuv\build\gyp
...@@ -53,6 +53,7 @@ src/unix/tty.c ...@@ -53,6 +53,7 @@ src/unix/tty.c
src/unix/udp.c src/unix/udp.c
src/uv-common.c src/uv-common.c
src/uv-common.h src/uv-common.h
src/uv-data-getter-setters.c
" "
TESTS=" TESTS="
...@@ -100,6 +101,7 @@ test/test-fs-copyfile.c ...@@ -100,6 +101,7 @@ test/test-fs-copyfile.c
test/test-fs-event.c test/test-fs-event.c
test/test-fs-poll.c test/test-fs-poll.c
test/test-fs.c test/test-fs.c
test/test-getters-setters.c
test/test-get-currentexe.c test/test-get-currentexe.c
test/test-get-loadavg.c test/test-get-loadavg.c
test/test-get-memory.c test/test-get-memory.c
...@@ -126,6 +128,7 @@ test/test-platform-output.c ...@@ -126,6 +128,7 @@ test/test-platform-output.c
test/test-poll-close.c test/test-poll-close.c
test/test-poll.c test/test-poll.c
test/test-process-title.c test/test-process-title.c
test/test-process-title-threadsafe.c
test/test-ref.c test/test-ref.c
test/test-run-nowait.c test/test-run-nowait.c
test/test-run-once.c test/test-run-once.c
......
...@@ -16,9 +16,9 @@ ...@@ -16,9 +16,9 @@
'VCCLCompilerTool': { 'VCCLCompilerTool': {
'target_conditions': [ 'target_conditions': [
['uv_library=="static_library"', { ['uv_library=="static_library"', {
'RuntimeLibrary': 1, # static debug 'RuntimeLibrary': 1, # /MTd static debug
}, { }, {
'RuntimeLibrary': 3, # DLL debug 'RuntimeLibrary': 3, # /MDd DLL debug
}], }],
], ],
'Optimization': 0, # /Od, no optimization 'Optimization': 0, # /Od, no optimization
...@@ -52,9 +52,9 @@ ...@@ -52,9 +52,9 @@
'VCCLCompilerTool': { 'VCCLCompilerTool': {
'target_conditions': [ 'target_conditions': [
['uv_library=="static_library"', { ['uv_library=="static_library"', {
'RuntimeLibrary': 0, # static release 'RuntimeLibrary': 0, # /MT static release
}, { }, {
'RuntimeLibrary': 2, # debug release 'RuntimeLibrary': 2, # /MD DLL release
}], }],
], ],
'Optimization': 3, # /Ox, full optimization 'Optimization': 3, # /Ox, full optimization
......
...@@ -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.18.0], [https://github.com/libuv/libuv/issues]) AC_INIT([libuv], [1.19.2], [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])
...@@ -68,10 +68,5 @@ AS_CASE([$host_os],[mingw*], [ ...@@ -68,10 +68,5 @@ AS_CASE([$host_os],[mingw*], [
]) ])
AS_CASE([$host_os], [netbsd*], [AC_CHECK_LIB([kvm], [kvm_open])]) AS_CASE([$host_os], [netbsd*], [AC_CHECK_LIB([kvm], [kvm_open])])
AC_CHECK_HEADERS([sys/ahafs_evProds.h]) AC_CHECK_HEADERS([sys/ahafs_evProds.h])
AC_CHECK_PROG(PKG_CONFIG, pkg-config, yes) AC_CONFIG_FILES([Makefile libuv.pc])
AM_CONDITIONAL([HAVE_PKG_CONFIG], [test "x$PKG_CONFIG" != "x"])
AS_IF([test "x$PKG_CONFIG" != "x"], [
AC_CONFIG_FILES([libuv.pc])
])
AC_CONFIG_FILES([Makefile])
AC_OUTPUT AC_OUTPUT
...@@ -43,28 +43,7 @@ def run_gyp(args): ...@@ -43,28 +43,7 @@ def run_gyp(args):
if __name__ == '__main__': if __name__ == '__main__':
args = sys.argv[1:] args = sys.argv[1:]
args.extend('-I common.gypi test/test.gyp'.split(' '))
# GYP bug.
# On msvs it will crash if it gets an absolute path.
# On Mac/make it will crash if it doesn't get an absolute path.
if sys.platform == 'win32':
args.append(os.path.join(uv_root, 'uv.gyp'))
common_fn = os.path.join(uv_root, 'common.gypi')
options_fn = os.path.join(uv_root, 'options.gypi')
# we force vs 2010 over 2008 which would otherwise be the default for gyp
if not os.environ.get('GYP_MSVS_VERSION'):
os.environ['GYP_MSVS_VERSION'] = '2010'
else:
args.append(os.path.join(os.path.abspath(uv_root), 'uv.gyp'))
common_fn = os.path.join(os.path.abspath(uv_root), 'common.gypi')
options_fn = os.path.join(os.path.abspath(uv_root), 'options.gypi')
if os.path.exists(common_fn):
args.extend(['-I', common_fn])
if os.path.exists(options_fn):
args.extend(['-I', options_fn])
args.append('--depth=' + uv_root) args.append('--depth=' + uv_root)
# There's a bug with windows which doesn't allow this feature. # There's a bug with windows which doesn't allow this feature.
......
This diff is collapsed.
...@@ -27,4 +27,7 @@ ...@@ -27,4 +27,7 @@
#define UV_PLATFORM_LOOP_FIELDS \ #define UV_PLATFORM_LOOP_FIELDS \
void* ep; \ void* ep; \
#define UV_PLATFORM_FS_EVENT_FIELDS \
char rfis_rftok[8]; \
#endif /* UV_MVS_H */ #endif /* UV_MVS_H */
...@@ -31,8 +31,8 @@ ...@@ -31,8 +31,8 @@
*/ */
#define UV_VERSION_MAJOR 1 #define UV_VERSION_MAJOR 1
#define UV_VERSION_MINOR 18 #define UV_VERSION_MINOR 19
#define UV_VERSION_PATCH 0 #define UV_VERSION_PATCH 2
#define UV_VERSION_IS_RELEASE 1 #define UV_VERSION_IS_RELEASE 1
#define UV_VERSION_SUFFIX "" #define UV_VERSION_SUFFIX ""
......
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
*/ */
#ifndef _WIN32_WINNT #ifndef _WIN32_WINNT
# define _WIN32_WINNT 0x0502 # define _WIN32_WINNT 0x0600
#endif #endif
#if !defined(_SSIZE_T_) && !defined(_SSIZE_T_DEFINED) #if !defined(_SSIZE_T_) && !defined(_SSIZE_T_DEFINED)
......
...@@ -425,7 +425,17 @@ struct uv_handle_s { ...@@ -425,7 +425,17 @@ struct uv_handle_s {
}; };
UV_EXTERN size_t uv_handle_size(uv_handle_type type); UV_EXTERN size_t uv_handle_size(uv_handle_type type);
UV_EXTERN uv_handle_type uv_handle_get_type(const uv_handle_t* handle);
UV_EXTERN const char* uv_handle_type_name(uv_handle_type type);
UV_EXTERN void* uv_handle_get_data(const uv_handle_t* handle);
UV_EXTERN uv_loop_t* uv_handle_get_loop(const uv_handle_t* handle);
UV_EXTERN void uv_handle_set_data(uv_handle_t* handle, void* data);
UV_EXTERN size_t uv_req_size(uv_req_type type); UV_EXTERN size_t uv_req_size(uv_req_type type);
UV_EXTERN void* uv_req_get_data(const uv_req_t* req);
UV_EXTERN void uv_req_set_data(uv_req_t* req, void* data);
UV_EXTERN uv_req_type uv_req_get_type(const uv_req_t* req);
UV_EXTERN const char* uv_req_type_name(uv_req_type type);
UV_EXTERN int uv_is_active(const uv_handle_t* handle); UV_EXTERN int uv_is_active(const uv_handle_t* handle);
...@@ -465,6 +475,8 @@ struct uv_stream_s { ...@@ -465,6 +475,8 @@ struct uv_stream_s {
UV_STREAM_FIELDS UV_STREAM_FIELDS
}; };
UV_EXTERN size_t uv_stream_get_write_queue_size(const uv_stream_t* stream);
UV_EXTERN int uv_listen(uv_stream_t* stream, int backlog, uv_connection_cb cb); UV_EXTERN int uv_listen(uv_stream_t* stream, int backlog, uv_connection_cb cb);
UV_EXTERN int uv_accept(uv_stream_t* server, uv_stream_t* client); UV_EXTERN int uv_accept(uv_stream_t* server, uv_stream_t* client);
...@@ -642,6 +654,8 @@ UV_EXTERN int uv_udp_recv_start(uv_udp_t* handle, ...@@ -642,6 +654,8 @@ UV_EXTERN int uv_udp_recv_start(uv_udp_t* handle,
uv_alloc_cb alloc_cb, uv_alloc_cb alloc_cb,
uv_udp_recv_cb recv_cb); uv_udp_recv_cb recv_cb);
UV_EXTERN int uv_udp_recv_stop(uv_udp_t* handle); UV_EXTERN int uv_udp_recv_stop(uv_udp_t* handle);
UV_EXTERN size_t uv_udp_get_send_queue_size(const uv_udp_t* handle);
UV_EXTERN size_t uv_udp_get_send_queue_count(const uv_udp_t* handle);
/* /*
...@@ -962,6 +976,7 @@ UV_EXTERN int uv_spawn(uv_loop_t* loop, ...@@ -962,6 +976,7 @@ UV_EXTERN int uv_spawn(uv_loop_t* loop,
const uv_process_options_t* options); const uv_process_options_t* options);
UV_EXTERN int uv_process_kill(uv_process_t*, int signum); UV_EXTERN int uv_process_kill(uv_process_t*, int signum);
UV_EXTERN int uv_kill(int pid, int signum); UV_EXTERN int uv_kill(int pid, int signum);
UV_EXTERN uv_pid_t uv_process_get_pid(const uv_process_t*);
/* /*
...@@ -1135,6 +1150,12 @@ struct uv_fs_s { ...@@ -1135,6 +1150,12 @@ struct uv_fs_s {
UV_FS_PRIVATE_FIELDS UV_FS_PRIVATE_FIELDS
}; };
UV_EXTERN uv_fs_type uv_fs_get_type(const uv_fs_t*);
UV_EXTERN ssize_t uv_fs_get_result(const uv_fs_t*);
UV_EXTERN void* uv_fs_get_ptr(const uv_fs_t*);
UV_EXTERN const char* uv_fs_get_path(const uv_fs_t*);
UV_EXTERN uv_stat_t* uv_fs_get_statbuf(uv_fs_t*);
UV_EXTERN void uv_fs_req_cleanup(uv_fs_t* req); UV_EXTERN void uv_fs_req_cleanup(uv_fs_t* req);
UV_EXTERN int uv_fs_close(uv_loop_t* loop, UV_EXTERN int uv_fs_close(uv_loop_t* loop,
uv_fs_t* req, uv_fs_t* req,
...@@ -1516,6 +1537,8 @@ struct uv_loop_s { ...@@ -1516,6 +1537,8 @@ struct uv_loop_s {
UV_LOOP_PRIVATE_FIELDS UV_LOOP_PRIVATE_FIELDS
}; };
UV_EXTERN void* uv_loop_get_data(const uv_loop_t*);
UV_EXTERN void uv_loop_set_data(uv_loop_t*, void* data);
/* Don't export the private CPP symbols. */ /* Don't export the private CPP symbols. */
#undef UV_HANDLE_TYPE_PRIVATE #undef UV_HANDLE_TYPE_PRIVATE
...@@ -1536,6 +1559,7 @@ struct uv_loop_s { ...@@ -1536,6 +1559,7 @@ struct uv_loop_s {
#undef UV_SIGNAL_PRIVATE_FIELDS #undef UV_SIGNAL_PRIVATE_FIELDS
#undef UV_LOOP_PRIVATE_FIELDS #undef UV_LOOP_PRIVATE_FIELDS
#undef UV_LOOP_PRIVATE_PLATFORM_FIELDS #undef UV_LOOP_PRIVATE_PLATFORM_FIELDS
#undef UV__ERR
#ifdef __cplusplus #ifdef __cplusplus
} }
......
; NSIS installer script for libuv
!include "MUI2.nsh"
Name "libuv"
OutFile "libuv-${ARCH}-${VERSION}.exe"
!include "x64.nsh"
# Default install location, for 32-bit files
InstallDir "$PROGRAMFILES\libuv"
# Override install and registry locations if this is a 64-bit install.
function .onInit
${If} ${ARCH} == "x64"
SetRegView 64
StrCpy $INSTDIR "$PROGRAMFILES64\libuv"
${EndIf}
functionEnd
;--------------------------------
; Installer pages
!insertmacro MUI_PAGE_WELCOME
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_PAGE_FINISH
;--------------------------------
; Uninstaller pages
!insertmacro MUI_UNPAGE_WELCOME
!insertmacro MUI_UNPAGE_CONFIRM
!insertmacro MUI_UNPAGE_INSTFILES
!insertmacro MUI_UNPAGE_FINISH
;--------------------------------
; Languages
!insertmacro MUI_LANGUAGE "English"
;--------------------------------
; Installer sections
Section "Files" SecInstall
SectionIn RO
SetOutPath "$INSTDIR"
File "Release\*.dll"
File "Release\*.lib"
File "LICENSE"
File "README.md"
SetOutPath "$INSTDIR\include"
File "include\uv.h"
File "include\uv-errno.h"
File "include\uv-threadpool.h"
File "include\uv-version.h"
File "include\uv-win.h"
File "include\tree.h"
WriteUninstaller "$INSTDIR\Uninstall.exe"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\libuv-${ARCH}-${VERSION}" "DisplayName" "libuv-${ARCH}-${VERSION}"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\libuv-${ARCH}-${VERSION}" "UninstallString" "$\"$INSTDIR\Uninstall.exe$\""
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\libuv-${ARCH}-${VERSION}" "QuietUninstallString" "$\"$INSTDIR\Uninstall.exe$\" /S"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\libuv-${ARCH}-${VERSION}" "HelpLink" "http://libuv.org/"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\libuv-${ARCH}-${VERSION}" "URLInfoAbout" "http://libuv.org/"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\libuv-${ARCH}-${VERSION}" "DisplayVersion" "${VERSION}"
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\libuv-${ARCH}-${VERSION}" "NoModify" "1"
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\libuv-${ARCH}-${VERSION}" "NoRepair" "1"
SectionEnd
Section "Uninstall"
Delete "$INSTDIR\libuv.dll"
Delete "$INSTDIR\libuv.lib"
Delete "$INSTDIR\LICENSE"
Delete "$INSTDIR\README.md"
Delete "$INSTDIR\include\uv.h"
Delete "$INSTDIR\include\uv-errno.h"
Delete "$INSTDIR\include\uv-threadpool.h"
Delete "$INSTDIR\include\uv-version.h"
Delete "$INSTDIR\include\uv-win.h"
Delete "$INSTDIR\include\tree.h"
Delete "$INSTDIR\Uninstall.exe"
RMDir "$INSTDIR"
DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\libuv-${ARCH}-${VERSION}"
SectionEnd
...@@ -6,6 +6,7 @@ includedir=@includedir@ ...@@ -6,6 +6,7 @@ includedir=@includedir@
Name: @PACKAGE_NAME@ Name: @PACKAGE_NAME@
Version: @PACKAGE_VERSION@ Version: @PACKAGE_VERSION@
Description: multi-platform support library with a focus on asynchronous I/O. Description: multi-platform support library with a focus on asynchronous I/O.
URL: http://libuv.org/
Libs: -L${libdir} -luv @LIBS@ Libs: -L${libdir} -luv @LIBS@
Cflags: -I${includedir} Cflags: -I${includedir}
...@@ -38,7 +38,6 @@ static uv_thread_t* threads; ...@@ -38,7 +38,6 @@ static uv_thread_t* threads;
static uv_thread_t default_threads[4]; static uv_thread_t default_threads[4];
static QUEUE exit_message; static QUEUE exit_message;
static QUEUE wq; static QUEUE wq;
static volatile int initialized;
static void uv__cancelled(struct uv__work* w) { static void uv__cancelled(struct uv__work* w) {
...@@ -53,7 +52,8 @@ static void worker(void* arg) { ...@@ -53,7 +52,8 @@ static void worker(void* arg) {
struct uv__work* w; struct uv__work* w;
QUEUE* q; QUEUE* q;
(void) arg; uv_sem_post((uv_sem_t*) arg);
arg = NULL;
for (;;) { for (;;) {
uv_mutex_lock(&mutex); uv_mutex_lock(&mutex);
...@@ -105,7 +105,7 @@ static void post(QUEUE* q) { ...@@ -105,7 +105,7 @@ static void post(QUEUE* q) {
UV_DESTRUCTOR(static void cleanup(void)) { UV_DESTRUCTOR(static void cleanup(void)) {
unsigned int i; unsigned int i;
if (initialized == 0) if (nthreads == 0)
return; return;
post(&exit_message); post(&exit_message);
...@@ -122,7 +122,6 @@ UV_DESTRUCTOR(static void cleanup(void)) { ...@@ -122,7 +122,6 @@ UV_DESTRUCTOR(static void cleanup(void)) {
threads = NULL; threads = NULL;
nthreads = 0; nthreads = 0;
initialized = 0;
} }
#endif #endif
...@@ -130,6 +129,7 @@ UV_DESTRUCTOR(static void cleanup(void)) { ...@@ -130,6 +129,7 @@ UV_DESTRUCTOR(static void cleanup(void)) {
static void init_threads(void) { static void init_threads(void) {
unsigned int i; unsigned int i;
const char* val; const char* val;
uv_sem_t sem;
nthreads = ARRAY_SIZE(default_threads); nthreads = ARRAY_SIZE(default_threads);
val = getenv("UV_THREADPOOL_SIZE"); val = getenv("UV_THREADPOOL_SIZE");
...@@ -157,11 +157,17 @@ static void init_threads(void) { ...@@ -157,11 +157,17 @@ static void init_threads(void) {
QUEUE_INIT(&wq); QUEUE_INIT(&wq);
if (uv_sem_init(&sem, 0))
abort();
for (i = 0; i < nthreads; i++) for (i = 0; i < nthreads; i++)
if (uv_thread_create(threads + i, worker, NULL)) if (uv_thread_create(threads + i, worker, &sem))
abort(); abort();
initialized = 1; for (i = 0; i < nthreads; i++)
uv_sem_wait(&sem);
uv_sem_destroy(&sem);
} }
......
...@@ -83,12 +83,12 @@ int uv_exepath(char* buffer, size_t* size) { ...@@ -83,12 +83,12 @@ int uv_exepath(char* buffer, size_t* size) {
struct procsinfo pi; struct procsinfo pi;
if (buffer == NULL || size == NULL || *size == 0) if (buffer == NULL || size == NULL || *size == 0)
return -EINVAL; return UV_EINVAL;
pi.pi_pid = getpid(); pi.pi_pid = getpid();
res = getargs(&pi, sizeof(pi), args, sizeof(args)); res = getargs(&pi, sizeof(pi), args, sizeof(args));
if (res < 0) if (res < 0)
return -EINVAL; return UV_EINVAL;
/* /*
* Possibilities for args: * Possibilities for args:
...@@ -101,7 +101,7 @@ int uv_exepath(char* buffer, size_t* size) { ...@@ -101,7 +101,7 @@ int uv_exepath(char* buffer, size_t* size) {
/* Case i) and ii) absolute or relative paths */ /* Case i) and ii) absolute or relative paths */
if (strchr(args, '/') != NULL) { if (strchr(args, '/') != NULL) {
if (realpath(args, abspath) != abspath) if (realpath(args, abspath) != abspath)
return -errno; return UV__ERR(errno);
abspath_size = strlen(abspath); abspath_size = strlen(abspath);
...@@ -121,11 +121,11 @@ int uv_exepath(char* buffer, size_t* size) { ...@@ -121,11 +121,11 @@ int uv_exepath(char* buffer, size_t* size) {
char *path = getenv("PATH"); char *path = getenv("PATH");
if (path == NULL) if (path == NULL)
return -EINVAL; return UV_EINVAL;
clonedpath = uv__strdup(path); clonedpath = uv__strdup(path);
if (clonedpath == NULL) if (clonedpath == NULL)
return -ENOMEM; return UV_ENOMEM;
token = strtok(clonedpath, ":"); token = strtok(clonedpath, ":");
while (token != NULL) { while (token != NULL) {
...@@ -151,7 +151,7 @@ int uv_exepath(char* buffer, size_t* size) { ...@@ -151,7 +151,7 @@ int uv_exepath(char* buffer, size_t* size) {
uv__free(clonedpath); uv__free(clonedpath);
/* Out of tokens (path entries), and no match found */ /* Out of tokens (path entries), and no match found */
return -EINVAL; return UV_EINVAL;
} }
} }
...@@ -177,19 +177,19 @@ int uv_interface_addresses(uv_interface_address_t** addresses, ...@@ -177,19 +177,19 @@ int uv_interface_addresses(uv_interface_address_t** addresses,
*count = 0; *count = 0;
if (0 > (sockfd = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP))) { if (0 > (sockfd = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP))) {
return -errno; return UV__ERR(errno);
} }
if (ioctl(sockfd, SIOCGSIZIFCONF, &size) == -1) { if (ioctl(sockfd, SIOCGSIZIFCONF, &size) == -1) {
uv__close(sockfd); uv__close(sockfd);
return -errno; return UV__ERR(errno);
} }
ifc.ifc_req = (struct ifreq*)uv__malloc(size); ifc.ifc_req = (struct ifreq*)uv__malloc(size);
ifc.ifc_len = size; ifc.ifc_len = size;
if (ioctl(sockfd, SIOCGIFCONF, &ifc) == -1) { if (ioctl(sockfd, SIOCGIFCONF, &ifc) == -1) {
uv__close(sockfd); uv__close(sockfd);
return -errno; return UV__ERR(errno);
} }
#define ADDR_SIZE(p) MAX((p).sa_len, sizeof(p)) #define ADDR_SIZE(p) MAX((p).sa_len, sizeof(p))
...@@ -208,7 +208,7 @@ int uv_interface_addresses(uv_interface_address_t** addresses, ...@@ -208,7 +208,7 @@ int uv_interface_addresses(uv_interface_address_t** addresses,
memcpy(flg.ifr_name, p->ifr_name, sizeof(flg.ifr_name)); memcpy(flg.ifr_name, p->ifr_name, sizeof(flg.ifr_name));
if (ioctl(sockfd, SIOCGIFFLAGS, &flg) == -1) { if (ioctl(sockfd, SIOCGIFFLAGS, &flg) == -1) {
uv__close(sockfd); uv__close(sockfd);
return -errno; return UV__ERR(errno);
} }
if (!(flg.ifr_flags & IFF_UP && flg.ifr_flags & IFF_RUNNING)) if (!(flg.ifr_flags & IFF_UP && flg.ifr_flags & IFF_RUNNING))
...@@ -221,7 +221,7 @@ int uv_interface_addresses(uv_interface_address_t** addresses, ...@@ -221,7 +221,7 @@ int uv_interface_addresses(uv_interface_address_t** addresses,
*addresses = uv__malloc(*count * sizeof(uv_interface_address_t)); *addresses = uv__malloc(*count * sizeof(uv_interface_address_t));
if (!(*addresses)) { if (!(*addresses)) {
uv__close(sockfd); uv__close(sockfd);
return -ENOMEM; return UV_ENOMEM;
} }
address = *addresses; address = *addresses;
...@@ -240,7 +240,7 @@ int uv_interface_addresses(uv_interface_address_t** addresses, ...@@ -240,7 +240,7 @@ int uv_interface_addresses(uv_interface_address_t** addresses,
memcpy(flg.ifr_name, p->ifr_name, sizeof(flg.ifr_name)); memcpy(flg.ifr_name, p->ifr_name, sizeof(flg.ifr_name));
if (ioctl(sockfd, SIOCGIFFLAGS, &flg) == -1) { if (ioctl(sockfd, SIOCGIFFLAGS, &flg) == -1) {
uv__close(sockfd); uv__close(sockfd);
return -ENOSYS; return UV_ENOSYS;
} }
if (!(flg.ifr_flags & IFF_UP && flg.ifr_flags & IFF_RUNNING)) if (!(flg.ifr_flags & IFF_UP && flg.ifr_flags & IFF_RUNNING))
...@@ -260,7 +260,7 @@ int uv_interface_addresses(uv_interface_address_t** addresses, ...@@ -260,7 +260,7 @@ int uv_interface_addresses(uv_interface_address_t** addresses,
if (ioctl(sockfd, SIOCGIFNETMASK, p) == -1) { if (ioctl(sockfd, SIOCGIFNETMASK, p) == -1) {
uv__close(sockfd); uv__close(sockfd);
return -ENOSYS; return UV_ENOSYS;
} }
if (inet6) if (inet6)
......
...@@ -65,11 +65,18 @@ ...@@ -65,11 +65,18 @@
#define RDWR_BUF_SIZE 4096 #define RDWR_BUF_SIZE 4096
#define EQ(a,b) (strcmp(a,b) == 0) #define EQ(a,b) (strcmp(a,b) == 0)
static uv_mutex_t process_title_mutex;
static uv_once_t process_title_mutex_once = UV_ONCE_INIT;
static void* args_mem = NULL; static void* args_mem = NULL;
static char** process_argv = NULL; static char** process_argv = NULL;
static int process_argc = 0; static int process_argc = 0;
static char* process_title_ptr = NULL; static char* process_title_ptr = NULL;
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) {
loop->fs_fd = -1; loop->fs_fd = -1;
...@@ -112,7 +119,7 @@ int uv__io_check_fd(uv_loop_t* loop, int fd) { ...@@ -112,7 +119,7 @@ int uv__io_check_fd(uv_loop_t* loop, int fd) {
pc.fd = fd; pc.fd = fd;
if (pollset_ctl(loop->backend_fd, &pc, 1)) if (pollset_ctl(loop->backend_fd, &pc, 1))
return -errno; return UV__ERR(errno);
pc.cmd = PS_DELETE; pc.cmd = PS_DELETE;
if (pollset_ctl(loop->backend_fd, &pc, 1)) if (pollset_ctl(loop->backend_fd, &pc, 1))
...@@ -402,22 +409,22 @@ static int uv__is_ahafs_mounted(void){ ...@@ -402,22 +409,22 @@ static int uv__is_ahafs_mounted(void){
p = uv__malloc(siz); p = uv__malloc(siz);
if (p == NULL) if (p == NULL)
return -errno; return UV__ERR(errno);
/* Retrieve all mounted filesystems */ /* Retrieve all mounted filesystems */
rv = mntctl(MCTL_QUERY, siz, (char*)p); rv = mntctl(MCTL_QUERY, siz, (char*)p);
if (rv < 0) if (rv < 0)
return -errno; return UV__ERR(errno);
if (rv == 0) { if (rv == 0) {
/* buffer was not large enough, reallocate to correct size */ /* buffer was not large enough, reallocate to correct size */
siz = *(int*)p; siz = *(int*)p;
uv__free(p); uv__free(p);
p = uv__malloc(siz); p = uv__malloc(siz);
if (p == NULL) if (p == NULL)
return -errno; return UV__ERR(errno);
rv = mntctl(MCTL_QUERY, siz, (char*)p); rv = mntctl(MCTL_QUERY, siz, (char*)p);
if (rv < 0) if (rv < 0)
return -errno; return UV__ERR(errno);
} }
/* Look for dev in filesystems mount info */ /* Look for dev in filesystems mount info */
...@@ -488,7 +495,7 @@ static int uv__make_subdirs_p(const char *filename) { ...@@ -488,7 +495,7 @@ static int uv__make_subdirs_p(const char *filename) {
rc = uv__makedir_p(cmd); rc = uv__makedir_p(cmd);
if (rc == -1 && errno != EEXIST){ if (rc == -1 && errno != EEXIST){
return -errno; return UV__ERR(errno);
} }
return rc; return rc;
...@@ -515,7 +522,7 @@ static int uv__setup_ahafs(const char* filename, int *fd) { ...@@ -515,7 +522,7 @@ static int uv__setup_ahafs(const char* filename, int *fd) {
sprintf(mon_file, "/aha/fs/modFile.monFactory"); sprintf(mon_file, "/aha/fs/modFile.monFactory");
if ((strlen(mon_file) + strlen(filename) + 5) > PATH_MAX) if ((strlen(mon_file) + strlen(filename) + 5) > PATH_MAX)
return -ENAMETOOLONG; return UV_ENAMETOOLONG;
/* Make the necessary subdirectories for the monitor file */ /* Make the necessary subdirectories for the monitor file */
rc = uv__make_subdirs_p(filename); rc = uv__make_subdirs_p(filename);
...@@ -530,7 +537,7 @@ static int uv__setup_ahafs(const char* filename, int *fd) { ...@@ -530,7 +537,7 @@ static int uv__setup_ahafs(const char* filename, int *fd) {
/* Open the monitor file, creating it if necessary */ /* Open the monitor file, creating it if necessary */
*fd = open(mon_file, O_CREAT|O_RDWR); *fd = open(mon_file, O_CREAT|O_RDWR);
if (*fd < 0) if (*fd < 0)
return -errno; return UV__ERR(errno);
/* Write out the monitoring specifications. /* Write out the monitoring specifications.
* In this case, we are monitoring for a state change event type * In this case, we are monitoring for a state change event type
...@@ -551,7 +558,7 @@ static int uv__setup_ahafs(const char* filename, int *fd) { ...@@ -551,7 +558,7 @@ static int uv__setup_ahafs(const char* filename, int *fd) {
rc = write(*fd, mon_file_write_string, strlen(mon_file_write_string)+1); rc = write(*fd, mon_file_write_string, strlen(mon_file_write_string)+1);
if (rc < 0) if (rc < 0)
return -errno; return UV__ERR(errno);
return 0; return 0;
} }
...@@ -709,7 +716,7 @@ int uv_fs_event_init(uv_loop_t* loop, uv_fs_event_t* handle) { ...@@ -709,7 +716,7 @@ int uv_fs_event_init(uv_loop_t* loop, uv_fs_event_t* handle) {
uv__handle_init(loop, (uv_handle_t*)handle, UV_FS_EVENT); uv__handle_init(loop, (uv_handle_t*)handle, UV_FS_EVENT);
return 0; return 0;
#else #else
return -ENOSYS; return UV_ENOSYS;
#endif #endif
} }
...@@ -764,7 +771,7 @@ int uv_fs_event_start(uv_fs_event_t* handle, ...@@ -764,7 +771,7 @@ int uv_fs_event_start(uv_fs_event_t* handle,
return 0; return 0;
#else #else
return -ENOSYS; return UV_ENOSYS;
#endif #endif
} }
...@@ -789,7 +796,7 @@ int uv_fs_event_stop(uv_fs_event_t* handle) { ...@@ -789,7 +796,7 @@ int uv_fs_event_stop(uv_fs_event_t* handle) {
return 0; return 0;
#else #else
return -ENOSYS; return UV_ENOSYS;
#endif #endif
} }
...@@ -854,7 +861,10 @@ int uv_set_process_title(const char* title) { ...@@ -854,7 +861,10 @@ int uv_set_process_title(const char* title) {
*/ */
new_title = uv__strdup(title); new_title = uv__strdup(title);
if (new_title == NULL) if (new_title == NULL)
return -ENOMEM; return UV_ENOMEM;
uv_once(&process_title_mutex_once, init_process_title_mutex_once);
uv_mutex_lock(&process_title_mutex);
/* If this is the first time this is set, /* If this is the first time this is set,
* don't free and set argv[1] to NULL. * don't free and set argv[1] to NULL.
...@@ -868,6 +878,8 @@ int uv_set_process_title(const char* title) { ...@@ -868,6 +878,8 @@ int uv_set_process_title(const char* title) {
if (process_argc > 1) if (process_argc > 1)
process_argv[1] = NULL; process_argv[1] = NULL;
uv_mutex_unlock(&process_title_mutex);
return 0; return 0;
} }
...@@ -876,12 +888,17 @@ int uv_get_process_title(char* buffer, size_t size) { ...@@ -876,12 +888,17 @@ int uv_get_process_title(char* buffer, size_t size) {
size_t len; size_t len;
len = strlen(process_argv[0]); len = strlen(process_argv[0]);
if (buffer == NULL || size == 0) if (buffer == NULL || size == 0)
return -EINVAL; return UV_EINVAL;
else if (size <= len) else if (size <= len)
return -ENOBUFS; return UV_ENOBUFS;
uv_once(&process_title_mutex_once, init_process_title_mutex_once);
uv_mutex_lock(&process_title_mutex);
memcpy(buffer, process_argv[0], len + 1); memcpy(buffer, process_argv[0], len + 1);
uv_mutex_unlock(&process_title_mutex);
return 0; return 0;
} }
...@@ -902,10 +919,10 @@ int uv_resident_set_memory(size_t* rss) { ...@@ -902,10 +919,10 @@ int uv_resident_set_memory(size_t* rss) {
fd = open(pp, O_RDONLY); fd = open(pp, O_RDONLY);
if (fd == -1) if (fd == -1)
return -errno; return UV__ERR(errno);
/* FIXME(bnoordhuis) Handle EINTR. */ /* FIXME(bnoordhuis) Handle EINTR. */
err = -EINVAL; err = UV_EINVAL;
if (read(fd, &psinfo, sizeof(psinfo)) == sizeof(psinfo)) { if (read(fd, &psinfo, sizeof(psinfo)) == sizeof(psinfo)) {
*rss = (size_t)psinfo.pr_rssize * 1024; *rss = (size_t)psinfo.pr_rssize * 1024;
err = 0; err = 0;
...@@ -936,7 +953,7 @@ int uv_uptime(double* uptime) { ...@@ -936,7 +953,7 @@ int uv_uptime(double* uptime) {
endutent(); endutent();
if (boot_time == 0) if (boot_time == 0)
return -ENOSYS; return UV_ENOSYS;
*uptime = time(NULL) - boot_time; *uptime = time(NULL) - boot_time;
return 0; return 0;
...@@ -952,30 +969,30 @@ int uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) { ...@@ -952,30 +969,30 @@ int uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) {
result = perfstat_cpu_total(NULL, &ps_total, sizeof(ps_total), 1); result = perfstat_cpu_total(NULL, &ps_total, sizeof(ps_total), 1);
if (result == -1) { if (result == -1) {
return -ENOSYS; return UV_ENOSYS;
} }
ncpus = result = perfstat_cpu(NULL, NULL, sizeof(perfstat_cpu_t), 0); ncpus = result = perfstat_cpu(NULL, NULL, sizeof(perfstat_cpu_t), 0);
if (result == -1) { if (result == -1) {
return -ENOSYS; return UV_ENOSYS;
} }
ps_cpus = (perfstat_cpu_t*) uv__malloc(ncpus * sizeof(perfstat_cpu_t)); ps_cpus = (perfstat_cpu_t*) uv__malloc(ncpus * sizeof(perfstat_cpu_t));
if (!ps_cpus) { if (!ps_cpus) {
return -ENOMEM; return UV_ENOMEM;
} }
strcpy(cpu_id.name, FIRST_CPU); strcpy(cpu_id.name, FIRST_CPU);
result = perfstat_cpu(&cpu_id, ps_cpus, sizeof(perfstat_cpu_t), ncpus); result = perfstat_cpu(&cpu_id, ps_cpus, sizeof(perfstat_cpu_t), ncpus);
if (result == -1) { if (result == -1) {
uv__free(ps_cpus); uv__free(ps_cpus);
return -ENOSYS; return UV_ENOSYS;
} }
*cpu_infos = (uv_cpu_info_t*) uv__malloc(ncpus * sizeof(uv_cpu_info_t)); *cpu_infos = (uv_cpu_info_t*) uv__malloc(ncpus * sizeof(uv_cpu_info_t));
if (!*cpu_infos) { if (!*cpu_infos) {
uv__free(ps_cpus); uv__free(ps_cpus);
return -ENOMEM; return UV_ENOMEM;
} }
*count = ncpus; *count = ncpus;
......
...@@ -166,7 +166,7 @@ static int uv__async_start(uv_loop_t* loop) { ...@@ -166,7 +166,7 @@ static int uv__async_start(uv_loop_t* loop) {
pipefd[0] = err; pipefd[0] = err;
pipefd[1] = -1; pipefd[1] = -1;
} }
else if (err == -ENOSYS) { else if (err == UV_ENOSYS) {
err = uv__make_pipe(pipefd, UV__F_NONBLOCK); err = uv__make_pipe(pipefd, UV__F_NONBLOCK);
#if defined(__linux__) #if defined(__linux__)
/* Save a file descriptor by opening one of the pipe descriptors as /* Save a file descriptor by opening one of the pipe descriptors as
...@@ -240,7 +240,7 @@ static int uv__async_eventfd(void) { ...@@ -240,7 +240,7 @@ static int uv__async_eventfd(void) {
return fd; return fd;
if (errno != ENOSYS) if (errno != ENOSYS)
return -errno; return UV__ERR(errno);
no_eventfd2 = 1; no_eventfd2 = 1;
...@@ -257,7 +257,7 @@ skip_eventfd2: ...@@ -257,7 +257,7 @@ skip_eventfd2:
} }
if (errno != ENOSYS) if (errno != ENOSYS)
return -errno; return UV__ERR(errno);
no_eventfd = 1; no_eventfd = 1;
...@@ -265,5 +265,5 @@ skip_eventfd: ...@@ -265,5 +265,5 @@ skip_eventfd:
#endif #endif
return -ENOSYS; return UV_ENOSYS;
} }
...@@ -36,6 +36,7 @@ static int uv__ifaddr_exclude(struct ifaddrs *ent, int exclude_type) { ...@@ -36,6 +36,7 @@ static int uv__ifaddr_exclude(struct ifaddrs *ent, int exclude_type) {
return 1; return 1;
if (ent->ifa_addr == NULL) if (ent->ifa_addr == NULL)
return 1; return 1;
#if !defined(__CYGWIN__) && !defined(__MSYS__)
/* /*
* If `exclude_type` is `UV__EXCLUDE_IFPHYS`, just see whether `sa_family` * If `exclude_type` is `UV__EXCLUDE_IFPHYS`, just see whether `sa_family`
* equals to `AF_LINK` or not. Otherwise, the result depends on the operation * equals to `AF_LINK` or not. Otherwise, the result depends on the operation
...@@ -43,6 +44,7 @@ static int uv__ifaddr_exclude(struct ifaddrs *ent, int exclude_type) { ...@@ -43,6 +44,7 @@ static int uv__ifaddr_exclude(struct ifaddrs *ent, int exclude_type) {
*/ */
if (exclude_type == UV__EXCLUDE_IFPHYS) if (exclude_type == UV__EXCLUDE_IFPHYS)
return (ent->ifa_addr->sa_family != AF_LINK); return (ent->ifa_addr->sa_family != AF_LINK);
#endif
#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__DragonFly__) #if defined(__APPLE__) || defined(__FreeBSD__) || defined(__DragonFly__)
/* /*
* On BSD getifaddrs returns information related to the raw underlying * On BSD getifaddrs returns information related to the raw underlying
...@@ -68,7 +70,7 @@ int uv_interface_addresses(uv_interface_address_t** addresses, int* count) { ...@@ -68,7 +70,7 @@ int uv_interface_addresses(uv_interface_address_t** addresses, int* count) {
int i; int i;
if (getifaddrs(&addrs) != 0) if (getifaddrs(&addrs) != 0)
return -errno; return UV__ERR(errno);
*count = 0; *count = 0;
...@@ -83,7 +85,7 @@ int uv_interface_addresses(uv_interface_address_t** addresses, int* count) { ...@@ -83,7 +85,7 @@ int uv_interface_addresses(uv_interface_address_t** addresses, int* count) {
if (*addresses == NULL) { if (*addresses == NULL) {
freeifaddrs(addrs); freeifaddrs(addrs);
return -ENOMEM; return UV_ENOMEM;
} }
address = *addresses; address = *addresses;
......
...@@ -191,14 +191,14 @@ int uv__socket_sockopt(uv_handle_t* handle, int optname, int* value) { ...@@ -191,14 +191,14 @@ int uv__socket_sockopt(uv_handle_t* handle, int optname, int* value) {
socklen_t len; socklen_t len;
if (handle == NULL || value == NULL) if (handle == NULL || value == NULL)
return -EINVAL; return UV_EINVAL;
if (handle->type == UV_TCP || handle->type == UV_NAMED_PIPE) if (handle->type == UV_TCP || handle->type == UV_NAMED_PIPE)
fd = uv__stream_fd((uv_stream_t*) handle); fd = uv__stream_fd((uv_stream_t*) handle);
else if (handle->type == UV_UDP) else if (handle->type == UV_UDP)
fd = ((uv_udp_t *) handle)->io_watcher.fd; fd = ((uv_udp_t *) handle)->io_watcher.fd;
else else
return -ENOTSUP; return UV_ENOTSUP;
len = sizeof(*value); len = sizeof(*value);
...@@ -208,7 +208,7 @@ int uv__socket_sockopt(uv_handle_t* handle, int optname, int* value) { ...@@ -208,7 +208,7 @@ int uv__socket_sockopt(uv_handle_t* handle, int optname, int* value) {
r = setsockopt(fd, SOL_SOCKET, optname, (const void*) value, len); r = setsockopt(fd, SOL_SOCKET, optname, (const void*) value, len);
if (r < 0) if (r < 0)
return -errno; return UV__ERR(errno);
return 0; return 0;
} }
...@@ -418,12 +418,12 @@ int uv__socket(int domain, int type, int protocol) { ...@@ -418,12 +418,12 @@ int uv__socket(int domain, int type, int protocol) {
return sockfd; return sockfd;
if (errno != EINVAL) if (errno != EINVAL)
return -errno; return UV__ERR(errno);
#endif #endif
sockfd = socket(domain, type, protocol); sockfd = socket(domain, type, protocol);
if (sockfd == -1) if (sockfd == -1)
return -errno; return UV__ERR(errno);
err = uv__nonblock(sockfd, 1); err = uv__nonblock(sockfd, 1);
if (err == 0) if (err == 0)
...@@ -487,7 +487,7 @@ int uv__accept(int sockfd) { ...@@ -487,7 +487,7 @@ int uv__accept(int sockfd) {
continue; continue;
if (errno != ENOSYS) if (errno != ENOSYS)
return -errno; return UV__ERR(errno);
no_accept4 = 1; no_accept4 = 1;
skip: skip:
...@@ -497,7 +497,7 @@ skip: ...@@ -497,7 +497,7 @@ skip:
if (peerfd == -1) { if (peerfd == -1) {
if (errno == EINTR) if (errno == EINTR)
continue; continue;
return -errno; return UV__ERR(errno);
} }
err = uv__cloexec(peerfd, 1); err = uv__cloexec(peerfd, 1);
...@@ -523,8 +523,8 @@ int uv__close_nocheckstdio(int fd) { ...@@ -523,8 +523,8 @@ int uv__close_nocheckstdio(int fd) {
saved_errno = errno; saved_errno = errno;
rc = close(fd); rc = close(fd);
if (rc == -1) { if (rc == -1) {
rc = -errno; rc = UV__ERR(errno);
if (rc == -EINTR || rc == -EINPROGRESS) if (rc == UV_EINTR || rc == UV__ERR(EINPROGRESS))
rc = 0; /* The close is in progress, not an error. */ rc = 0; /* The close is in progress, not an error. */
errno = saved_errno; errno = saved_errno;
} }
...@@ -550,7 +550,7 @@ int uv__nonblock_ioctl(int fd, int set) { ...@@ -550,7 +550,7 @@ int uv__nonblock_ioctl(int fd, int set) {
while (r == -1 && errno == EINTR); while (r == -1 && errno == EINTR);
if (r) if (r)
return -errno; return UV__ERR(errno);
return 0; return 0;
} }
...@@ -565,7 +565,7 @@ int uv__cloexec_ioctl(int fd, int set) { ...@@ -565,7 +565,7 @@ int uv__cloexec_ioctl(int fd, int set) {
while (r == -1 && errno == EINTR); while (r == -1 && errno == EINTR);
if (r) if (r)
return -errno; return UV__ERR(errno);
return 0; return 0;
} }
...@@ -581,7 +581,7 @@ int uv__nonblock_fcntl(int fd, int set) { ...@@ -581,7 +581,7 @@ int uv__nonblock_fcntl(int fd, int set) {
while (r == -1 && errno == EINTR); while (r == -1 && errno == EINTR);
if (r == -1) if (r == -1)
return -errno; return UV__ERR(errno);
/* Bail out now if already set/clear. */ /* Bail out now if already set/clear. */
if (!!(r & O_NONBLOCK) == !!set) if (!!(r & O_NONBLOCK) == !!set)
...@@ -597,7 +597,7 @@ int uv__nonblock_fcntl(int fd, int set) { ...@@ -597,7 +597,7 @@ int uv__nonblock_fcntl(int fd, int set) {
while (r == -1 && errno == EINTR); while (r == -1 && errno == EINTR);
if (r) if (r)
return -errno; return UV__ERR(errno);
return 0; return 0;
} }
...@@ -612,7 +612,7 @@ int uv__cloexec_fcntl(int fd, int set) { ...@@ -612,7 +612,7 @@ int uv__cloexec_fcntl(int fd, int set) {
while (r == -1 && errno == EINTR); while (r == -1 && errno == EINTR);
if (r == -1) if (r == -1)
return -errno; return UV__ERR(errno);
/* Bail out now if already set/clear. */ /* Bail out now if already set/clear. */
if (!!(r & FD_CLOEXEC) == !!set) if (!!(r & FD_CLOEXEC) == !!set)
...@@ -628,7 +628,7 @@ int uv__cloexec_fcntl(int fd, int set) { ...@@ -628,7 +628,7 @@ int uv__cloexec_fcntl(int fd, int set) {
while (r == -1 && errno == EINTR); while (r == -1 && errno == EINTR);
if (r) if (r)
return -errno; return UV__ERR(errno);
return 0; return 0;
} }
...@@ -643,7 +643,7 @@ int uv__dup(int fd) { ...@@ -643,7 +643,7 @@ int uv__dup(int fd) {
fd = dup(fd); fd = dup(fd);
if (fd == -1) if (fd == -1)
return -errno; return UV__ERR(errno);
err = uv__cloexec(fd, 1); err = uv__cloexec(fd, 1);
if (err) { if (err) {
...@@ -667,10 +667,10 @@ ssize_t uv__recvmsg(int fd, struct msghdr* msg, int flags) { ...@@ -667,10 +667,10 @@ ssize_t uv__recvmsg(int fd, struct msghdr* msg, int flags) {
if (rc != -1) if (rc != -1)
return rc; return rc;
if (errno != EINVAL) if (errno != EINVAL)
return -errno; return UV__ERR(errno);
rc = recvmsg(fd, msg, flags); rc = recvmsg(fd, msg, flags);
if (rc == -1) if (rc == -1)
return -errno; return UV__ERR(errno);
no_msg_cmsg_cloexec = 1; no_msg_cmsg_cloexec = 1;
} else { } else {
rc = recvmsg(fd, msg, flags); rc = recvmsg(fd, msg, flags);
...@@ -679,7 +679,7 @@ ssize_t uv__recvmsg(int fd, struct msghdr* msg, int flags) { ...@@ -679,7 +679,7 @@ ssize_t uv__recvmsg(int fd, struct msghdr* msg, int flags) {
rc = recvmsg(fd, msg, flags); rc = recvmsg(fd, msg, flags);
#endif #endif
if (rc == -1) if (rc == -1)
return -errno; return UV__ERR(errno);
if (msg->msg_controllen == 0) if (msg->msg_controllen == 0)
return rc; return rc;
for (cmsg = CMSG_FIRSTHDR(msg); cmsg != NULL; cmsg = CMSG_NXTHDR(msg, cmsg)) for (cmsg = CMSG_FIRSTHDR(msg); cmsg != NULL; cmsg = CMSG_NXTHDR(msg, cmsg))
...@@ -695,10 +695,10 @@ ssize_t uv__recvmsg(int fd, struct msghdr* msg, int flags) { ...@@ -695,10 +695,10 @@ ssize_t uv__recvmsg(int fd, struct msghdr* msg, int flags) {
int uv_cwd(char* buffer, size_t* size) { int uv_cwd(char* buffer, size_t* size) {
if (buffer == NULL || size == NULL) if (buffer == NULL || size == NULL)
return -EINVAL; return UV_EINVAL;
if (getcwd(buffer, *size) == NULL) if (getcwd(buffer, *size) == NULL)
return -errno; return UV__ERR(errno);
*size = strlen(buffer); *size = strlen(buffer);
if (*size > 1 && buffer[*size - 1] == '/') { if (*size > 1 && buffer[*size - 1] == '/') {
...@@ -712,7 +712,7 @@ int uv_cwd(char* buffer, size_t* size) { ...@@ -712,7 +712,7 @@ int uv_cwd(char* buffer, size_t* size) {
int uv_chdir(const char* dir) { int uv_chdir(const char* dir) {
if (chdir(dir)) if (chdir(dir))
return -errno; return UV__ERR(errno);
return 0; return 0;
} }
...@@ -749,11 +749,11 @@ int uv_fileno(const uv_handle_t* handle, uv_os_fd_t* fd) { ...@@ -749,11 +749,11 @@ int uv_fileno(const uv_handle_t* handle, uv_os_fd_t* fd) {
break; break;
default: default:
return -EINVAL; return UV_EINVAL;
} }
if (uv__is_closing(handle) || fd_out == -1) if (uv__is_closing(handle) || fd_out == -1)
return -EBADF; return UV_EBADF;
*fd = fd_out; *fd = fd_out;
return 0; return 0;
...@@ -931,7 +931,7 @@ int uv_getrusage(uv_rusage_t* rusage) { ...@@ -931,7 +931,7 @@ int uv_getrusage(uv_rusage_t* rusage) {
struct rusage usage; struct rusage usage;
if (getrusage(RUSAGE_SELF, &usage)) if (getrusage(RUSAGE_SELF, &usage))
return -errno; return UV__ERR(errno);
rusage->ru_utime.tv_sec = usage.ru_utime.tv_sec; rusage->ru_utime.tv_sec = usage.ru_utime.tv_sec;
rusage->ru_utime.tv_usec = usage.ru_utime.tv_usec; rusage->ru_utime.tv_usec = usage.ru_utime.tv_usec;
...@@ -973,7 +973,7 @@ int uv__open_cloexec(const char* path, int flags) { ...@@ -973,7 +973,7 @@ int uv__open_cloexec(const char* path, int flags) {
return fd; return fd;
if (errno != EINVAL) if (errno != EINVAL)
return -errno; return UV__ERR(errno);
/* O_CLOEXEC not supported. */ /* O_CLOEXEC not supported. */
no_cloexec = 1; no_cloexec = 1;
...@@ -982,7 +982,7 @@ int uv__open_cloexec(const char* path, int flags) { ...@@ -982,7 +982,7 @@ int uv__open_cloexec(const char* path, int flags) {
fd = open(path, flags); fd = open(path, flags);
if (fd == -1) if (fd == -1)
return -errno; return UV__ERR(errno);
err = uv__cloexec(fd, 1); err = uv__cloexec(fd, 1);
if (err) { if (err) {
...@@ -999,14 +999,14 @@ int uv__dup2_cloexec(int oldfd, int newfd) { ...@@ -999,14 +999,14 @@ int uv__dup2_cloexec(int oldfd, int newfd) {
#if (defined(__FreeBSD__) && __FreeBSD__ >= 10) || defined(__NetBSD__) #if (defined(__FreeBSD__) && __FreeBSD__ >= 10) || defined(__NetBSD__)
r = dup3(oldfd, newfd, O_CLOEXEC); r = dup3(oldfd, newfd, O_CLOEXEC);
if (r == -1) if (r == -1)
return -errno; return UV__ERR(errno);
return r; return r;
#elif defined(__FreeBSD__) && defined(F_DUP2FD_CLOEXEC) #elif defined(__FreeBSD__) && defined(F_DUP2FD_CLOEXEC)
r = fcntl(oldfd, F_DUP2FD_CLOEXEC, newfd); r = fcntl(oldfd, F_DUP2FD_CLOEXEC, newfd);
if (r != -1) if (r != -1)
return r; return r;
if (errno != EINVAL) if (errno != EINVAL)
return -errno; return UV__ERR(errno);
/* Fall through. */ /* Fall through. */
#elif defined(__linux__) #elif defined(__linux__)
static int no_dup3; static int no_dup3;
...@@ -1017,7 +1017,7 @@ int uv__dup2_cloexec(int oldfd, int newfd) { ...@@ -1017,7 +1017,7 @@ int uv__dup2_cloexec(int oldfd, int newfd) {
if (r != -1) if (r != -1)
return r; return r;
if (errno != ENOSYS) if (errno != ENOSYS)
return -errno; return UV__ERR(errno);
/* Fall through. */ /* Fall through. */
no_dup3 = 1; no_dup3 = 1;
} }
...@@ -1033,7 +1033,7 @@ int uv__dup2_cloexec(int oldfd, int newfd) { ...@@ -1033,7 +1033,7 @@ int uv__dup2_cloexec(int oldfd, int newfd) {
#endif #endif
if (r == -1) if (r == -1)
return -errno; return UV__ERR(errno);
err = uv__cloexec(newfd, 1); err = uv__cloexec(newfd, 1);
if (err) { if (err) {
...@@ -1053,7 +1053,7 @@ int uv_os_homedir(char* buffer, size_t* size) { ...@@ -1053,7 +1053,7 @@ int uv_os_homedir(char* buffer, size_t* size) {
int r; int r;
if (buffer == NULL || size == NULL || *size == 0) if (buffer == NULL || size == NULL || *size == 0)
return -EINVAL; return UV_EINVAL;
/* Check if the HOME environment variable is set first */ /* Check if the HOME environment variable is set first */
buf = getenv("HOME"); buf = getenv("HOME");
...@@ -1063,7 +1063,7 @@ int uv_os_homedir(char* buffer, size_t* size) { ...@@ -1063,7 +1063,7 @@ int uv_os_homedir(char* buffer, size_t* size) {
if (len >= *size) { if (len >= *size) {
*size = len + 1; *size = len + 1;
return -ENOBUFS; return UV_ENOBUFS;
} }
memcpy(buffer, buf, len + 1); memcpy(buffer, buf, len + 1);
...@@ -1084,7 +1084,7 @@ int uv_os_homedir(char* buffer, size_t* size) { ...@@ -1084,7 +1084,7 @@ int uv_os_homedir(char* buffer, size_t* size) {
if (len >= *size) { if (len >= *size) {
*size = len + 1; *size = len + 1;
uv_os_free_passwd(&pwd); uv_os_free_passwd(&pwd);
return -ENOBUFS; return UV_ENOBUFS;
} }
memcpy(buffer, pwd.homedir, len + 1); memcpy(buffer, pwd.homedir, len + 1);
...@@ -1100,7 +1100,7 @@ int uv_os_tmpdir(char* buffer, size_t* size) { ...@@ -1100,7 +1100,7 @@ int uv_os_tmpdir(char* buffer, size_t* size) {
size_t len; size_t len;
if (buffer == NULL || size == NULL || *size == 0) if (buffer == NULL || size == NULL || *size == 0)
return -EINVAL; return UV_EINVAL;
#define CHECK_ENV_VAR(name) \ #define CHECK_ENV_VAR(name) \
do { \ do { \
...@@ -1130,7 +1130,7 @@ return_buffer: ...@@ -1130,7 +1130,7 @@ return_buffer:
if (len >= *size) { if (len >= *size) {
*size = len + 1; *size = len + 1;
return -ENOBUFS; return UV_ENOBUFS;
} }
/* The returned directory should not have a trailing slash. */ /* The returned directory should not have a trailing slash. */
...@@ -1162,11 +1162,11 @@ int uv__getpwuid_r(uv_passwd_t* pwd) { ...@@ -1162,11 +1162,11 @@ int uv__getpwuid_r(uv_passwd_t* pwd) {
getpwuid_r = dlsym(RTLD_DEFAULT, "getpwuid_r"); getpwuid_r = dlsym(RTLD_DEFAULT, "getpwuid_r");
if (getpwuid_r == NULL) if (getpwuid_r == NULL)
return -ENOSYS; return UV_ENOSYS;
#endif #endif
if (pwd == NULL) if (pwd == NULL)
return -EINVAL; return UV_EINVAL;
initsize = sysconf(_SC_GETPW_R_SIZE_MAX); initsize = sysconf(_SC_GETPW_R_SIZE_MAX);
...@@ -1183,7 +1183,7 @@ int uv__getpwuid_r(uv_passwd_t* pwd) { ...@@ -1183,7 +1183,7 @@ int uv__getpwuid_r(uv_passwd_t* pwd) {
buf = uv__malloc(bufsize); buf = uv__malloc(bufsize);
if (buf == NULL) if (buf == NULL)
return -ENOMEM; return UV_ENOMEM;
r = getpwuid_r(uid, &pw, buf, bufsize, &result); r = getpwuid_r(uid, &pw, buf, bufsize, &result);
...@@ -1200,7 +1200,7 @@ int uv__getpwuid_r(uv_passwd_t* pwd) { ...@@ -1200,7 +1200,7 @@ int uv__getpwuid_r(uv_passwd_t* pwd) {
if (result == NULL) { if (result == NULL) {
uv__free(buf); uv__free(buf);
return -ENOENT; return UV_ENOENT;
} }
/* Allocate memory for the username, shell, and home directory */ /* Allocate memory for the username, shell, and home directory */
...@@ -1211,7 +1211,7 @@ int uv__getpwuid_r(uv_passwd_t* pwd) { ...@@ -1211,7 +1211,7 @@ int uv__getpwuid_r(uv_passwd_t* pwd) {
if (pwd->username == NULL) { if (pwd->username == NULL) {
uv__free(buf); uv__free(buf);
return -ENOMEM; return UV_ENOMEM;
} }
/* Copy the username */ /* Copy the username */
...@@ -1267,18 +1267,18 @@ int uv_os_getenv(const char* name, char* buffer, size_t* size) { ...@@ -1267,18 +1267,18 @@ int uv_os_getenv(const char* name, char* buffer, size_t* size) {
size_t len; size_t len;
if (name == NULL || buffer == NULL || size == NULL || *size == 0) if (name == NULL || buffer == NULL || size == NULL || *size == 0)
return -EINVAL; return UV_EINVAL;
var = getenv(name); var = getenv(name);
if (var == NULL) if (var == NULL)
return -ENOENT; return UV_ENOENT;
len = strlen(var); len = strlen(var);
if (len >= *size) { if (len >= *size) {
*size = len + 1; *size = len + 1;
return -ENOBUFS; return UV_ENOBUFS;
} }
memcpy(buffer, var, len + 1); memcpy(buffer, var, len + 1);
...@@ -1290,10 +1290,10 @@ int uv_os_getenv(const char* name, char* buffer, size_t* size) { ...@@ -1290,10 +1290,10 @@ int uv_os_getenv(const char* name, char* buffer, size_t* size) {
int uv_os_setenv(const char* name, const char* value) { int uv_os_setenv(const char* name, const char* value) {
if (name == NULL || value == NULL) if (name == NULL || value == NULL)
return -EINVAL; return UV_EINVAL;
if (setenv(name, value, 1) != 0) if (setenv(name, value, 1) != 0)
return -errno; return UV__ERR(errno);
return 0; return 0;
} }
...@@ -1301,10 +1301,10 @@ int uv_os_setenv(const char* name, const char* value) { ...@@ -1301,10 +1301,10 @@ int uv_os_setenv(const char* name, const char* value) {
int uv_os_unsetenv(const char* name) { int uv_os_unsetenv(const char* name) {
if (name == NULL) if (name == NULL)
return -EINVAL; return UV_EINVAL;
if (unsetenv(name) != 0) if (unsetenv(name) != 0)
return -errno; return UV__ERR(errno);
return 0; return 0;
} }
...@@ -1321,17 +1321,17 @@ int uv_os_gethostname(char* buffer, size_t* size) { ...@@ -1321,17 +1321,17 @@ int uv_os_gethostname(char* buffer, size_t* size) {
size_t len; size_t len;
if (buffer == NULL || size == NULL || *size == 0) if (buffer == NULL || size == NULL || *size == 0)
return -EINVAL; return UV_EINVAL;
if (gethostname(buf, sizeof(buf)) != 0) if (gethostname(buf, sizeof(buf)) != 0)
return -errno; return UV__ERR(errno);
buf[sizeof(buf) - 1] = '\0'; /* Null terminate, just to be safe. */ buf[sizeof(buf) - 1] = '\0'; /* Null terminate, just to be safe. */
len = strlen(buf); len = strlen(buf);
if (len >= *size) { if (len >= *size) {
*size = len + 1; *size = len + 1;
return -ENOBUFS; return UV_ENOBUFS;
} }
memcpy(buffer, buf, len + 1); memcpy(buffer, buf, len + 1);
......
...@@ -29,7 +29,7 @@ int uv_uptime(double* uptime) { ...@@ -29,7 +29,7 @@ int uv_uptime(double* uptime) {
struct sysinfo info; struct sysinfo info;
if (sysinfo(&info) < 0) if (sysinfo(&info) < 0)
return -errno; return UV__ERR(errno);
*uptime = info.uptime; *uptime = info.uptime;
return 0; return 0;
......
...@@ -18,6 +18,9 @@ ...@@ -18,6 +18,9 @@
* IN THE SOFTWARE. * IN THE SOFTWARE.
*/ */
#include "uv.h"
#include "internal.h"
#include <dlfcn.h> #include <dlfcn.h>
#include <errno.h> #include <errno.h>
#include <stdlib.h> #include <stdlib.h>
...@@ -41,14 +44,14 @@ static int uv__pthread_setname_np(const char* name) { ...@@ -41,14 +44,14 @@ static int uv__pthread_setname_np(const char* name) {
dlsym(RTLD_DEFAULT, "pthread_setname_np"); dlsym(RTLD_DEFAULT, "pthread_setname_np");
if (dynamic_pthread_setname_np == NULL) if (dynamic_pthread_setname_np == NULL)
return -ENOSYS; return UV_ENOSYS;
strncpy(namebuf, name, sizeof(namebuf) - 1); strncpy(namebuf, name, sizeof(namebuf) - 1);
namebuf[sizeof(namebuf) - 1] = '\0'; namebuf[sizeof(namebuf) - 1] = '\0';
err = dynamic_pthread_setname_np(namebuf); err = dynamic_pthread_setname_np(namebuf);
if (err) if (err)
return -err; return UV__ERR(err);
return 0; return 0;
} }
...@@ -84,7 +87,7 @@ int uv__set_process_title(const char* title) { ...@@ -84,7 +87,7 @@ int uv__set_process_title(const char* title) {
CFTypeRef asn; CFTypeRef asn;
int err; int err;
err = -ENOENT; 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",
...@@ -151,7 +154,7 @@ int uv__set_process_title(const char* title) { ...@@ -151,7 +154,7 @@ int uv__set_process_title(const char* title) {
/* 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 = -ENOENT; err = UV_ENOENT;
if (hi_services_bundle == NULL) if (hi_services_bundle == NULL)
goto out; goto out;
...@@ -182,7 +185,7 @@ int uv__set_process_title(const char* title) { ...@@ -182,7 +185,7 @@ int uv__set_process_title(const char* title) {
asn = pLSGetCurrentApplicationASN(); asn = pLSGetCurrentApplicationASN();
err = -EINVAL; err = UV_EINVAL;
if (pLSSetApplicationInformationItem(-2, /* Magic value. */ if (pLSSetApplicationInformationItem(-2, /* Magic value. */
asn, asn,
*display_name_key, *display_name_key,
......
...@@ -37,7 +37,7 @@ int uv__platform_loop_init(uv_loop_t* loop) { ...@@ -37,7 +37,7 @@ int uv__platform_loop_init(uv_loop_t* loop) {
loop->cf_state = NULL; loop->cf_state = NULL;
if (uv__kqueue_init(loop)) if (uv__kqueue_init(loop))
return -errno; return UV__ERR(errno);
return 0; return 0;
} }
...@@ -68,18 +68,18 @@ int uv_exepath(char* buffer, size_t* size) { ...@@ -68,18 +68,18 @@ int uv_exepath(char* buffer, size_t* size) {
size_t abspath_size; size_t abspath_size;
if (buffer == NULL || size == NULL || *size == 0) if (buffer == NULL || size == NULL || *size == 0)
return -EINVAL; return UV_EINVAL;
exepath_size = sizeof(exepath); exepath_size = sizeof(exepath);
if (_NSGetExecutablePath(exepath, &exepath_size)) if (_NSGetExecutablePath(exepath, &exepath_size))
return -EIO; return UV_EIO;
if (realpath(exepath, abspath) != abspath) if (realpath(exepath, abspath) != abspath)
return -errno; return UV__ERR(errno);
abspath_size = strlen(abspath); abspath_size = strlen(abspath);
if (abspath_size == 0) if (abspath_size == 0)
return -EIO; return UV_EIO;
*size -= 1; *size -= 1;
if (*size > abspath_size) if (*size > abspath_size)
...@@ -98,7 +98,7 @@ uint64_t uv_get_free_memory(void) { ...@@ -98,7 +98,7 @@ uint64_t uv_get_free_memory(void) {
if (host_statistics(mach_host_self(), HOST_VM_INFO, if (host_statistics(mach_host_self(), HOST_VM_INFO,
(host_info_t)&info, &count) != KERN_SUCCESS) { (host_info_t)&info, &count) != KERN_SUCCESS) {
return -EINVAL; /* FIXME(bnoordhuis) Translate error. */ return UV_EINVAL; /* FIXME(bnoordhuis) Translate error. */
} }
return (uint64_t) info.free_count * sysconf(_SC_PAGESIZE); return (uint64_t) info.free_count * sysconf(_SC_PAGESIZE);
...@@ -111,7 +111,7 @@ uint64_t uv_get_total_memory(void) { ...@@ -111,7 +111,7 @@ uint64_t uv_get_total_memory(void) {
size_t size = sizeof(info); size_t size = sizeof(info);
if (sysctl(which, 2, &info, &size, NULL, 0)) if (sysctl(which, 2, &info, &size, NULL, 0))
return -errno; return UV__ERR(errno);
return (uint64_t) info; return (uint64_t) info;
} }
...@@ -158,7 +158,7 @@ int uv_uptime(double* uptime) { ...@@ -158,7 +158,7 @@ int uv_uptime(double* uptime) {
static int which[] = {CTL_KERN, KERN_BOOTTIME}; static int which[] = {CTL_KERN, KERN_BOOTTIME};
if (sysctl(which, 2, &info, &size, NULL, 0)) if (sysctl(which, 2, &info, &size, NULL, 0))
return -errno; return UV__ERR(errno);
now = time(NULL); now = time(NULL);
*uptime = now - info.tv_sec; *uptime = now - info.tv_sec;
...@@ -181,23 +181,23 @@ int uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) { ...@@ -181,23 +181,23 @@ int uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) {
size = sizeof(model); size = sizeof(model);
if (sysctlbyname("machdep.cpu.brand_string", &model, &size, NULL, 0) && if (sysctlbyname("machdep.cpu.brand_string", &model, &size, NULL, 0) &&
sysctlbyname("hw.model", &model, &size, NULL, 0)) { sysctlbyname("hw.model", &model, &size, NULL, 0)) {
return -errno; return UV__ERR(errno);
} }
size = sizeof(cpuspeed); size = sizeof(cpuspeed);
if (sysctlbyname("hw.cpufrequency", &cpuspeed, &size, NULL, 0)) if (sysctlbyname("hw.cpufrequency", &cpuspeed, &size, NULL, 0))
return -errno; return UV__ERR(errno);
if (host_processor_info(mach_host_self(), PROCESSOR_CPU_LOAD_INFO, &numcpus, if (host_processor_info(mach_host_self(), PROCESSOR_CPU_LOAD_INFO, &numcpus,
(processor_info_array_t*)&info, (processor_info_array_t*)&info,
&msg_type) != KERN_SUCCESS) { &msg_type) != KERN_SUCCESS) {
return -EINVAL; /* FIXME(bnoordhuis) Translate error. */ return UV_EINVAL; /* FIXME(bnoordhuis) Translate error. */
} }
*cpu_infos = uv__malloc(numcpus * sizeof(**cpu_infos)); *cpu_infos = uv__malloc(numcpus * sizeof(**cpu_infos));
if (!(*cpu_infos)) { if (!(*cpu_infos)) {
vm_deallocate(mach_task_self(), (vm_address_t)info, msg_type); vm_deallocate(mach_task_self(), (vm_address_t)info, msg_type);
return -ENOMEM; return UV_ENOMEM;
} }
*count = numcpus; *count = numcpus;
......
...@@ -47,9 +47,16 @@ ...@@ -47,9 +47,16 @@
# 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 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);
} }
...@@ -65,11 +72,11 @@ int uv_exepath(char* buffer, size_t* size) { ...@@ -65,11 +72,11 @@ int uv_exepath(char* buffer, size_t* size) {
ssize_t abspath_size; ssize_t abspath_size;
if (buffer == NULL || size == NULL || *size == 0) if (buffer == NULL || size == NULL || *size == 0)
return -EINVAL; return UV_EINVAL;
abspath_size = readlink("/proc/curproc/file", abspath, sizeof(abspath)); abspath_size = readlink("/proc/curproc/file", abspath, sizeof(abspath));
if (abspath_size < 0) if (abspath_size < 0)
return -errno; return UV__ERR(errno);
assert(abspath_size > 0); assert(abspath_size > 0);
*size -= 1; *size -= 1;
...@@ -89,7 +96,7 @@ int uv_exepath(char* buffer, size_t* size) { ...@@ -89,7 +96,7 @@ int uv_exepath(char* buffer, size_t* size) {
size_t abspath_size; size_t abspath_size;
if (buffer == NULL || size == NULL || *size == 0) if (buffer == NULL || size == NULL || *size == 0)
return -EINVAL; return UV_EINVAL;
mib[0] = CTL_KERN; mib[0] = CTL_KERN;
mib[1] = KERN_PROC; mib[1] = KERN_PROC;
...@@ -98,7 +105,7 @@ int uv_exepath(char* buffer, size_t* size) { ...@@ -98,7 +105,7 @@ int uv_exepath(char* buffer, size_t* size) {
abspath_size = sizeof abspath; abspath_size = sizeof abspath;
if (sysctl(mib, 4, abspath, &abspath_size, NULL, 0)) if (sysctl(mib, 4, abspath, &abspath_size, NULL, 0))
return -errno; return UV__ERR(errno);
assert(abspath_size > 0); assert(abspath_size > 0);
abspath_size -= 1; abspath_size -= 1;
...@@ -119,7 +126,7 @@ uint64_t uv_get_free_memory(void) { ...@@ -119,7 +126,7 @@ uint64_t uv_get_free_memory(void) {
size_t size = sizeof(freecount); size_t size = sizeof(freecount);
if (sysctlbyname("vm.stats.vm.v_free_count", &freecount, &size, NULL, 0)) if (sysctlbyname("vm.stats.vm.v_free_count", &freecount, &size, NULL, 0))
return -errno; return UV__ERR(errno);
return (uint64_t) freecount * sysconf(_SC_PAGESIZE); return (uint64_t) freecount * sysconf(_SC_PAGESIZE);
...@@ -133,7 +140,7 @@ uint64_t uv_get_total_memory(void) { ...@@ -133,7 +140,7 @@ uint64_t uv_get_total_memory(void) {
size_t size = sizeof(info); size_t size = sizeof(info);
if (sysctl(which, 2, &info, &size, NULL, 0)) if (sysctl(which, 2, &info, &size, NULL, 0))
return -errno; return UV__ERR(errno);
return (uint64_t) info; return (uint64_t) info;
} }
...@@ -163,8 +170,15 @@ int uv_set_process_title(const char* title) { ...@@ -163,8 +170,15 @@ int uv_set_process_title(const char* title) {
char* new_title; char* new_title;
new_title = uv__strdup(title); new_title = uv__strdup(title);
if (process_title == NULL)
return -ENOMEM; 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); uv__free(process_title);
process_title = new_title; process_title = new_title;
...@@ -180,6 +194,8 @@ int uv_set_process_title(const char* title) { ...@@ -180,6 +194,8 @@ int uv_set_process_title(const char* title) {
process_title, process_title,
strlen(process_title) + 1); strlen(process_title) + 1);
uv_mutex_unlock(&process_title_mutex);
return 0; return 0;
} }
...@@ -188,19 +204,26 @@ int uv_get_process_title(char* buffer, size_t size) { ...@@ -188,19 +204,26 @@ int uv_get_process_title(char* buffer, size_t size) {
size_t len; size_t len;
if (buffer == NULL || size == 0) if (buffer == NULL || size == 0)
return -EINVAL; return UV_EINVAL;
uv_once(&process_title_mutex_once, init_process_title_mutex_once);
uv_mutex_lock(&process_title_mutex);
if (process_title) { if (process_title) {
len = strlen(process_title) + 1; len = strlen(process_title) + 1;
if (size < len) if (size < len) {
return -ENOBUFS; uv_mutex_unlock(&process_title_mutex);
return UV_ENOBUFS;
}
memcpy(buffer, process_title, len); memcpy(buffer, process_title, len);
} else { } else {
len = 0; len = 0;
} }
uv_mutex_unlock(&process_title_mutex);
buffer[len] = '\0'; buffer[len] = '\0';
return 0; return 0;
...@@ -220,7 +243,7 @@ int uv_resident_set_memory(size_t* rss) { ...@@ -220,7 +243,7 @@ int uv_resident_set_memory(size_t* rss) {
kinfo_size = sizeof(kinfo); kinfo_size = sizeof(kinfo);
if (sysctl(mib, 4, &kinfo, &kinfo_size, NULL, 0)) if (sysctl(mib, 4, &kinfo, &kinfo_size, NULL, 0))
return -errno; return UV__ERR(errno);
page_size = getpagesize(); page_size = getpagesize();
...@@ -239,7 +262,7 @@ int uv_uptime(double* uptime) { ...@@ -239,7 +262,7 @@ int uv_uptime(double* uptime) {
struct timespec sp; struct timespec sp;
r = clock_gettime(CLOCK_MONOTONIC, &sp); r = clock_gettime(CLOCK_MONOTONIC, &sp);
if (r) if (r)
return -errno; return UV__ERR(errno);
*uptime = sp.tv_sec; *uptime = sp.tv_sec;
return 0; return 0;
...@@ -253,6 +276,7 @@ int uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) { ...@@ -253,6 +276,7 @@ int uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) {
uv_cpu_info_t* cpu_info; uv_cpu_info_t* cpu_info;
const char* maxcpus_key; const char* maxcpus_key;
const char* cptimes_key; const char* cptimes_key;
const char* model_key;
char model[512]; char model[512];
long* cp_times; long* cp_times;
int numcpus; int numcpus;
...@@ -271,33 +295,39 @@ int uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) { ...@@ -271,33 +295,39 @@ int uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) {
cptimes_key = "kern.cp_times"; cptimes_key = "kern.cp_times";
#endif #endif
size = sizeof(model); #if defined(__arm__) || defined(__aarch64__)
if (sysctlbyname("hw.model", &model, &size, NULL, 0)) /* The key hw.model and hw.clockrate are not available on FreeBSD ARM. */
model_key = "hw.machine";
cpuspeed = 0;
#else
model_key = "hw.model";
size = sizeof(cpuspeed);
if (sysctlbyname("hw.clockrate", &cpuspeed, &size, NULL, 0))
return -errno; return -errno;
#endif
size = sizeof(model);
if (sysctlbyname(model_key, &model, &size, NULL, 0))
return UV__ERR(errno);
size = sizeof(numcpus); size = sizeof(numcpus);
if (sysctlbyname("hw.ncpu", &numcpus, &size, NULL, 0)) if (sysctlbyname("hw.ncpu", &numcpus, &size, NULL, 0))
return -errno; return UV__ERR(errno);
*cpu_infos = uv__malloc(numcpus * sizeof(**cpu_infos)); *cpu_infos = uv__malloc(numcpus * sizeof(**cpu_infos));
if (!(*cpu_infos)) if (!(*cpu_infos))
return -ENOMEM; return UV_ENOMEM;
*count = numcpus; *count = numcpus;
size = sizeof(cpuspeed);
if (sysctlbyname("hw.clockrate", &cpuspeed, &size, NULL, 0)) {
uv__free(*cpu_infos);
return -errno;
}
/* kern.cp_times on FreeBSD i386 gives an array up to maxcpus instead of /* kern.cp_times on FreeBSD i386 gives an array up to maxcpus instead of
* ncpu. * ncpu.
*/ */
size = sizeof(maxcpus); size = sizeof(maxcpus);
if (sysctlbyname(maxcpus_key, &maxcpus, &size, NULL, 0)) { if (sysctlbyname(maxcpus_key, &maxcpus, &size, NULL, 0)) {
uv__free(*cpu_infos); uv__free(*cpu_infos);
return -errno; return UV__ERR(errno);
} }
size = maxcpus * CPUSTATES * sizeof(long); size = maxcpus * CPUSTATES * sizeof(long);
...@@ -305,13 +335,13 @@ int uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) { ...@@ -305,13 +335,13 @@ int uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) {
cp_times = uv__malloc(size); cp_times = uv__malloc(size);
if (cp_times == NULL) { if (cp_times == NULL) {
uv__free(*cpu_infos); uv__free(*cpu_infos);
return -ENOMEM; return UV_ENOMEM;
} }
if (sysctlbyname(cptimes_key, cp_times, &size, NULL, 0)) { if (sysctlbyname(cptimes_key, cp_times, &size, NULL, 0)) {
uv__free(cp_times); uv__free(cp_times);
uv__free(*cpu_infos); uv__free(*cpu_infos);
return -errno; return UV__ERR(errno);
} }
for (i = 0; i < numcpus; i++) { for (i = 0; i < numcpus; i++) {
......
...@@ -67,16 +67,15 @@ ...@@ -67,16 +67,15 @@
#define INIT(subtype) \ #define INIT(subtype) \
do { \ do { \
if (req == NULL) \ if (req == NULL) \
return -EINVAL; \ return UV_EINVAL; \
req->type = UV_FS; \ UV_REQ_INIT(req, UV_FS); \
if (cb != NULL) \
uv__req_init(loop, req, UV_FS); \
req->fs_type = UV_FS_ ## subtype; \ req->fs_type = UV_FS_ ## subtype; \
req->result = 0; \ req->result = 0; \
req->ptr = NULL; \ req->ptr = NULL; \
req->loop = loop; \ req->loop = loop; \
req->path = NULL; \ req->path = NULL; \
req->new_path = NULL; \ req->new_path = NULL; \
req->bufs = NULL; \
req->cb = cb; \ req->cb = cb; \
} \ } \
while (0) while (0)
...@@ -88,10 +87,8 @@ ...@@ -88,10 +87,8 @@
req->path = path; \ req->path = path; \
} else { \ } else { \
req->path = uv__strdup(path); \ req->path = uv__strdup(path); \
if (req->path == NULL) { \ if (req->path == NULL) \
uv__req_unregister(loop, req); \ return UV_ENOMEM; \
return -ENOMEM; \
} \
} \ } \
} \ } \
while (0) while (0)
...@@ -107,10 +104,8 @@ ...@@ -107,10 +104,8 @@
path_len = strlen(path) + 1; \ path_len = strlen(path) + 1; \
new_path_len = strlen(new_path) + 1; \ new_path_len = strlen(new_path) + 1; \
req->path = uv__malloc(path_len + new_path_len); \ req->path = uv__malloc(path_len + new_path_len); \
if (req->path == NULL) { \ if (req->path == NULL) \
uv__req_unregister(loop, req); \ return UV_ENOMEM; \
return -ENOMEM; \
} \
req->new_path = req->path + path_len; \ req->new_path = req->path + path_len; \
memcpy((void*) req->path, path, path_len); \ memcpy((void*) req->path, path, path_len); \
memcpy((void*) req->new_path, new_path, new_path_len); \ memcpy((void*) req->new_path, new_path, new_path_len); \
...@@ -121,6 +116,7 @@ ...@@ -121,6 +116,7 @@
#define POST \ #define POST \
do { \ do { \
if (cb != NULL) { \ if (cb != NULL) { \
uv__req_register(loop, req); \
uv__work_submit(loop, &req->work_req, uv__fs_work, uv__fs_done); \ uv__work_submit(loop, &req->work_req, uv__fs_work, uv__fs_done); \
return 0; \ return 0; \
} \ } \
...@@ -818,7 +814,7 @@ static ssize_t uv__fs_copyfile(uv_fs_t* req) { ...@@ -818,7 +814,7 @@ static ssize_t uv__fs_copyfile(uv_fs_t* req) {
/* Get the source file's mode. */ /* Get the source file's mode. */
if (fstat(srcfd, &statsbuf)) { if (fstat(srcfd, &statsbuf)) {
err = -errno; err = UV__ERR(errno);
goto out; goto out;
} }
...@@ -842,7 +838,7 @@ static ssize_t uv__fs_copyfile(uv_fs_t* req) { ...@@ -842,7 +838,7 @@ static ssize_t uv__fs_copyfile(uv_fs_t* req) {
} }
if (fchmod(dstfd, statsbuf.st_mode) == -1) { if (fchmod(dstfd, statsbuf.st_mode) == -1) {
err = -errno; err = UV__ERR(errno);
goto out; goto out;
} }
...@@ -1107,7 +1103,7 @@ static void uv__fs_work(struct uv__work* w) { ...@@ -1107,7 +1103,7 @@ static void uv__fs_work(struct uv__work* w) {
} while (r == -1 && errno == EINTR && retry_on_eintr); } while (r == -1 && errno == EINTR && retry_on_eintr);
if (r == -1) if (r == -1)
req->result = -errno; req->result = UV__ERR(errno);
else else
req->result = r; req->result = r;
...@@ -1125,9 +1121,9 @@ static void uv__fs_done(struct uv__work* w, int status) { ...@@ -1125,9 +1121,9 @@ static void uv__fs_done(struct uv__work* w, int status) {
req = container_of(w, uv_fs_t, work_req); req = container_of(w, uv_fs_t, work_req);
uv__req_unregister(req->loop, req); uv__req_unregister(req->loop, req);
if (status == -ECANCELED) { if (status == UV_ECANCELED) {
assert(req->result == 0); assert(req->result == 0);
req->result = -ECANCELED; req->result = UV_ECANCELED;
} }
req->cb(req); req->cb(req);
...@@ -1288,11 +1284,8 @@ int uv_fs_mkdtemp(uv_loop_t* loop, ...@@ -1288,11 +1284,8 @@ int uv_fs_mkdtemp(uv_loop_t* loop,
uv_fs_cb cb) { uv_fs_cb cb) {
INIT(MKDTEMP); INIT(MKDTEMP);
req->path = uv__strdup(tpl); req->path = uv__strdup(tpl);
if (req->path == NULL) { if (req->path == NULL)
if (cb != NULL) return UV_ENOMEM;
uv__req_unregister(loop, req);
return -ENOMEM;
}
POST; POST;
} }
...@@ -1320,7 +1313,7 @@ int uv_fs_read(uv_loop_t* loop, uv_fs_t* req, ...@@ -1320,7 +1313,7 @@ int uv_fs_read(uv_loop_t* loop, uv_fs_t* req,
INIT(READ); INIT(READ);
if (bufs == NULL || nbufs == 0) if (bufs == NULL || nbufs == 0)
return -EINVAL; return UV_EINVAL;
req->file = file; req->file = file;
...@@ -1329,11 +1322,8 @@ int uv_fs_read(uv_loop_t* loop, uv_fs_t* req, ...@@ -1329,11 +1322,8 @@ int uv_fs_read(uv_loop_t* loop, uv_fs_t* req,
if (nbufs > ARRAY_SIZE(req->bufsml)) if (nbufs > ARRAY_SIZE(req->bufsml))
req->bufs = uv__malloc(nbufs * sizeof(*bufs)); req->bufs = uv__malloc(nbufs * sizeof(*bufs));
if (req->bufs == NULL) { if (req->bufs == NULL)
if (cb != NULL) return UV_ENOMEM;
uv__req_unregister(loop, req);
return -ENOMEM;
}
memcpy(req->bufs, bufs, nbufs * sizeof(*bufs)); memcpy(req->bufs, bufs, nbufs * sizeof(*bufs));
...@@ -1459,7 +1449,7 @@ int uv_fs_write(uv_loop_t* loop, ...@@ -1459,7 +1449,7 @@ int uv_fs_write(uv_loop_t* loop,
INIT(WRITE); INIT(WRITE);
if (bufs == NULL || nbufs == 0) if (bufs == NULL || nbufs == 0)
return -EINVAL; return UV_EINVAL;
req->file = file; req->file = file;
...@@ -1468,11 +1458,8 @@ int uv_fs_write(uv_loop_t* loop, ...@@ -1468,11 +1458,8 @@ int uv_fs_write(uv_loop_t* loop,
if (nbufs > ARRAY_SIZE(req->bufsml)) if (nbufs > ARRAY_SIZE(req->bufsml))
req->bufs = uv__malloc(nbufs * sizeof(*bufs)); req->bufs = uv__malloc(nbufs * sizeof(*bufs));
if (req->bufs == NULL) { if (req->bufs == NULL)
if (cb != NULL) return UV_ENOMEM;
uv__req_unregister(loop, req);
return -ENOMEM;
}
memcpy(req->bufs, bufs, nbufs * sizeof(*bufs)); memcpy(req->bufs, bufs, nbufs * sizeof(*bufs));
...@@ -1499,6 +1486,10 @@ void uv_fs_req_cleanup(uv_fs_t* req) { ...@@ -1499,6 +1486,10 @@ void uv_fs_req_cleanup(uv_fs_t* req) {
if (req->fs_type == UV_FS_SCANDIR && req->ptr != NULL) if (req->fs_type == UV_FS_SCANDIR && req->ptr != NULL)
uv__fs_scandir_cleanup(req); uv__fs_scandir_cleanup(req);
if (req->bufs != req->bufsml)
uv__free(req->bufs);
req->bufs = NULL;
if (req->ptr != &req->statbuf) if (req->ptr != &req->statbuf)
uv__free(req->ptr); uv__free(req->ptr);
req->ptr = NULL; req->ptr = NULL;
...@@ -1514,7 +1505,7 @@ int uv_fs_copyfile(uv_loop_t* loop, ...@@ -1514,7 +1505,7 @@ int uv_fs_copyfile(uv_loop_t* loop,
INIT(COPYFILE); INIT(COPYFILE);
if (flags & ~UV_FS_COPYFILE_EXCL) if (flags & ~UV_FS_COPYFILE_EXCL)
return -EINVAL; return UV_EINVAL;
PATH2; PATH2;
req->flags = flags; req->flags = flags;
......
...@@ -379,7 +379,7 @@ static int uv__fsevents_create_stream(uv_loop_t* loop, CFArrayRef paths) { ...@@ -379,7 +379,7 @@ static int uv__fsevents_create_stream(uv_loop_t* loop, CFArrayRef paths) {
if (!pFSEventStreamStart(ref)) { if (!pFSEventStreamStart(ref)) {
pFSEventStreamInvalidate(ref); pFSEventStreamInvalidate(ref);
pFSEventStreamRelease(ref); pFSEventStreamRelease(ref);
return -EMFILE; return UV_EMFILE;
} }
state->fsevent_stream = ref; state->fsevent_stream = ref;
...@@ -440,7 +440,7 @@ static void uv__fsevents_reschedule(uv_fs_event_t* handle, ...@@ -440,7 +440,7 @@ static void uv__fsevents_reschedule(uv_fs_event_t* handle,
uv__fsevents_destroy_stream(handle->loop); uv__fsevents_destroy_stream(handle->loop);
/* Any failure below will be a memory failure */ /* Any failure below will be a memory failure */
err = -ENOMEM; err = UV_ENOMEM;
/* Create list of all watched paths */ /* Create list of all watched paths */
uv_mutex_lock(&state->fsevent_mutex); uv_mutex_lock(&state->fsevent_mutex);
...@@ -474,7 +474,7 @@ static void uv__fsevents_reschedule(uv_fs_event_t* handle, ...@@ -474,7 +474,7 @@ static void uv__fsevents_reschedule(uv_fs_event_t* handle,
/* Create new FSEventStream */ /* Create new FSEventStream */
cf_paths = pCFArrayCreate(NULL, (const void**) paths, path_count, NULL); cf_paths = pCFArrayCreate(NULL, (const void**) paths, path_count, NULL);
if (cf_paths == NULL) { if (cf_paths == NULL) {
err = -ENOMEM; err = UV_ENOMEM;
goto final; goto final;
} }
err = uv__fsevents_create_stream(handle->loop, cf_paths); err = uv__fsevents_create_stream(handle->loop, cf_paths);
...@@ -528,7 +528,7 @@ static int uv__fsevents_global_init(void) { ...@@ -528,7 +528,7 @@ static int uv__fsevents_global_init(void) {
* but if it ever becomes one, we can turn the dynamic library handles into * but if it ever becomes one, we can turn the dynamic library handles into
* per-event loop properties and have the dynamic linker keep track for us. * per-event loop properties and have the dynamic linker keep track for us.
*/ */
err = -ENOSYS; err = UV_ENOSYS;
core_foundation_handle = dlopen("/System/Library/Frameworks/" core_foundation_handle = dlopen("/System/Library/Frameworks/"
"CoreFoundation.framework/" "CoreFoundation.framework/"
"Versions/A/CoreFoundation", "Versions/A/CoreFoundation",
...@@ -543,7 +543,7 @@ static int uv__fsevents_global_init(void) { ...@@ -543,7 +543,7 @@ static int uv__fsevents_global_init(void) {
if (core_services_handle == NULL) if (core_services_handle == NULL)
goto out; goto out;
err = -ENOENT; err = UV_ENOENT;
#define V(handle, symbol) \ #define V(handle, symbol) \
do { \ do { \
*(void **)(&p ## symbol) = dlsym((handle), #symbol); \ *(void **)(&p ## symbol) = dlsym((handle), #symbol); \
...@@ -607,7 +607,7 @@ static int uv__fsevents_loop_init(uv_loop_t* loop) { ...@@ -607,7 +607,7 @@ static int uv__fsevents_loop_init(uv_loop_t* loop) {
state = uv__calloc(1, sizeof(*state)); state = uv__calloc(1, sizeof(*state));
if (state == NULL) if (state == NULL)
return -ENOMEM; return UV_ENOMEM;
err = uv_mutex_init(&loop->cf_mutex); err = uv_mutex_init(&loop->cf_mutex);
if (err) if (err)
...@@ -636,7 +636,7 @@ static int uv__fsevents_loop_init(uv_loop_t* loop) { ...@@ -636,7 +636,7 @@ static int uv__fsevents_loop_init(uv_loop_t* loop) {
ctx.perform = uv__cf_loop_cb; ctx.perform = uv__cf_loop_cb;
state->signal_source = pCFRunLoopSourceCreate(NULL, 0, &ctx); state->signal_source = pCFRunLoopSourceCreate(NULL, 0, &ctx);
if (state->signal_source == NULL) { if (state->signal_source == NULL) {
err = -ENOMEM; err = UV_ENOMEM;
goto fail_signal_source_create; goto fail_signal_source_create;
} }
...@@ -655,7 +655,7 @@ static int uv__fsevents_loop_init(uv_loop_t* loop) { ...@@ -655,7 +655,7 @@ static int uv__fsevents_loop_init(uv_loop_t* loop) {
loop->cf_state = state; loop->cf_state = state;
/* uv_thread_t is an alias for pthread_t. */ /* uv_thread_t is an alias for pthread_t. */
err = -pthread_create(&loop->cf_thread, attr, uv__cf_loop_runner, loop); err = UV__ERR(pthread_create(&loop->cf_thread, attr, uv__cf_loop_runner, loop));
if (attr != NULL) if (attr != NULL)
pthread_attr_destroy(attr); pthread_attr_destroy(attr);
...@@ -787,7 +787,7 @@ int uv__cf_loop_signal(uv_loop_t* loop, ...@@ -787,7 +787,7 @@ int uv__cf_loop_signal(uv_loop_t* loop,
item = uv__malloc(sizeof(*item)); item = uv__malloc(sizeof(*item));
if (item == NULL) if (item == NULL)
return -ENOMEM; return UV_ENOMEM;
item->handle = handle; item->handle = handle;
item->type = type; item->type = type;
...@@ -817,7 +817,7 @@ int uv__fsevents_init(uv_fs_event_t* handle) { ...@@ -817,7 +817,7 @@ int uv__fsevents_init(uv_fs_event_t* handle) {
/* Get absolute path to file */ /* Get absolute path to file */
handle->realpath = realpath(handle->path, NULL); handle->realpath = realpath(handle->path, NULL);
if (handle->realpath == NULL) if (handle->realpath == NULL)
return -errno; return UV__ERR(errno);
handle->realpath_len = strlen(handle->realpath); handle->realpath_len = strlen(handle->realpath);
/* Initialize event queue */ /* Initialize event queue */
...@@ -830,7 +830,7 @@ int uv__fsevents_init(uv_fs_event_t* handle) { ...@@ -830,7 +830,7 @@ int uv__fsevents_init(uv_fs_event_t* handle) {
*/ */
handle->cf_cb = uv__malloc(sizeof(*handle->cf_cb)); handle->cf_cb = uv__malloc(sizeof(*handle->cf_cb));
if (handle->cf_cb == NULL) { if (handle->cf_cb == NULL) {
err = -ENOMEM; err = UV_ENOMEM;
goto fail_cf_cb_malloc; goto fail_cf_cb_malloc;
} }
...@@ -881,7 +881,7 @@ int uv__fsevents_close(uv_fs_event_t* handle) { ...@@ -881,7 +881,7 @@ int uv__fsevents_close(uv_fs_event_t* handle) {
uv__cf_loop_state_t* state; uv__cf_loop_state_t* state;
if (handle->cf_cb == NULL) if (handle->cf_cb == NULL)
return -EINVAL; return UV_EINVAL;
/* Remove handle from the list */ /* Remove handle from the list */
state = handle->loop->cf_state; state = handle->loop->cf_state;
...@@ -895,7 +895,7 @@ int uv__fsevents_close(uv_fs_event_t* handle) { ...@@ -895,7 +895,7 @@ int uv__fsevents_close(uv_fs_event_t* handle) {
assert(handle != NULL); assert(handle != NULL);
err = uv__cf_loop_signal(handle->loop, handle, kUVCFLoopSignalClosing); err = uv__cf_loop_signal(handle->loop, handle, kUVCFLoopSignalClosing);
if (err) if (err)
return -err; return UV__ERR(err);
/* Wait for deinitialization */ /* Wait for deinitialization */
uv_sem_wait(&state->fsevent_sem); uv_sem_wait(&state->fsevent_sem);
......
...@@ -86,7 +86,7 @@ int uv__getaddrinfo_translate_error(int sys_err) { ...@@ -86,7 +86,7 @@ int uv__getaddrinfo_translate_error(int sys_err) {
case EAI_SOCKTYPE: return UV_EAI_SOCKTYPE; case EAI_SOCKTYPE: return UV_EAI_SOCKTYPE;
#endif #endif
#if defined(EAI_SYSTEM) #if defined(EAI_SYSTEM)
case EAI_SYSTEM: return -errno; case EAI_SYSTEM: return UV__ERR(errno);
#endif #endif
} }
assert(!"unknown EAI_* error code"); assert(!"unknown EAI_* error code");
...@@ -125,7 +125,7 @@ static void uv__getaddrinfo_done(struct uv__work* w, int status) { ...@@ -125,7 +125,7 @@ static void uv__getaddrinfo_done(struct uv__work* w, int status) {
req->service = NULL; req->service = NULL;
req->hostname = NULL; req->hostname = NULL;
if (status == -ECANCELED) { if (status == UV_ECANCELED) {
assert(req->retcode == 0); assert(req->retcode == 0);
req->retcode = UV_EAI_CANCELED; req->retcode = UV_EAI_CANCELED;
} }
...@@ -148,7 +148,7 @@ int uv_getaddrinfo(uv_loop_t* loop, ...@@ -148,7 +148,7 @@ int uv_getaddrinfo(uv_loop_t* loop,
char* buf; char* buf;
if (req == NULL || (hostname == NULL && service == NULL)) if (req == NULL || (hostname == NULL && service == NULL))
return -EINVAL; return UV_EINVAL;
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;
...@@ -156,7 +156,7 @@ int uv_getaddrinfo(uv_loop_t* loop, ...@@ -156,7 +156,7 @@ int uv_getaddrinfo(uv_loop_t* loop,
buf = uv__malloc(hostname_len + service_len + hints_len); buf = uv__malloc(hostname_len + service_len + hints_len);
if (buf == NULL) if (buf == NULL)
return -ENOMEM; return UV_ENOMEM;
uv__req_init(loop, req, UV_GETADDRINFO); uv__req_init(loop, req, UV_GETADDRINFO);
req->loop = loop; req->loop = loop;
...@@ -211,7 +211,7 @@ int uv_if_indextoname(unsigned int ifindex, char* buffer, size_t* size) { ...@@ -211,7 +211,7 @@ int uv_if_indextoname(unsigned int ifindex, char* buffer, size_t* size) {
return UV_EINVAL; return UV_EINVAL;
if (if_indextoname(ifindex, ifname_buf) == NULL) if (if_indextoname(ifindex, ifname_buf) == NULL)
return -errno; return UV__ERR(errno);
len = strnlen(ifname_buf, sizeof(ifname_buf)); len = strnlen(ifname_buf, sizeof(ifname_buf));
......
...@@ -61,7 +61,7 @@ static void uv__getnameinfo_done(struct uv__work* w, int status) { ...@@ -61,7 +61,7 @@ static void uv__getnameinfo_done(struct uv__work* w, int status) {
uv__req_unregister(req->loop, req); uv__req_unregister(req->loop, req);
host = service = NULL; host = service = NULL;
if (status == -ECANCELED) { if (status == UV_ECANCELED) {
assert(req->retcode == 0); assert(req->retcode == 0);
req->retcode = UV_EAI_CANCELED; req->retcode = UV_EAI_CANCELED;
} else if (req->retcode == 0) { } else if (req->retcode == 0) {
......
...@@ -92,7 +92,7 @@ int uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) { ...@@ -92,7 +92,7 @@ int uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) {
*cpu_infos = uv__malloc(numcpus * sizeof(uv_cpu_info_t)); *cpu_infos = uv__malloc(numcpus * sizeof(uv_cpu_info_t));
if (!*cpu_infos) { if (!*cpu_infos) {
return -ENOMEM; return UV_ENOMEM;
} }
cpu_info = *cpu_infos; cpu_info = *cpu_infos;
......
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
#include <string.h> /* strrchr */ #include <string.h> /* strrchr */
#include <fcntl.h> /* O_CLOEXEC, may be */ #include <fcntl.h> /* O_CLOEXEC, may be */
#include <stdio.h> #include <stdio.h>
#include <errno.h>
#if defined(__STRICT_ANSI__) #if defined(__STRICT_ANSI__)
# define inline __inline # define inline __inline
......
...@@ -51,7 +51,7 @@ static void uv__fs_event(uv_loop_t* loop, uv__io_t* w, unsigned int fflags); ...@@ -51,7 +51,7 @@ static void uv__fs_event(uv_loop_t* loop, uv__io_t* w, unsigned int fflags);
int uv__kqueue_init(uv_loop_t* loop) { int uv__kqueue_init(uv_loop_t* loop) {
loop->backend_fd = kqueue(); loop->backend_fd = kqueue();
if (loop->backend_fd == -1) if (loop->backend_fd == -1)
return -errno; return UV__ERR(errno);
uv__cloexec(loop->backend_fd, 1); uv__cloexec(loop->backend_fd, 1);
...@@ -98,7 +98,7 @@ int uv__io_check_fd(uv_loop_t* loop, int fd) { ...@@ -98,7 +98,7 @@ int uv__io_check_fd(uv_loop_t* loop, int fd) {
rc = 0; rc = 0;
EV_SET(&ev, fd, EVFILT_READ, EV_ADD, 0, 0, 0); EV_SET(&ev, fd, EVFILT_READ, EV_ADD, 0, 0, 0);
if (kevent(loop->backend_fd, &ev, 1, NULL, 0, NULL)) if (kevent(loop->backend_fd, &ev, 1, NULL, 0, NULL))
rc = -errno; rc = UV__ERR(errno);
EV_SET(&ev, fd, EVFILT_READ, EV_DELETE, 0, 0, 0); EV_SET(&ev, fd, EVFILT_READ, EV_DELETE, 0, 0, 0);
if (rc == 0) if (rc == 0)
...@@ -458,12 +458,12 @@ int uv_fs_event_start(uv_fs_event_t* handle, ...@@ -458,12 +458,12 @@ int uv_fs_event_start(uv_fs_event_t* handle,
int fd; int fd;
if (uv__is_active(handle)) if (uv__is_active(handle))
return -EINVAL; return UV_EINVAL;
/* TODO open asynchronously - but how do we report back errors? */ /* TODO open asynchronously - but how do we report back errors? */
fd = open(path, O_RDONLY); fd = open(path, O_RDONLY);
if (fd == -1) if (fd == -1)
return -errno; return UV__ERR(errno);
uv__handle_start(handle); uv__handle_start(handle);
uv__io_init(&handle->event_watcher, uv__fs_event, fd); uv__io_init(&handle->event_watcher, uv__fs_event, fd);
......
...@@ -101,7 +101,7 @@ int uv__platform_loop_init(uv_loop_t* loop) { ...@@ -101,7 +101,7 @@ int uv__platform_loop_init(uv_loop_t* loop) {
loop->inotify_watchers = NULL; loop->inotify_watchers = NULL;
if (fd == -1) if (fd == -1)
return -errno; return UV__ERR(errno);
return 0; return 0;
} }
...@@ -175,7 +175,7 @@ int uv__io_check_fd(uv_loop_t* loop, int fd) { ...@@ -175,7 +175,7 @@ int uv__io_check_fd(uv_loop_t* loop, int fd) {
rc = 0; rc = 0;
if (uv__epoll_ctl(loop->backend_fd, UV__EPOLL_CTL_ADD, fd, &e)) if (uv__epoll_ctl(loop->backend_fd, UV__EPOLL_CTL_ADD, fd, &e))
if (errno != EEXIST) if (errno != EEXIST)
rc = -errno; rc = UV__ERR(errno);
if (rc == 0) if (rc == 0)
if (uv__epoll_ctl(loop->backend_fd, UV__EPOLL_CTL_DEL, fd, &e)) if (uv__epoll_ctl(loop->backend_fd, UV__EPOLL_CTL_DEL, fd, &e))
...@@ -485,7 +485,7 @@ int uv_resident_set_memory(size_t* rss) { ...@@ -485,7 +485,7 @@ int uv_resident_set_memory(size_t* rss) {
while (fd == -1 && errno == EINTR); while (fd == -1 && errno == EINTR);
if (fd == -1) if (fd == -1)
return -errno; return UV__ERR(errno);
do do
n = read(fd, buf, sizeof(buf) - 1); n = read(fd, buf, sizeof(buf) - 1);
...@@ -493,7 +493,7 @@ int uv_resident_set_memory(size_t* rss) { ...@@ -493,7 +493,7 @@ int uv_resident_set_memory(size_t* rss) {
uv__close(fd); uv__close(fd);
if (n == -1) if (n == -1)
return -errno; return UV__ERR(errno);
buf[n] = '\0'; buf[n] = '\0';
s = strchr(buf, ' '); s = strchr(buf, ' ');
...@@ -525,7 +525,7 @@ int uv_resident_set_memory(size_t* rss) { ...@@ -525,7 +525,7 @@ int uv_resident_set_memory(size_t* rss) {
return 0; return 0;
err: err:
return -EINVAL; return UV_EINVAL;
} }
...@@ -547,7 +547,7 @@ int uv_uptime(double* uptime) { ...@@ -547,7 +547,7 @@ int uv_uptime(double* uptime) {
} }
if (r) if (r)
return -errno; return UV__ERR(errno);
*uptime = now.tv_sec; *uptime = now.tv_sec;
return 0; return 0;
...@@ -559,7 +559,7 @@ static int uv__cpu_num(FILE* statfile_fp, unsigned int* numcpus) { ...@@ -559,7 +559,7 @@ static int uv__cpu_num(FILE* statfile_fp, unsigned int* numcpus) {
char buf[1024]; char buf[1024];
if (!fgets(buf, sizeof(buf), statfile_fp)) if (!fgets(buf, sizeof(buf), statfile_fp))
return -EIO; return UV_EIO;
num = 0; num = 0;
while (fgets(buf, sizeof(buf), statfile_fp)) { while (fgets(buf, sizeof(buf), statfile_fp)) {
...@@ -569,7 +569,7 @@ static int uv__cpu_num(FILE* statfile_fp, unsigned int* numcpus) { ...@@ -569,7 +569,7 @@ static int uv__cpu_num(FILE* statfile_fp, unsigned int* numcpus) {
} }
if (num == 0) if (num == 0)
return -EIO; return UV_EIO;
*numcpus = num; *numcpus = num;
return 0; return 0;
...@@ -587,13 +587,13 @@ int uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) { ...@@ -587,13 +587,13 @@ int uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) {
statfile_fp = uv__open_file("/proc/stat"); statfile_fp = uv__open_file("/proc/stat");
if (statfile_fp == NULL) if (statfile_fp == NULL)
return -errno; return UV__ERR(errno);
err = uv__cpu_num(statfile_fp, &numcpus); err = uv__cpu_num(statfile_fp, &numcpus);
if (err < 0) if (err < 0)
goto out; goto out;
err = -ENOMEM; err = UV_ENOMEM;
ci = uv__calloc(numcpus, sizeof(*ci)); ci = uv__calloc(numcpus, sizeof(*ci));
if (ci == NULL) if (ci == NULL)
goto out; goto out;
...@@ -667,7 +667,7 @@ static int read_models(unsigned int numcpus, uv_cpu_info_t* ci) { ...@@ -667,7 +667,7 @@ static int read_models(unsigned int numcpus, uv_cpu_info_t* ci) {
defined(__x86_64__) defined(__x86_64__)
fp = uv__open_file("/proc/cpuinfo"); fp = uv__open_file("/proc/cpuinfo");
if (fp == NULL) if (fp == NULL)
return -errno; return UV__ERR(errno);
while (fgets(buf, sizeof(buf), fp)) { while (fgets(buf, sizeof(buf), fp)) {
if (model_idx < numcpus) { if (model_idx < numcpus) {
...@@ -676,7 +676,7 @@ static int read_models(unsigned int numcpus, uv_cpu_info_t* ci) { ...@@ -676,7 +676,7 @@ static int read_models(unsigned int numcpus, uv_cpu_info_t* ci) {
model = uv__strndup(model, strlen(model) - 1); /* Strip newline. */ model = uv__strndup(model, strlen(model) - 1); /* Strip newline. */
if (model == NULL) { if (model == NULL) {
fclose(fp); fclose(fp);
return -ENOMEM; return UV_ENOMEM;
} }
ci[model_idx++].model = model; ci[model_idx++].model = model;
continue; continue;
...@@ -695,7 +695,7 @@ static int read_models(unsigned int numcpus, uv_cpu_info_t* ci) { ...@@ -695,7 +695,7 @@ static int read_models(unsigned int numcpus, uv_cpu_info_t* ci) {
model = uv__strndup(model, strlen(model) - 1); /* Strip newline. */ model = uv__strndup(model, strlen(model) - 1); /* Strip newline. */
if (model == NULL) { if (model == NULL) {
fclose(fp); fclose(fp);
return -ENOMEM; return UV_ENOMEM;
} }
ci[model_idx++].model = model; ci[model_idx++].model = model;
continue; continue;
...@@ -725,7 +725,7 @@ static int read_models(unsigned int numcpus, uv_cpu_info_t* ci) { ...@@ -725,7 +725,7 @@ static int read_models(unsigned int numcpus, uv_cpu_info_t* ci) {
while (model_idx < numcpus) { while (model_idx < numcpus) {
model = uv__strndup(inferred_model, strlen(inferred_model)); model = uv__strndup(inferred_model, strlen(inferred_model));
if (model == NULL) if (model == NULL)
return -ENOMEM; return UV_ENOMEM;
ci[model_idx++].model = model; ci[model_idx++].model = model;
} }
...@@ -854,7 +854,7 @@ static int uv__ifaddr_exclude(struct ifaddrs *ent, int exclude_type) { ...@@ -854,7 +854,7 @@ static int uv__ifaddr_exclude(struct ifaddrs *ent, int 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
return -ENOSYS; return UV_ENOSYS;
#else #else
struct ifaddrs *addrs, *ent; struct ifaddrs *addrs, *ent;
uv_interface_address_t* address; uv_interface_address_t* address;
...@@ -862,7 +862,7 @@ int uv_interface_addresses(uv_interface_address_t** addresses, ...@@ -862,7 +862,7 @@ int uv_interface_addresses(uv_interface_address_t** addresses,
struct sockaddr_ll *sll; struct sockaddr_ll *sll;
if (getifaddrs(&addrs)) if (getifaddrs(&addrs))
return -errno; return UV__ERR(errno);
*count = 0; *count = 0;
*addresses = NULL; *addresses = NULL;
...@@ -881,7 +881,7 @@ int uv_interface_addresses(uv_interface_address_t** addresses, ...@@ -881,7 +881,7 @@ int uv_interface_addresses(uv_interface_address_t** addresses,
*addresses = uv__malloc(*count * sizeof(**addresses)); *addresses = uv__malloc(*count * sizeof(**addresses));
if (!(*addresses)) { if (!(*addresses)) {
freeifaddrs(addrs); freeifaddrs(addrs);
return -ENOMEM; return UV_ENOMEM;
} }
address = *addresses; address = *addresses;
......
...@@ -73,11 +73,11 @@ static int new_inotify_fd(void) { ...@@ -73,11 +73,11 @@ static int new_inotify_fd(void) {
return fd; return fd;
if (errno != ENOSYS) if (errno != ENOSYS)
return -errno; return UV__ERR(errno);
fd = uv__inotify_init(); fd = uv__inotify_init();
if (fd == -1) if (fd == -1)
return -errno; return UV__ERR(errno);
err = uv__cloexec(fd, 1); err = uv__cloexec(fd, 1);
if (err == 0) if (err == 0)
...@@ -283,7 +283,7 @@ int uv_fs_event_start(uv_fs_event_t* handle, ...@@ -283,7 +283,7 @@ int uv_fs_event_start(uv_fs_event_t* handle,
int wd; int wd;
if (uv__is_active(handle)) if (uv__is_active(handle))
return -EINVAL; return UV_EINVAL;
err = init_inotify(handle->loop); err = init_inotify(handle->loop);
if (err) if (err)
...@@ -300,7 +300,7 @@ int uv_fs_event_start(uv_fs_event_t* handle, ...@@ -300,7 +300,7 @@ int uv_fs_event_start(uv_fs_event_t* handle,
wd = uv__inotify_add_watch(handle->loop->inotify_fd, path, events); wd = uv__inotify_add_watch(handle->loop->inotify_fd, path, events);
if (wd == -1) if (wd == -1)
return -errno; return UV__ERR(errno);
w = find_watcher(handle->loop, wd); w = find_watcher(handle->loop, wd);
if (w) if (w)
...@@ -308,7 +308,7 @@ int uv_fs_event_start(uv_fs_event_t* handle, ...@@ -308,7 +308,7 @@ int uv_fs_event_start(uv_fs_event_t* handle,
w = uv__malloc(sizeof(*w) + strlen(path) + 1); w = uv__malloc(sizeof(*w) + strlen(path) + 1);
if (w == NULL) if (w == NULL)
return -ENOMEM; return UV_ENOMEM;
w->wd = wd; w->wd = wd;
w->path = strcpy((char*)(w + 1), path); w->path = strcpy((char*)(w + 1), path);
......
...@@ -42,7 +42,7 @@ ...@@ -42,7 +42,7 @@
\ \
int uv_##name##_start(uv_##name##_t* handle, uv_##name##_cb cb) { \ int uv_##name##_start(uv_##name##_t* handle, uv_##name##_cb cb) { \
if (uv__is_active(handle)) return 0; \ if (uv__is_active(handle)) return 0; \
if (cb == NULL) return -EINVAL; \ if (cb == NULL) return UV_EINVAL; \
QUEUE_INSERT_HEAD(&handle->loop->name##_handles, &handle->queue); \ QUEUE_INSERT_HEAD(&handle->loop->name##_handles, &handle->queue); \
handle->name##_cb = cb; \ handle->name##_cb = cb; \
uv__handle_start(handle); \ uv__handle_start(handle); \
......
...@@ -40,9 +40,16 @@ ...@@ -40,9 +40,16 @@
#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 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);
} }
...@@ -75,7 +82,7 @@ int uv_exepath(char* buffer, size_t* size) { ...@@ -75,7 +82,7 @@ int uv_exepath(char* buffer, size_t* size) {
int mib[4]; int mib[4];
if (buffer == NULL || size == NULL || *size == 0) if (buffer == NULL || size == NULL || *size == 0)
return -EINVAL; return UV_EINVAL;
mib[0] = CTL_KERN; mib[0] = CTL_KERN;
mib[1] = KERN_PROC_ARGS; mib[1] = KERN_PROC_ARGS;
...@@ -84,7 +91,7 @@ int uv_exepath(char* buffer, size_t* size) { ...@@ -84,7 +91,7 @@ int uv_exepath(char* buffer, size_t* size) {
int_size = ARRAY_SIZE(int_buf); int_size = ARRAY_SIZE(int_buf);
if (sysctl(mib, 4, int_buf, &int_size, NULL, 0)) if (sysctl(mib, 4, int_buf, &int_size, NULL, 0))
return -errno; return UV__ERR(errno);
/* Copy string from the intermediate buffer to outer one with appropriate /* Copy string from the intermediate buffer to outer one with appropriate
* length. * length.
...@@ -104,7 +111,7 @@ uint64_t uv_get_free_memory(void) { ...@@ -104,7 +111,7 @@ uint64_t uv_get_free_memory(void) {
int which[] = {CTL_VM, VM_UVMEXP}; int which[] = {CTL_VM, VM_UVMEXP};
if (sysctl(which, 2, &info, &size, NULL, 0)) if (sysctl(which, 2, &info, &size, NULL, 0))
return -errno; return UV__ERR(errno);
return (uint64_t) info.free * sysconf(_SC_PAGESIZE); return (uint64_t) info.free * sysconf(_SC_PAGESIZE);
} }
...@@ -121,7 +128,7 @@ uint64_t uv_get_total_memory(void) { ...@@ -121,7 +128,7 @@ uint64_t uv_get_total_memory(void) {
size_t size = sizeof(info); size_t size = sizeof(info);
if (sysctl(which, 2, &info, &size, NULL, 0)) if (sysctl(which, 2, &info, &size, NULL, 0))
return -errno; return UV__ERR(errno);
return (uint64_t) info; return (uint64_t) info;
} }
...@@ -137,12 +144,21 @@ int uv_set_process_title(const char* title) { ...@@ -137,12 +144,21 @@ int uv_set_process_title(const char* title) {
char* new_title; char* new_title;
new_title = uv__strdup(title); new_title = uv__strdup(title);
if (process_title == NULL)
return -ENOMEM; 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); uv__free(process_title);
process_title = new_title; process_title = new_title;
setproctitle("%s", title); setproctitle("%s", title);
uv_mutex_unlock(&process_title_mutex);
return 0; return 0;
} }
...@@ -151,19 +167,26 @@ int uv_get_process_title(char* buffer, size_t size) { ...@@ -151,19 +167,26 @@ int uv_get_process_title(char* buffer, size_t size) {
size_t len; size_t len;
if (buffer == NULL || size == 0) if (buffer == NULL || size == 0)
return -EINVAL; return UV_EINVAL;
uv_once(&process_title_mutex_once, init_process_title_mutex_once);
uv_mutex_lock(&process_title_mutex);
if (process_title) { if (process_title) {
len = strlen(process_title) + 1; len = strlen(process_title) + 1;
if (size < len) if (size < len) {
return -ENOBUFS; uv_mutex_unlock(&process_title_mutex);
return UV_ENOBUFS;
}
memcpy(buffer, process_title, len); memcpy(buffer, process_title, len);
} else { } else {
len = 0; len = 0;
} }
uv_mutex_unlock(&process_title_mutex);
buffer[len] = '\0'; buffer[len] = '\0';
return 0; return 0;
...@@ -196,7 +219,7 @@ int uv_resident_set_memory(size_t* rss) { ...@@ -196,7 +219,7 @@ int uv_resident_set_memory(size_t* rss) {
error: error:
if (kd) kvm_close(kd); if (kd) kvm_close(kd);
return -EPERM; return UV_EPERM;
} }
...@@ -207,7 +230,7 @@ int uv_uptime(double* uptime) { ...@@ -207,7 +230,7 @@ int uv_uptime(double* uptime) {
static int which[] = {CTL_KERN, KERN_BOOTTIME}; static int which[] = {CTL_KERN, KERN_BOOTTIME};
if (sysctl(which, 2, &info, &size, NULL, 0)) if (sysctl(which, 2, &info, &size, NULL, 0))
return -errno; return UV__ERR(errno);
now = time(NULL); now = time(NULL);
...@@ -231,12 +254,12 @@ int uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) { ...@@ -231,12 +254,12 @@ int uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) {
size = sizeof(model); size = sizeof(model);
if (sysctlbyname("machdep.cpu_brand", &model, &size, NULL, 0) && if (sysctlbyname("machdep.cpu_brand", &model, &size, NULL, 0) &&
sysctlbyname("hw.model", &model, &size, NULL, 0)) { sysctlbyname("hw.model", &model, &size, NULL, 0)) {
return -errno; return UV__ERR(errno);
} }
size = sizeof(numcpus); size = sizeof(numcpus);
if (sysctlbyname("hw.ncpu", &numcpus, &size, NULL, 0)) if (sysctlbyname("hw.ncpu", &numcpus, &size, NULL, 0))
return -errno; return UV__ERR(errno);
*count = numcpus; *count = numcpus;
/* Only i386 and amd64 have machdep.tsc_freq */ /* Only i386 and amd64 have machdep.tsc_freq */
...@@ -247,16 +270,16 @@ int uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) { ...@@ -247,16 +270,16 @@ int uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) {
size = numcpus * CPUSTATES * sizeof(*cp_times); size = numcpus * CPUSTATES * sizeof(*cp_times);
cp_times = uv__malloc(size); cp_times = uv__malloc(size);
if (cp_times == NULL) if (cp_times == NULL)
return -ENOMEM; return UV_ENOMEM;
if (sysctlbyname("kern.cp_time", cp_times, &size, NULL, 0)) if (sysctlbyname("kern.cp_time", cp_times, &size, NULL, 0))
return -errno; return UV__ERR(errno);
*cpu_infos = uv__malloc(numcpus * sizeof(**cpu_infos)); *cpu_infos = uv__malloc(numcpus * sizeof(**cpu_infos));
if (!(*cpu_infos)) { if (!(*cpu_infos)) {
uv__free(cp_times); uv__free(cp_times);
uv__free(*cpu_infos); uv__free(*cpu_infos);
return -ENOMEM; return UV_ENOMEM;
} }
for (i = 0; i < numcpus; i++) { for (i = 0; i < numcpus; i++) {
......
...@@ -25,16 +25,16 @@ ...@@ -25,16 +25,16 @@
#include <errno.h> #include <errno.h>
int uv_fs_event_init(uv_loop_t* loop, uv_fs_event_t* handle) { int uv_fs_event_init(uv_loop_t* loop, uv_fs_event_t* handle) {
return -ENOSYS; return UV_ENOSYS;
} }
int uv_fs_event_start(uv_fs_event_t* handle, uv_fs_event_cb cb, int uv_fs_event_start(uv_fs_event_t* handle, uv_fs_event_cb cb,
const char* filename, unsigned int flags) { const char* filename, unsigned int flags) {
return -ENOSYS; return UV_ENOSYS;
} }
int uv_fs_event_stop(uv_fs_event_t* handle) { int uv_fs_event_stop(uv_fs_event_t* handle) {
return -ENOSYS; return UV_ENOSYS;
} }
void uv__fs_event_close(uv_fs_event_t* handle) { void uv__fs_event_close(uv_fs_event_t* handle) {
......
...@@ -35,7 +35,7 @@ int uv_set_process_title(const char* title) { ...@@ -35,7 +35,7 @@ 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) {
if (buffer == NULL || size == 0) if (buffer == NULL || size == 0)
return -EINVAL; return UV_EINVAL;
buffer[0] = '\0'; buffer[0] = '\0';
return 0; return 0;
......
...@@ -36,9 +36,16 @@ ...@@ -36,9 +36,16 @@
#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 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);
} }
...@@ -71,11 +78,11 @@ int uv_exepath(char* buffer, size_t* size) { ...@@ -71,11 +78,11 @@ int uv_exepath(char* buffer, size_t* size) {
int err; int err;
if (buffer == NULL || size == NULL || *size == 0) if (buffer == NULL || size == NULL || *size == 0)
return -EINVAL; return UV_EINVAL;
mypid = getpid(); mypid = getpid();
for (;;) { for (;;) {
err = -ENOMEM; err = UV_ENOMEM;
argsbuf_tmp = uv__realloc(argsbuf, argsbuf_size); argsbuf_tmp = uv__realloc(argsbuf, argsbuf_size);
if (argsbuf_tmp == NULL) if (argsbuf_tmp == NULL)
goto out; goto out;
...@@ -88,14 +95,14 @@ int uv_exepath(char* buffer, size_t* size) { ...@@ -88,14 +95,14 @@ int uv_exepath(char* buffer, size_t* size) {
break; break;
} }
if (errno != ENOMEM) { if (errno != ENOMEM) {
err = -errno; err = UV__ERR(errno);
goto out; goto out;
} }
argsbuf_size *= 2U; argsbuf_size *= 2U;
} }
if (argsbuf[0] == NULL) { if (argsbuf[0] == NULL) {
err = -EINVAL; /* FIXME(bnoordhuis) More appropriate error. */ err = UV_EINVAL; /* FIXME(bnoordhuis) More appropriate error. */
goto out; goto out;
} }
...@@ -121,7 +128,7 @@ uint64_t uv_get_free_memory(void) { ...@@ -121,7 +128,7 @@ uint64_t uv_get_free_memory(void) {
int which[] = {CTL_VM, VM_UVMEXP}; int which[] = {CTL_VM, VM_UVMEXP};
if (sysctl(which, 2, &info, &size, NULL, 0)) if (sysctl(which, 2, &info, &size, NULL, 0))
return -errno; return UV__ERR(errno);
return (uint64_t) info.free * sysconf(_SC_PAGESIZE); return (uint64_t) info.free * sysconf(_SC_PAGESIZE);
} }
...@@ -133,7 +140,7 @@ uint64_t uv_get_total_memory(void) { ...@@ -133,7 +140,7 @@ uint64_t uv_get_total_memory(void) {
size_t size = sizeof(info); size_t size = sizeof(info);
if (sysctl(which, 2, &info, &size, NULL, 0)) if (sysctl(which, 2, &info, &size, NULL, 0))
return -errno; return UV__ERR(errno);
return (uint64_t) info; return (uint64_t) info;
} }
...@@ -149,11 +156,21 @@ int uv_set_process_title(const char* title) { ...@@ -149,11 +156,21 @@ int uv_set_process_title(const char* title) {
char* new_title; char* new_title;
new_title = uv__strdup(title); new_title = uv__strdup(title);
if (process_title == NULL)
return -ENOMEM; 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); uv__free(process_title);
process_title = new_title; process_title = new_title;
setproctitle("%s", title); setproctitle("%s", title);
uv_mutex_unlock(&process_title_mutex);
return 0; return 0;
} }
...@@ -162,19 +179,26 @@ int uv_get_process_title(char* buffer, size_t size) { ...@@ -162,19 +179,26 @@ int uv_get_process_title(char* buffer, size_t size) {
size_t len; size_t len;
if (buffer == NULL || size == 0) if (buffer == NULL || size == 0)
return -EINVAL; return UV_EINVAL;
uv_once(&process_title_mutex_once, init_process_title_mutex_once);
uv_mutex_lock(&process_title_mutex);
if (process_title) { if (process_title) {
len = strlen(process_title) + 1; len = strlen(process_title) + 1;
if (size < len) if (size < len) {
return -ENOBUFS; uv_mutex_unlock(&process_title_mutex);
return UV_ENOBUFS;
}
memcpy(buffer, process_title, len); memcpy(buffer, process_title, len);
} else { } else {
len = 0; len = 0;
} }
uv_mutex_unlock(&process_title_mutex);
buffer[len] = '\0'; buffer[len] = '\0';
return 0; return 0;
...@@ -195,7 +219,7 @@ int uv_resident_set_memory(size_t* rss) { ...@@ -195,7 +219,7 @@ int uv_resident_set_memory(size_t* rss) {
mib[5] = 1; mib[5] = 1;
if (sysctl(mib, 6, &kinfo, &size, NULL, 0) < 0) if (sysctl(mib, 6, &kinfo, &size, NULL, 0) < 0)
return -errno; return UV__ERR(errno);
*rss = kinfo.p_vm_rssize * page_size; *rss = kinfo.p_vm_rssize * page_size;
return 0; return 0;
...@@ -209,7 +233,7 @@ int uv_uptime(double* uptime) { ...@@ -209,7 +233,7 @@ int uv_uptime(double* uptime) {
static int which[] = {CTL_KERN, KERN_BOOTTIME}; static int which[] = {CTL_KERN, KERN_BOOTTIME};
if (sysctl(which, 2, &info, &size, NULL, 0)) if (sysctl(which, 2, &info, &size, NULL, 0))
return -errno; return UV__ERR(errno);
now = time(NULL); now = time(NULL);
...@@ -231,16 +255,16 @@ int uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) { ...@@ -231,16 +255,16 @@ int uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) {
size = sizeof(model); size = sizeof(model);
if (sysctl(which, 2, &model, &size, NULL, 0)) if (sysctl(which, 2, &model, &size, NULL, 0))
return -errno; return UV__ERR(errno);
which[1] = HW_NCPU; which[1] = HW_NCPU;
size = sizeof(numcpus); size = sizeof(numcpus);
if (sysctl(which, 2, &numcpus, &size, NULL, 0)) if (sysctl(which, 2, &numcpus, &size, NULL, 0))
return -errno; return UV__ERR(errno);
*cpu_infos = uv__malloc(numcpus * sizeof(**cpu_infos)); *cpu_infos = uv__malloc(numcpus * sizeof(**cpu_infos));
if (!(*cpu_infos)) if (!(*cpu_infos))
return -ENOMEM; return UV_ENOMEM;
*count = numcpus; *count = numcpus;
...@@ -248,7 +272,7 @@ int uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) { ...@@ -248,7 +272,7 @@ int uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) {
size = sizeof(cpuspeed); size = sizeof(cpuspeed);
if (sysctl(which, 2, &cpuspeed, &size, NULL, 0)) { if (sysctl(which, 2, &cpuspeed, &size, NULL, 0)) {
uv__free(*cpu_infos); uv__free(*cpu_infos);
return -errno; return UV__ERR(errno);
} }
size = sizeof(info); size = sizeof(info);
...@@ -259,7 +283,7 @@ int uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) { ...@@ -259,7 +283,7 @@ int uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) {
size = sizeof(info); size = sizeof(info);
if (sysctl(which, 3, &info, &size, NULL, 0)) { if (sysctl(which, 3, &info, &size, NULL, 0)) {
uv__free(*cpu_infos); uv__free(*cpu_infos);
return -errno; return UV__ERR(errno);
} }
cpu_info = &(*cpu_infos)[i]; cpu_info = &(*cpu_infos)[i];
......
...@@ -25,6 +25,8 @@ ...@@ -25,6 +25,8 @@
#include <stdlib.h> #include <stdlib.h>
#include <assert.h> #include <assert.h>
#include <search.h> #include <search.h>
#include <termios.h>
#include <sys/msg.h>
#define CW_CONDVAR 32 #define CW_CONDVAR 32
...@@ -103,10 +105,19 @@ static void maybe_resize(uv__os390_epoll* lst, unsigned int len) { ...@@ -103,10 +105,19 @@ static void maybe_resize(uv__os390_epoll* lst, unsigned int len) {
unsigned int newsize; unsigned int newsize;
unsigned int i; unsigned int i;
struct pollfd* newlst; struct pollfd* newlst;
struct pollfd event;
if (len <= lst->size) if (len <= lst->size)
return; return;
if (lst->size == 0)
event.fd = -1;
else {
/* Extract the message queue at the end. */
event = lst->items[lst->size - 1];
lst->items[lst->size - 1].fd = -1;
}
newsize = next_power_of_two(len); newsize = next_power_of_two(len);
newlst = uv__realloc(lst->items, newsize * sizeof(lst->items[0])); newlst = uv__realloc(lst->items, newsize * sizeof(lst->items[0]));
...@@ -115,11 +126,40 @@ static void maybe_resize(uv__os390_epoll* lst, unsigned int len) { ...@@ -115,11 +126,40 @@ static void maybe_resize(uv__os390_epoll* lst, unsigned int len) {
for (i = lst->size; i < newsize; ++i) for (i = lst->size; i < newsize; ++i)
newlst[i].fd = -1; newlst[i].fd = -1;
/* Restore the message queue at the end */
newlst[newsize - 1] = event;
lst->items = newlst; lst->items = newlst;
lst->size = newsize; lst->size = newsize;
} }
static void init_message_queue(uv__os390_epoll* lst) {
struct {
long int header;
char body;
} msg;
/* initialize message queue */
lst->msg_queue = msgget(IPC_PRIVATE, 0622 | IPC_CREAT);
if (lst->msg_queue == -1)
abort();
/*
On z/OS, the message queue will be affiliated with the process only
when a send is performed on it. Once this is done, the system
can be queried for all message queues belonging to our process id.
*/
msg.header = 1;
if (msgsnd(lst->msg_queue, &msg, sizeof(msg.body), 0) != 0)
abort();
/* Clean up the dummy message sent above */
if (msgrcv(lst->msg_queue, &msg, sizeof(msg.body), 0, 0) != sizeof(msg.body))
abort();
}
static void before_fork(void) { static void before_fork(void) {
uv_mutex_lock(&global_epoll_lock); uv_mutex_lock(&global_epoll_lock);
} }
...@@ -139,8 +179,13 @@ static void child_fork(void) { ...@@ -139,8 +179,13 @@ static void child_fork(void) {
/* reset epoll list */ /* reset epoll list */
while (!QUEUE_EMPTY(&global_epoll_queue)) { while (!QUEUE_EMPTY(&global_epoll_queue)) {
uv__os390_epoll* lst;
q = QUEUE_HEAD(&global_epoll_queue); q = QUEUE_HEAD(&global_epoll_queue);
QUEUE_REMOVE(q); QUEUE_REMOVE(q);
lst = QUEUE_DATA(q, uv__os390_epoll, member);
uv__free(lst->items);
lst->items = NULL;
lst->size = 0;
} }
uv_mutex_unlock(&global_epoll_lock); uv_mutex_unlock(&global_epoll_lock);
...@@ -166,6 +211,10 @@ uv__os390_epoll* epoll_create1(int flags) { ...@@ -166,6 +211,10 @@ uv__os390_epoll* epoll_create1(int flags) {
/* initialize list */ /* initialize list */
lst->size = 0; lst->size = 0;
lst->items = NULL; lst->items = NULL;
init_message_queue(lst);
maybe_resize(lst, 1);
lst->items[lst->size - 1].fd = lst->msg_queue;
lst->items[lst->size - 1].events = POLLIN;
uv_once(&once, epoll_init); uv_once(&once, epoll_init);
uv_mutex_lock(&global_epoll_lock); uv_mutex_lock(&global_epoll_lock);
QUEUE_INSERT_TAIL(&global_epoll_queue, &lst->member); QUEUE_INSERT_TAIL(&global_epoll_queue, &lst->member);
...@@ -182,15 +231,20 @@ int epoll_ctl(uv__os390_epoll* lst, ...@@ -182,15 +231,20 @@ int epoll_ctl(uv__os390_epoll* lst,
struct epoll_event *event) { struct epoll_event *event) {
uv_mutex_lock(&global_epoll_lock); uv_mutex_lock(&global_epoll_lock);
if(op == EPOLL_CTL_DEL) { if (op == EPOLL_CTL_DEL) {
if (fd >= lst->size || lst->items[fd].fd == -1) { if (fd >= lst->size || lst->items[fd].fd == -1) {
uv_mutex_unlock(&global_epoll_lock); uv_mutex_unlock(&global_epoll_lock);
errno = ENOENT; errno = ENOENT;
return -1; return -1;
} }
lst->items[fd].fd = -1; lst->items[fd].fd = -1;
} else if(op == EPOLL_CTL_ADD) { } else if (op == EPOLL_CTL_ADD) {
maybe_resize(lst, fd + 1);
/* Resizing to 'fd + 1' would expand the list to contain at least
* 'fd'. But we need to guarantee that the last index on the list
* is reserved for the message queue. So specify 'fd + 2' instead.
*/
maybe_resize(lst, fd + 2);
if (lst->items[fd].fd != -1) { if (lst->items[fd].fd != -1) {
uv_mutex_unlock(&global_epoll_lock); uv_mutex_unlock(&global_epoll_lock);
errno = EEXIST; errno = EEXIST;
...@@ -198,7 +252,7 @@ int epoll_ctl(uv__os390_epoll* lst, ...@@ -198,7 +252,7 @@ int epoll_ctl(uv__os390_epoll* lst,
} }
lst->items[fd].fd = fd; lst->items[fd].fd = fd;
lst->items[fd].events = event->events; lst->items[fd].events = event->events;
} else if(op == EPOLL_CTL_MOD) { } else if (op == EPOLL_CTL_MOD) {
if (fd >= lst->size || lst->items[fd].fd == -1) { if (fd >= lst->size || lst->items[fd].fd == -1) {
uv_mutex_unlock(&global_epoll_lock); uv_mutex_unlock(&global_epoll_lock);
errno = ENOENT; errno = ENOENT;
...@@ -215,17 +269,19 @@ int epoll_ctl(uv__os390_epoll* lst, ...@@ -215,17 +269,19 @@ int epoll_ctl(uv__os390_epoll* lst,
int epoll_wait(uv__os390_epoll* lst, struct epoll_event* events, int epoll_wait(uv__os390_epoll* lst, struct epoll_event* events,
int maxevents, int timeout) { int maxevents, int timeout) {
size_t size; nmsgsfds_t size;
struct pollfd* pfds; struct pollfd* pfds;
int pollret; int pollret;
int reventcount; int reventcount;
size = lst->size; size = _SET_FDS_MSGS(size, 1, lst->size - 1);
pfds = lst->items; pfds = lst->items;
pollret = poll(pfds, size, timeout); pollret = poll(pfds, size, timeout);
if (pollret <= 0) if (pollret <= 0)
return pollret; return pollret;
pollret = _NFDS(pollret) + _NMSGS(pollret);
reventcount = 0; reventcount = 0;
for (int i = 0; for (int i = 0;
i < lst->size && i < maxevents && reventcount < pollret; ++i) { i < lst->size && i < maxevents && reventcount < pollret; ++i) {
...@@ -261,9 +317,14 @@ int epoll_file_close(int fd) { ...@@ -261,9 +317,14 @@ int epoll_file_close(int fd) {
} }
void epoll_queue_close(uv__os390_epoll* lst) { void epoll_queue_close(uv__os390_epoll* lst) {
/* Remove epoll instance from global queue */
uv_mutex_lock(&global_epoll_lock); uv_mutex_lock(&global_epoll_lock);
QUEUE_REMOVE(&lst->member); QUEUE_REMOVE(&lst->member);
uv_mutex_unlock(&global_epoll_lock); uv_mutex_unlock(&global_epoll_lock);
/* Free resources */
msgctl(lst->msg_queue, IPC_RMID, NULL);
lst->msg_queue = -1;
uv__free(lst->items); uv__free(lst->items);
lst->items = NULL; lst->items = NULL;
} }
......
...@@ -50,6 +50,7 @@ typedef struct { ...@@ -50,6 +50,7 @@ typedef struct {
QUEUE member; QUEUE member;
struct pollfd* items; struct pollfd* items;
unsigned long size; unsigned long size;
int msg_queue;
} uv__os390_epoll; } uv__os390_epoll;
/* epoll api */ /* epoll api */
......
...@@ -26,6 +26,8 @@ ...@@ -26,6 +26,8 @@
#include <unistd.h> #include <unistd.h>
#include <sys/ps.h> #include <sys/ps.h>
#include <builtins.h> #include <builtins.h>
#include <termios.h>
#include <sys/msg.h>
#if defined(__clang__) #if defined(__clang__)
#include "csrsic.h" #include "csrsic.h"
#else #else
...@@ -120,7 +122,7 @@ int uv__platform_loop_init(uv_loop_t* loop) { ...@@ -120,7 +122,7 @@ int uv__platform_loop_init(uv_loop_t* loop) {
ep = epoll_create1(0); ep = epoll_create1(0);
loop->ep = ep; loop->ep = ep;
if (ep == NULL) if (ep == NULL)
return -errno; return UV__ERR(errno);
return 0; return 0;
} }
...@@ -257,12 +259,12 @@ int uv_exepath(char* buffer, size_t* size) { ...@@ -257,12 +259,12 @@ int uv_exepath(char* buffer, size_t* size) {
int pid; int pid;
if (buffer == NULL || size == NULL || *size == 0) if (buffer == NULL || size == NULL || *size == 0)
return -EINVAL; return UV_EINVAL;
pid = getpid(); pid = getpid();
res = getexe(pid, args, sizeof(args)); res = getexe(pid, args, sizeof(args));
if (res < 0) if (res < 0)
return -EINVAL; return UV_EINVAL;
/* /*
* Possibilities for args: * Possibilities for args:
...@@ -275,7 +277,7 @@ int uv_exepath(char* buffer, size_t* size) { ...@@ -275,7 +277,7 @@ int uv_exepath(char* buffer, size_t* size) {
/* Case i) and ii) absolute or relative paths */ /* Case i) and ii) absolute or relative paths */
if (strchr(args, '/') != NULL) { if (strchr(args, '/') != NULL) {
if (realpath(args, abspath) != abspath) if (realpath(args, abspath) != abspath)
return -errno; return UV__ERR(errno);
abspath_size = strlen(abspath); abspath_size = strlen(abspath);
...@@ -295,11 +297,11 @@ int uv_exepath(char* buffer, size_t* size) { ...@@ -295,11 +297,11 @@ int uv_exepath(char* buffer, size_t* size) {
char* path = getenv("PATH"); char* path = getenv("PATH");
if (path == NULL) if (path == NULL)
return -EINVAL; return UV_EINVAL;
clonedpath = uv__strdup(path); clonedpath = uv__strdup(path);
if (clonedpath == NULL) if (clonedpath == NULL)
return -ENOMEM; return UV_ENOMEM;
token = strtok(clonedpath, ":"); token = strtok(clonedpath, ":");
while (token != NULL) { while (token != NULL) {
...@@ -325,7 +327,7 @@ int uv_exepath(char* buffer, size_t* size) { ...@@ -325,7 +327,7 @@ int uv_exepath(char* buffer, size_t* size) {
uv__free(clonedpath); uv__free(clonedpath);
/* Out of tokens (path entries), and no match found */ /* Out of tokens (path entries), and no match found */
return -EINVAL; return UV_EINVAL;
} }
} }
...@@ -405,7 +407,7 @@ int uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) { ...@@ -405,7 +407,7 @@ int uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) {
*cpu_infos = uv__malloc(*count * sizeof(uv_cpu_info_t)); *cpu_infos = uv__malloc(*count * sizeof(uv_cpu_info_t));
if (!*cpu_infos) if (!*cpu_infos)
return -ENOMEM; return UV_ENOMEM;
cpu_info = *cpu_infos; cpu_info = *cpu_infos;
idx = 0; idx = 0;
...@@ -450,7 +452,7 @@ static int uv__interface_addresses_v6(uv_interface_address_t** addresses, ...@@ -450,7 +452,7 @@ static int uv__interface_addresses_v6(uv_interface_address_t** addresses,
maxsize = 16384; maxsize = 16384;
if (0 > (sockfd = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP))) if (0 > (sockfd = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP)))
return -errno; return UV__ERR(errno);
ifc.__nif6h_version = 1; ifc.__nif6h_version = 1;
ifc.__nif6h_buflen = maxsize; ifc.__nif6h_buflen = maxsize;
...@@ -458,7 +460,7 @@ static int uv__interface_addresses_v6(uv_interface_address_t** addresses, ...@@ -458,7 +460,7 @@ static int uv__interface_addresses_v6(uv_interface_address_t** addresses,
if (ioctl(sockfd, SIOCGIFCONF6, &ifc) == -1) { if (ioctl(sockfd, SIOCGIFCONF6, &ifc) == -1) {
uv__close(sockfd); uv__close(sockfd);
return -errno; return UV__ERR(errno);
} }
...@@ -482,7 +484,7 @@ static int uv__interface_addresses_v6(uv_interface_address_t** addresses, ...@@ -482,7 +484,7 @@ static int uv__interface_addresses_v6(uv_interface_address_t** addresses,
*addresses = uv__malloc(*count * sizeof(uv_interface_address_t)); *addresses = uv__malloc(*count * sizeof(uv_interface_address_t));
if (!(*addresses)) { if (!(*addresses)) {
uv__close(sockfd); uv__close(sockfd);
return -ENOMEM; return UV_ENOMEM;
} }
address = *addresses; address = *addresses;
...@@ -541,13 +543,13 @@ int uv_interface_addresses(uv_interface_address_t** addresses, int* count) { ...@@ -541,13 +543,13 @@ int uv_interface_addresses(uv_interface_address_t** addresses, int* count) {
sockfd = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP); sockfd = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP);
if (0 > sockfd) if (0 > sockfd)
return -errno; return UV__ERR(errno);
ifc.ifc_req = uv__calloc(1, maxsize); ifc.ifc_req = uv__calloc(1, maxsize);
ifc.ifc_len = maxsize; ifc.ifc_len = maxsize;
if (ioctl(sockfd, SIOCGIFCONF, &ifc) == -1) { if (ioctl(sockfd, SIOCGIFCONF, &ifc) == -1) {
uv__close(sockfd); uv__close(sockfd);
return -errno; return UV__ERR(errno);
} }
#define MAX(a,b) (((a)>(b))?(a):(b)) #define MAX(a,b) (((a)>(b))?(a):(b))
...@@ -567,7 +569,7 @@ int uv_interface_addresses(uv_interface_address_t** addresses, int* count) { ...@@ -567,7 +569,7 @@ int uv_interface_addresses(uv_interface_address_t** addresses, int* count) {
memcpy(flg.ifr_name, p->ifr_name, sizeof(flg.ifr_name)); memcpy(flg.ifr_name, p->ifr_name, sizeof(flg.ifr_name));
if (ioctl(sockfd, SIOCGIFFLAGS, &flg) == -1) { if (ioctl(sockfd, SIOCGIFFLAGS, &flg) == -1) {
uv__close(sockfd); uv__close(sockfd);
return -errno; return UV__ERR(errno);
} }
if (!(flg.ifr_flags & IFF_UP && flg.ifr_flags & IFF_RUNNING)) if (!(flg.ifr_flags & IFF_UP && flg.ifr_flags & IFF_RUNNING))
...@@ -582,7 +584,7 @@ int uv_interface_addresses(uv_interface_address_t** addresses, int* count) { ...@@ -582,7 +584,7 @@ int uv_interface_addresses(uv_interface_address_t** addresses, int* count) {
if (!(*addresses)) { if (!(*addresses)) {
uv__close(sockfd); uv__close(sockfd);
return -ENOMEM; return UV_ENOMEM;
} }
address = *addresses; address = *addresses;
...@@ -605,7 +607,7 @@ int uv_interface_addresses(uv_interface_address_t** addresses, int* count) { ...@@ -605,7 +607,7 @@ int uv_interface_addresses(uv_interface_address_t** addresses, int* count) {
memcpy(flg.ifr_name, p->ifr_name, sizeof(flg.ifr_name)); memcpy(flg.ifr_name, p->ifr_name, sizeof(flg.ifr_name));
if (ioctl(sockfd, SIOCGIFFLAGS, &flg) == -1) { if (ioctl(sockfd, SIOCGIFFLAGS, &flg) == -1) {
uv__close(sockfd); uv__close(sockfd);
return -ENOSYS; return UV_ENOSYS;
} }
if (!(flg.ifr_flags & IFF_UP && flg.ifr_flags & IFF_RUNNING)) if (!(flg.ifr_flags & IFF_UP && flg.ifr_flags & IFF_RUNNING))
...@@ -684,11 +686,124 @@ int uv__io_check_fd(uv_loop_t* loop, int fd) { ...@@ -684,11 +686,124 @@ int uv__io_check_fd(uv_loop_t* loop, int fd) {
return 0; return 0;
} }
void uv__fs_event_close(uv_fs_event_t* handle) {
uv_fs_event_stop(handle);
}
int uv_fs_event_init(uv_loop_t* loop, uv_fs_event_t* handle) {
uv__handle_init(loop, (uv_handle_t*)handle, UV_FS_EVENT);
return 0;
}
int uv_fs_event_start(uv_fs_event_t* handle, uv_fs_event_cb cb,
const char* filename, unsigned int flags) {
uv__os390_epoll* ep;
_RFIS reg_struct;
char* path;
int rc;
if (uv__is_active(handle))
return UV_EINVAL;
ep = handle->loop->ep;
assert(ep->msg_queue != -1);
reg_struct.__rfis_cmd = _RFIS_REG;
reg_struct.__rfis_qid = ep->msg_queue;
reg_struct.__rfis_type = 1;
memcpy(reg_struct.__rfis_utok, &handle, sizeof(handle));
path = uv__strdup(filename);
if (path == NULL)
return UV_ENOMEM;
rc = __w_pioctl(path, _IOCC_REGFILEINT, sizeof(reg_struct), &reg_struct);
if (rc != 0)
return UV__ERR(errno);
uv__handle_start(handle);
handle->path = path;
handle->cb = cb;
memcpy(handle->rfis_rftok, reg_struct.__rfis_rftok,
sizeof(handle->rfis_rftok));
return 0;
}
int uv_fs_event_stop(uv_fs_event_t* handle) {
uv__os390_epoll* ep;
_RFIS reg_struct;
int rc;
if (!uv__is_active(handle))
return 0;
ep = handle->loop->ep;
assert(ep->msg_queue != -1);
reg_struct.__rfis_cmd = _RFIS_UNREG;
reg_struct.__rfis_qid = ep->msg_queue;
reg_struct.__rfis_type = 1;
memcpy(reg_struct.__rfis_rftok, handle->rfis_rftok,
sizeof(handle->rfis_rftok));
/*
* This call will take "/" as the path argument in case we
* don't care to supply the correct path. The system will simply
* ignore it.
*/
rc = __w_pioctl("/", _IOCC_REGFILEINT, sizeof(reg_struct), &reg_struct);
if (rc != 0 && errno != EALREADY && errno != ENOENT)
abort();
uv__handle_stop(handle);
return 0;
}
static int os390_message_queue_handler(uv__os390_epoll* ep) {
uv_fs_event_t* handle;
int msglen;
int events;
_RFIM msg;
if (ep->msg_queue == -1)
return 0;
msglen = msgrcv(ep->msg_queue, &msg, sizeof(msg), 0, IPC_NOWAIT);
if (msglen == -1 && errno == ENOMSG)
return 0;
if (msglen == -1)
abort();
events = 0;
if (msg.__rfim_event == _RFIM_ATTR || msg.__rfim_event == _RFIM_WRITE)
events = UV_CHANGE;
else if (msg.__rfim_event == _RFIM_RENAME)
events = UV_RENAME;
else
/* Some event that we are not interested in. */
return 0;
handle = *(uv_fs_event_t**)(msg.__rfim_utok);
handle->cb(handle, uv__basename_r(handle->path), events, 0);
return 1;
}
void uv__io_poll(uv_loop_t* loop, int timeout) { void uv__io_poll(uv_loop_t* loop, int timeout) {
static const int max_safe_timeout = 1789569; static const int max_safe_timeout = 1789569;
struct epoll_event events[1024]; struct epoll_event events[1024];
struct epoll_event* pe; struct epoll_event* pe;
struct epoll_event e; struct epoll_event e;
uv__os390_epoll* ep;
int real_timeout; int real_timeout;
QUEUE* q; QUEUE* q;
uv__io_t* w; uv__io_t* w;
...@@ -802,6 +917,12 @@ void uv__io_poll(uv_loop_t* loop, int timeout) { ...@@ -802,6 +917,12 @@ void uv__io_poll(uv_loop_t* loop, int timeout) {
if (fd == -1) if (fd == -1)
continue; continue;
ep = loop->ep;
if (fd == ep->msg_queue) {
os390_message_queue_handler(ep);
continue;
}
assert(fd >= 0); assert(fd >= 0);
assert((unsigned) fd < loop->nwatchers); assert((unsigned) fd < loop->nwatchers);
...@@ -866,7 +987,12 @@ void uv__set_process_title(const char* title) { ...@@ -866,7 +987,12 @@ void uv__set_process_title(const char* title) {
} }
int uv__io_fork(uv_loop_t* loop) { int uv__io_fork(uv_loop_t* loop) {
uv__platform_loop_delete(loop); /*
Nullify the msg queue but don't close it because
it is still being used by the parent.
*/
loop->ep = NULL;
uv__platform_loop_delete(loop);
return uv__platform_loop_init(loop); return uv__platform_loop_init(loop);
} }
...@@ -50,12 +50,12 @@ int uv_pipe_bind(uv_pipe_t* handle, const char* name) { ...@@ -50,12 +50,12 @@ int uv_pipe_bind(uv_pipe_t* handle, const char* name) {
/* Already bound? */ /* Already bound? */
if (uv__stream_fd(handle) >= 0) if (uv__stream_fd(handle) >= 0)
return -EINVAL; return UV_EINVAL;
/* Make a copy of the file name, it outlives this function's scope. */ /* Make a copy of the file name, it outlives this function's scope. */
pipe_fname = uv__strdup(name); pipe_fname = uv__strdup(name);
if (pipe_fname == NULL) if (pipe_fname == NULL)
return -ENOMEM; return UV_ENOMEM;
/* We've got a copy, don't touch the original any more. */ /* We've got a copy, don't touch the original any more. */
name = NULL; name = NULL;
...@@ -71,10 +71,10 @@ int uv_pipe_bind(uv_pipe_t* handle, const char* name) { ...@@ -71,10 +71,10 @@ int uv_pipe_bind(uv_pipe_t* handle, const char* name) {
saddr.sun_family = AF_UNIX; saddr.sun_family = AF_UNIX;
if (bind(sockfd, (struct sockaddr*)&saddr, sizeof saddr)) { if (bind(sockfd, (struct sockaddr*)&saddr, sizeof saddr)) {
err = -errno; err = UV__ERR(errno);
/* Convert ENOENT to EACCES for compatibility with Windows. */ /* Convert ENOENT to EACCES for compatibility with Windows. */
if (err == -ENOENT) if (err == UV_ENOENT)
err = -EACCES; err = UV_EACCES;
uv__close(sockfd); uv__close(sockfd);
goto err_socket; goto err_socket;
...@@ -94,7 +94,7 @@ err_socket: ...@@ -94,7 +94,7 @@ err_socket:
int uv_pipe_listen(uv_pipe_t* handle, int backlog, uv_connection_cb cb) { int uv_pipe_listen(uv_pipe_t* handle, int backlog, uv_connection_cb cb) {
if (uv__stream_fd(handle) == -1) if (uv__stream_fd(handle) == -1)
return -EINVAL; return UV_EINVAL;
#if defined(__MVS__) #if defined(__MVS__)
/* On zOS, backlog=0 has undefined behaviour */ /* On zOS, backlog=0 has undefined behaviour */
...@@ -105,7 +105,7 @@ int uv_pipe_listen(uv_pipe_t* handle, int backlog, uv_connection_cb cb) { ...@@ -105,7 +105,7 @@ int uv_pipe_listen(uv_pipe_t* handle, int backlog, uv_connection_cb cb) {
#endif #endif
if (listen(uv__stream_fd(handle), backlog)) if (listen(uv__stream_fd(handle), backlog))
return -errno; return UV__ERR(errno);
handle->connection_cb = cb; handle->connection_cb = cb;
handle->io_watcher.cb = uv__server_io; handle->io_watcher.cb = uv__server_io;
...@@ -180,14 +180,14 @@ void uv_pipe_connect(uv_connect_t* req, ...@@ -180,14 +180,14 @@ void uv_pipe_connect(uv_connect_t* req,
while (r == -1 && errno == EINTR); while (r == -1 && errno == EINTR);
if (r == -1 && errno != EINPROGRESS) { if (r == -1 && errno != EINPROGRESS) {
err = -errno; err = UV__ERR(errno);
#if defined(__CYGWIN__) || defined(__MSYS__) #if defined(__CYGWIN__) || defined(__MSYS__)
/* EBADF is supposed to mean that the socket fd is bad, but /* EBADF is supposed to mean that the socket fd is bad, but
Cygwin reports EBADF instead of ENOTSOCK when the file is Cygwin reports EBADF instead of ENOTSOCK when the file is
not a socket. We do not expect to see a bad fd here not a socket. We do not expect to see a bad fd here
(e.g. due to new_sock), so translate the error. */ (e.g. due to new_sock), so translate the error. */
if (err == -EBADF) if (err == UV_EBADF)
err = -ENOTSOCK; err = UV_ENOTSOCK;
#endif #endif
goto out; goto out;
} }
...@@ -234,7 +234,7 @@ static int uv__pipe_getsockpeername(const uv_pipe_t* handle, ...@@ -234,7 +234,7 @@ static int uv__pipe_getsockpeername(const uv_pipe_t* handle,
err = func(uv__stream_fd(handle), (struct sockaddr*) &sa, &addrlen); err = func(uv__stream_fd(handle), (struct sockaddr*) &sa, &addrlen);
if (err < 0) { if (err < 0) {
*size = 0; *size = 0;
return -errno; return UV__ERR(errno);
} }
#if defined(__linux__) #if defined(__linux__)
...@@ -312,15 +312,15 @@ int uv_pipe_chmod(uv_pipe_t* handle, int mode) { ...@@ -312,15 +312,15 @@ int uv_pipe_chmod(uv_pipe_t* handle, int mode) {
int r; int r;
if (handle == NULL || uv__stream_fd(handle) == -1) if (handle == NULL || uv__stream_fd(handle) == -1)
return -EBADF; return UV_EBADF;
if (mode != UV_READABLE && if (mode != UV_READABLE &&
mode != UV_WRITABLE && mode != UV_WRITABLE &&
mode != (UV_WRITABLE | UV_READABLE)) mode != (UV_WRITABLE | UV_READABLE))
return -EINVAL; return UV_EINVAL;
if (fstat(uv__stream_fd(handle), &pipe_stat) == -1) if (fstat(uv__stream_fd(handle), &pipe_stat) == -1)
return -errno; return UV__ERR(errno);
desired_mode = 0; desired_mode = 0;
if (mode & UV_READABLE) if (mode & UV_READABLE)
...@@ -353,5 +353,5 @@ int uv_pipe_chmod(uv_pipe_t* handle, int mode) { ...@@ -353,5 +353,5 @@ int uv_pipe_chmod(uv_pipe_t* handle, int mode) {
r = chmod(name_buffer, pipe_stat.st_mode); r = chmod(name_buffer, pipe_stat.st_mode);
uv__free(name_buffer); uv__free(name_buffer);
return r != -1 ? 0 : -errno; return r != -1 ? 0 : UV__ERR(errno);
} }
...@@ -47,7 +47,7 @@ static void uv__poll_io(uv_loop_t* loop, uv__io_t* w, unsigned int events) { ...@@ -47,7 +47,7 @@ static void uv__poll_io(uv_loop_t* loop, uv__io_t* w, unsigned int events) {
if ((events & POLLERR) && !(events & UV__POLLPRI)) { if ((events & POLLERR) && !(events & UV__POLLPRI)) {
uv__io_stop(loop, w, POLLIN | POLLOUT | UV__POLLRDHUP | UV__POLLPRI); uv__io_stop(loop, w, POLLIN | POLLOUT | UV__POLLRDHUP | UV__POLLPRI);
uv__handle_stop(handle); uv__handle_stop(handle);
handle->poll_cb(handle, -EBADF, 0); handle->poll_cb(handle, UV_EBADF, 0);
return; return;
} }
...@@ -76,7 +76,7 @@ int uv_poll_init(uv_loop_t* loop, uv_poll_t* handle, int fd) { ...@@ -76,7 +76,7 @@ int uv_poll_init(uv_loop_t* loop, uv_poll_t* handle, int fd) {
* Workaround for e.g. kqueue fds not supporting ioctls. * Workaround for e.g. kqueue fds not supporting ioctls.
*/ */
err = uv__nonblock(fd, 1); err = uv__nonblock(fd, 1);
if (err == -ENOTTY) if (err == UV_ENOTTY)
if (uv__nonblock == uv__nonblock_ioctl) if (uv__nonblock == uv__nonblock_ioctl)
err = uv__nonblock_fcntl(fd, 1); err = uv__nonblock_fcntl(fd, 1);
......
...@@ -315,10 +315,10 @@ int uv__io_check_fd(uv_loop_t* loop, int fd) { ...@@ -315,10 +315,10 @@ int uv__io_check_fd(uv_loop_t* loop, int fd) {
while (rv == -1 && (errno == EINTR || errno == EAGAIN)); while (rv == -1 && (errno == EINTR || errno == EAGAIN));
if (rv == -1) if (rv == -1)
return -errno; return UV__ERR(errno);
if (p[0].revents & POLLNVAL) if (p[0].revents & POLLNVAL)
return -EINVAL; return UV_EINVAL;
return 0; return 0;
} }
...@@ -126,7 +126,7 @@ int uv__make_socketpair(int fds[2], int flags) { ...@@ -126,7 +126,7 @@ int uv__make_socketpair(int fds[2], int flags) {
* Anything else is a genuine error. * Anything else is a genuine error.
*/ */
if (errno != EINVAL) if (errno != EINVAL)
return -errno; return UV__ERR(errno);
no_cloexec = 1; no_cloexec = 1;
...@@ -134,7 +134,7 @@ skip: ...@@ -134,7 +134,7 @@ skip:
#endif #endif
if (socketpair(AF_UNIX, SOCK_STREAM, 0, fds)) if (socketpair(AF_UNIX, SOCK_STREAM, 0, fds))
return -errno; return UV__ERR(errno);
uv__cloexec(fds[0], 1); uv__cloexec(fds[0], 1);
uv__cloexec(fds[1], 1); uv__cloexec(fds[1], 1);
...@@ -159,7 +159,7 @@ int uv__make_pipe(int fds[2], int flags) { ...@@ -159,7 +159,7 @@ int uv__make_pipe(int fds[2], int flags) {
return 0; return 0;
if (errno != ENOSYS) if (errno != ENOSYS)
return -errno; return UV__ERR(errno);
no_pipe2 = 1; no_pipe2 = 1;
...@@ -167,7 +167,7 @@ skip: ...@@ -167,7 +167,7 @@ skip:
#endif #endif
if (pipe(fds)) if (pipe(fds))
return -errno; return UV__ERR(errno);
uv__cloexec(fds[0], 1); uv__cloexec(fds[0], 1);
uv__cloexec(fds[1], 1); uv__cloexec(fds[1], 1);
...@@ -198,7 +198,7 @@ static int uv__process_init_stdio(uv_stdio_container_t* container, int fds[2]) { ...@@ -198,7 +198,7 @@ static int uv__process_init_stdio(uv_stdio_container_t* container, int fds[2]) {
case UV_CREATE_PIPE: case UV_CREATE_PIPE:
assert(container->data.stream != NULL); assert(container->data.stream != NULL);
if (container->data.stream->type != UV_NAMED_PIPE) if (container->data.stream->type != UV_NAMED_PIPE)
return -EINVAL; return UV_EINVAL;
else else
return uv__make_socketpair(fds, 0); return uv__make_socketpair(fds, 0);
...@@ -210,14 +210,14 @@ static int uv__process_init_stdio(uv_stdio_container_t* container, int fds[2]) { ...@@ -210,14 +210,14 @@ static int uv__process_init_stdio(uv_stdio_container_t* container, int fds[2]) {
fd = uv__stream_fd(container->data.stream); fd = uv__stream_fd(container->data.stream);
if (fd == -1) if (fd == -1)
return -EINVAL; return UV_EINVAL;
fds[1] = fd; fds[1] = fd;
return 0; return 0;
default: default:
assert(0 && "Unexpected flags"); assert(0 && "Unexpected flags");
return -EINVAL; return UV_EINVAL;
} }
} }
...@@ -299,7 +299,7 @@ static void uv__process_child_init(const uv_process_options_t* options, ...@@ -299,7 +299,7 @@ static void uv__process_child_init(const uv_process_options_t* options,
continue; continue;
pipes[fd][1] = fcntl(use_fd, F_DUPFD, stdio_count); pipes[fd][1] = fcntl(use_fd, F_DUPFD, stdio_count);
if (pipes[fd][1] == -1) { if (pipes[fd][1] == -1) {
uv__write_int(error_fd, -errno); uv__write_int(error_fd, UV__ERR(errno));
_exit(127); _exit(127);
} }
} }
...@@ -319,7 +319,7 @@ static void uv__process_child_init(const uv_process_options_t* options, ...@@ -319,7 +319,7 @@ static void uv__process_child_init(const uv_process_options_t* options,
close_fd = use_fd; close_fd = use_fd;
if (use_fd == -1) { if (use_fd == -1) {
uv__write_int(error_fd, -errno); uv__write_int(error_fd, UV__ERR(errno));
_exit(127); _exit(127);
} }
} }
...@@ -331,7 +331,7 @@ static void uv__process_child_init(const uv_process_options_t* options, ...@@ -331,7 +331,7 @@ static void uv__process_child_init(const uv_process_options_t* options,
fd = dup2(use_fd, fd); fd = dup2(use_fd, fd);
if (fd == -1) { if (fd == -1) {
uv__write_int(error_fd, -errno); uv__write_int(error_fd, UV__ERR(errno));
_exit(127); _exit(127);
} }
...@@ -350,7 +350,7 @@ static void uv__process_child_init(const uv_process_options_t* options, ...@@ -350,7 +350,7 @@ static void uv__process_child_init(const uv_process_options_t* options,
} }
if (options->cwd != NULL && chdir(options->cwd)) { if (options->cwd != NULL && chdir(options->cwd)) {
uv__write_int(error_fd, -errno); uv__write_int(error_fd, UV__ERR(errno));
_exit(127); _exit(127);
} }
...@@ -366,12 +366,12 @@ static void uv__process_child_init(const uv_process_options_t* options, ...@@ -366,12 +366,12 @@ static void uv__process_child_init(const uv_process_options_t* options,
} }
if ((options->flags & UV_PROCESS_SETGID) && setgid(options->gid)) { if ((options->flags & UV_PROCESS_SETGID) && setgid(options->gid)) {
uv__write_int(error_fd, -errno); uv__write_int(error_fd, UV__ERR(errno));
_exit(127); _exit(127);
} }
if ((options->flags & UV_PROCESS_SETUID) && setuid(options->uid)) { if ((options->flags & UV_PROCESS_SETUID) && setuid(options->uid)) {
uv__write_int(error_fd, -errno); uv__write_int(error_fd, UV__ERR(errno));
_exit(127); _exit(127);
} }
...@@ -391,7 +391,7 @@ static void uv__process_child_init(const uv_process_options_t* options, ...@@ -391,7 +391,7 @@ static void uv__process_child_init(const uv_process_options_t* options,
if (SIG_ERR != signal(n, SIG_DFL)) if (SIG_ERR != signal(n, SIG_DFL))
continue; continue;
uv__write_int(error_fd, -errno); uv__write_int(error_fd, UV__ERR(errno));
_exit(127); _exit(127);
} }
...@@ -400,12 +400,12 @@ static void uv__process_child_init(const uv_process_options_t* options, ...@@ -400,12 +400,12 @@ static void uv__process_child_init(const uv_process_options_t* options,
err = pthread_sigmask(SIG_SETMASK, &set, NULL); err = pthread_sigmask(SIG_SETMASK, &set, NULL);
if (err != 0) { if (err != 0) {
uv__write_int(error_fd, -err); uv__write_int(error_fd, UV__ERR(err));
_exit(127); _exit(127);
} }
execvp(options->file, options->args); execvp(options->file, options->args);
uv__write_int(error_fd, -errno); uv__write_int(error_fd, UV__ERR(errno));
_exit(127); _exit(127);
} }
#endif #endif
...@@ -416,7 +416,7 @@ int uv_spawn(uv_loop_t* loop, ...@@ -416,7 +416,7 @@ int uv_spawn(uv_loop_t* loop,
const uv_process_options_t* options) { const uv_process_options_t* options) {
#if defined(__APPLE__) && (TARGET_OS_TV || TARGET_OS_WATCH) #if defined(__APPLE__) && (TARGET_OS_TV || TARGET_OS_WATCH)
/* fork is marked __WATCHOS_PROHIBITED __TVOS_PROHIBITED. */ /* fork is marked __WATCHOS_PROHIBITED __TVOS_PROHIBITED. */
return -ENOSYS; return UV_ENOSYS;
#else #else
int signal_pipe[2] = { -1, -1 }; int signal_pipe[2] = { -1, -1 };
int pipes_storage[8][2]; int pipes_storage[8][2];
...@@ -443,7 +443,7 @@ int uv_spawn(uv_loop_t* loop, ...@@ -443,7 +443,7 @@ int uv_spawn(uv_loop_t* loop,
if (stdio_count < 3) if (stdio_count < 3)
stdio_count = 3; stdio_count = 3;
err = -ENOMEM; err = UV_ENOMEM;
pipes = pipes_storage; pipes = pipes_storage;
if (stdio_count > (int) ARRAY_SIZE(pipes_storage)) if (stdio_count > (int) ARRAY_SIZE(pipes_storage))
pipes = uv__malloc(stdio_count * sizeof(*pipes)); pipes = uv__malloc(stdio_count * sizeof(*pipes));
...@@ -493,7 +493,7 @@ int uv_spawn(uv_loop_t* loop, ...@@ -493,7 +493,7 @@ int uv_spawn(uv_loop_t* loop,
pid = fork(); pid = fork();
if (pid == -1) { if (pid == -1) {
err = -errno; err = UV__ERR(errno);
uv_rwlock_wrunlock(&loop->cloexec_lock); uv_rwlock_wrunlock(&loop->cloexec_lock);
uv__close(signal_pipe[0]); uv__close(signal_pipe[0]);
uv__close(signal_pipe[1]); uv__close(signal_pipe[1]);
...@@ -585,7 +585,7 @@ int uv_process_kill(uv_process_t* process, int signum) { ...@@ -585,7 +585,7 @@ int uv_process_kill(uv_process_t* process, int signum) {
int uv_kill(int pid, int signum) { int uv_kill(int pid, int signum) {
if (kill(pid, signum)) if (kill(pid, signum))
return -errno; return UV__ERR(errno);
else else
return 0; return 0;
} }
......
...@@ -29,14 +29,14 @@ int uv_exepath(char* buffer, size_t* size) { ...@@ -29,14 +29,14 @@ int uv_exepath(char* buffer, size_t* size) {
ssize_t n; ssize_t n;
if (buffer == NULL || size == NULL || *size == 0) if (buffer == NULL || size == NULL || *size == 0)
return -EINVAL; return UV_EINVAL;
n = *size - 1; n = *size - 1;
if (n > 0) if (n > 0)
n = readlink("/proc/self/exe", buffer, n); n = readlink("/proc/self/exe", buffer, n);
if (n == -1) if (n == -1)
return -errno; return UV__ERR(errno);
buffer[n] = '\0'; buffer[n] = '\0';
*size = n; *size = n;
......
...@@ -26,6 +26,8 @@ ...@@ -26,6 +26,8 @@
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_once_t process_title_mutex_once = UV_ONCE_INIT;
static void* args_mem; static void* args_mem;
static struct { static struct {
...@@ -34,6 +36,11 @@ static struct { ...@@ -34,6 +36,11 @@ static struct {
} process_title; } process_title;
static void init_process_title_mutex_once(void) {
uv_mutex_init(&process_title_mutex);
}
char** uv_setup_args(int argc, char** argv) { char** uv_setup_args(int argc, char** argv) {
char** new_argv; char** new_argv;
size_t size; size_t size;
...@@ -81,12 +88,16 @@ char** uv_setup_args(int argc, char** argv) { ...@@ -81,12 +88,16 @@ char** uv_setup_args(int argc, char** argv) {
int uv_set_process_title(const char* title) { int uv_set_process_title(const char* title) {
if (process_title.len == 0) uv_once(&process_title_mutex_once, init_process_title_mutex_once);
return 0; uv_mutex_lock(&process_title_mutex);
if (process_title.len != 0) {
/* No need to terminate, byte after is always '\0'. */
strncpy(process_title.str, title, process_title.len);
uv__set_process_title(title);
}
/* No need to terminate, byte after is always '\0'. */ uv_mutex_unlock(&process_title_mutex);
strncpy(process_title.str, title, process_title.len);
uv__set_process_title(title);
return 0; return 0;
} }
...@@ -94,15 +105,23 @@ int uv_set_process_title(const char* title) { ...@@ -94,15 +105,23 @@ 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) {
if (buffer == NULL || size == 0) if (buffer == NULL || size == 0)
return -EINVAL; return UV_EINVAL;
else if (size <= process_title.len)
return -ENOBUFS; uv_once(&process_title_mutex_once, init_process_title_mutex_once);
uv_mutex_lock(&process_title_mutex);
if (size <= process_title.len) {
uv_mutex_unlock(&process_title_mutex);
return UV_ENOBUFS;
}
if (process_title.len != 0) if (process_title.len != 0)
memcpy(buffer, process_title.str, process_title.len + 1); memcpy(buffer, process_title.str, process_title.len + 1);
buffer[process_title.len] = '\0'; buffer[process_title.len] = '\0';
uv_mutex_unlock(&process_title_mutex);
return 0; return 0;
} }
......
...@@ -28,6 +28,9 @@ ...@@ -28,6 +28,9 @@
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
#ifndef SA_RESTART
# define SA_RESTART 0
#endif
typedef struct { typedef struct {
uv_signal_t* handle; uv_signal_t* handle;
...@@ -216,11 +219,13 @@ static int uv__signal_register_handler(int signum, int oneshot) { ...@@ -216,11 +219,13 @@ static int uv__signal_register_handler(int signum, int oneshot) {
if (sigfillset(&sa.sa_mask)) if (sigfillset(&sa.sa_mask))
abort(); abort();
sa.sa_handler = uv__signal_handler; sa.sa_handler = uv__signal_handler;
sa.sa_flags = oneshot ? SA_RESETHAND : 0; sa.sa_flags = SA_RESTART;
if (oneshot)
sa.sa_flags |= SA_RESETHAND;
/* XXX save old action so we can restore it later on? */ /* XXX save old action so we can restore it later on? */
if (sigaction(signum, &sa, NULL)) if (sigaction(signum, &sa, NULL))
return -errno; return UV__ERR(errno);
return 0; return 0;
} }
...@@ -357,7 +362,7 @@ static int uv__signal_start(uv_signal_t* handle, ...@@ -357,7 +362,7 @@ static int uv__signal_start(uv_signal_t* handle,
* eventually. * eventually.
*/ */
if (signum == 0) if (signum == 0)
return -EINVAL; return UV_EINVAL;
/* Short circuit: if the signal watcher is already watching {signum} don't /* Short circuit: if the signal watcher is already watching {signum} don't
* go through the process of deregistering and registering the handler. * go through the process of deregistering and registering the handler.
......
...@@ -58,6 +58,12 @@ struct uv__stream_select_s { ...@@ -58,6 +58,12 @@ struct uv__stream_select_s {
fd_set* swrite; fd_set* swrite;
size_t swrite_sz; size_t swrite_sz;
}; };
# define WRITE_RETRY_ON_ERROR(send_handle) \
(errno == EAGAIN || errno == EWOULDBLOCK || errno == ENOBUFS || \
(errno == EMSGSIZE && send_handle))
#else
# define WRITE_RETRY_ON_ERROR(send_handle) \
(errno == EAGAIN || errno == EWOULDBLOCK || errno == ENOBUFS)
#endif /* defined(__APPLE__) */ #endif /* defined(__APPLE__) */
static void uv__stream_connect(uv_stream_t*); static void uv__stream_connect(uv_stream_t*);
...@@ -282,7 +288,7 @@ int uv__stream_try_select(uv_stream_t* stream, int* fd) { ...@@ -282,7 +288,7 @@ int uv__stream_try_select(uv_stream_t* stream, int* fd) {
kq = kqueue(); kq = kqueue();
if (kq == -1) { if (kq == -1) {
perror("(libuv) kqueue()"); perror("(libuv) kqueue()");
return -errno; return UV__ERR(errno);
} }
EV_SET(&filter[0], *fd, EVFILT_READ, EV_ADD | EV_ENABLE, 0, 0, 0); EV_SET(&filter[0], *fd, EVFILT_READ, EV_ADD | EV_ENABLE, 0, 0, 0);
...@@ -298,7 +304,7 @@ int uv__stream_try_select(uv_stream_t* stream, int* fd) { ...@@ -298,7 +304,7 @@ int uv__stream_try_select(uv_stream_t* stream, int* fd) {
uv__close(kq); uv__close(kq);
if (ret == -1) if (ret == -1)
return -errno; return UV__ERR(errno);
if (ret == 0 || (events[0].flags & EV_ERROR) == 0 || events[0].data != EINVAL) if (ret == 0 || (events[0].flags & EV_ERROR) == 0 || events[0].data != EINVAL)
return 0; return 0;
...@@ -310,7 +316,7 @@ int uv__stream_try_select(uv_stream_t* stream, int* fd) { ...@@ -310,7 +316,7 @@ int uv__stream_try_select(uv_stream_t* stream, int* fd) {
* NOTE: do it ahead of malloc below to allocate enough space for fd_sets * NOTE: do it ahead of malloc below to allocate enough space for fd_sets
*/ */
if (socketpair(AF_UNIX, SOCK_STREAM, 0, fds)) if (socketpair(AF_UNIX, SOCK_STREAM, 0, fds))
return -errno; return UV__ERR(errno);
max_fd = *fd; max_fd = *fd;
if (fds[1] > max_fd) if (fds[1] > max_fd)
...@@ -321,7 +327,7 @@ int uv__stream_try_select(uv_stream_t* stream, int* fd) { ...@@ -321,7 +327,7 @@ int uv__stream_try_select(uv_stream_t* stream, int* fd) {
s = uv__malloc(sizeof(*s) + sread_sz + swrite_sz); s = uv__malloc(sizeof(*s) + sread_sz + swrite_sz);
if (s == NULL) { if (s == NULL) {
err = -ENOMEM; err = UV_ENOMEM;
goto failed_malloc; goto failed_malloc;
} }
...@@ -395,18 +401,18 @@ int uv__stream_open(uv_stream_t* stream, int fd, int flags) { ...@@ -395,18 +401,18 @@ int uv__stream_open(uv_stream_t* stream, int fd, int flags) {
#endif #endif
if (!(stream->io_watcher.fd == -1 || stream->io_watcher.fd == fd)) if (!(stream->io_watcher.fd == -1 || stream->io_watcher.fd == fd))
return -EBUSY; return UV_EBUSY;
assert(fd >= 0); assert(fd >= 0);
stream->flags |= flags; stream->flags |= flags;
if (stream->type == UV_TCP) { if (stream->type == UV_TCP) {
if ((stream->flags & UV_TCP_NODELAY) && uv__tcp_nodelay(fd, 1)) if ((stream->flags & UV_TCP_NODELAY) && uv__tcp_nodelay(fd, 1))
return -errno; return UV__ERR(errno);
/* TODO Use delay the user passed in. */ /* TODO Use delay the user passed in. */
if ((stream->flags & UV_TCP_KEEPALIVE) && uv__tcp_keepalive(fd, 1, 60)) if ((stream->flags & UV_TCP_KEEPALIVE) && uv__tcp_keepalive(fd, 1, 60))
return -errno; return UV__ERR(errno);
} }
#if defined(__APPLE__) #if defined(__APPLE__)
...@@ -414,7 +420,7 @@ int uv__stream_open(uv_stream_t* stream, int fd, int flags) { ...@@ -414,7 +420,7 @@ int uv__stream_open(uv_stream_t* stream, int fd, int flags) {
if (setsockopt(fd, SOL_SOCKET, SO_OOBINLINE, &enable, sizeof(enable)) && if (setsockopt(fd, SOL_SOCKET, SO_OOBINLINE, &enable, sizeof(enable)) &&
errno != ENOTSOCK && errno != ENOTSOCK &&
errno != EINVAL) { errno != EINVAL) {
return -errno; return UV__ERR(errno);
} }
#endif #endif
...@@ -445,11 +451,11 @@ void uv__stream_destroy(uv_stream_t* stream) { ...@@ -445,11 +451,11 @@ void uv__stream_destroy(uv_stream_t* stream) {
if (stream->connect_req) { if (stream->connect_req) {
uv__req_unregister(stream->loop, stream->connect_req); uv__req_unregister(stream->loop, stream->connect_req);
stream->connect_req->cb(stream->connect_req, -ECANCELED); stream->connect_req->cb(stream->connect_req, UV_ECANCELED);
stream->connect_req = NULL; stream->connect_req = NULL;
} }
uv__stream_flush_write_queue(stream, -ECANCELED); uv__stream_flush_write_queue(stream, UV_ECANCELED);
uv__write_callbacks(stream); uv__write_callbacks(stream);
if (stream->shutdown_req) { if (stream->shutdown_req) {
...@@ -459,7 +465,7 @@ void uv__stream_destroy(uv_stream_t* stream) { ...@@ -459,7 +465,7 @@ void uv__stream_destroy(uv_stream_t* stream) {
* callee that the handle has been destroyed. * callee that the handle has been destroyed.
*/ */
uv__req_unregister(stream->loop, stream->shutdown_req); uv__req_unregister(stream->loop, stream->shutdown_req);
stream->shutdown_req->cb(stream->shutdown_req, -ECANCELED); stream->shutdown_req->cb(stream->shutdown_req, UV_ECANCELED);
stream->shutdown_req = NULL; stream->shutdown_req = NULL;
} }
...@@ -483,7 +489,7 @@ static int uv__emfile_trick(uv_loop_t* loop, int accept_fd) { ...@@ -483,7 +489,7 @@ static int uv__emfile_trick(uv_loop_t* loop, int accept_fd) {
int emfile_fd; int emfile_fd;
if (loop->emfile_fd == -1) if (loop->emfile_fd == -1)
return -EMFILE; return UV_EMFILE;
uv__close(loop->emfile_fd); uv__close(loop->emfile_fd);
loop->emfile_fd = -1; loop->emfile_fd = -1;
...@@ -492,7 +498,7 @@ static int uv__emfile_trick(uv_loop_t* loop, int accept_fd) { ...@@ -492,7 +498,7 @@ static int uv__emfile_trick(uv_loop_t* loop, int accept_fd) {
err = uv__accept(accept_fd); err = uv__accept(accept_fd);
if (err >= 0) if (err >= 0)
uv__close(err); uv__close(err);
} while (err >= 0 || err == -EINTR); } while (err >= 0 || err == UV_EINTR);
emfile_fd = uv__open_cloexec("/", O_RDONLY); emfile_fd = uv__open_cloexec("/", O_RDONLY);
if (emfile_fd >= 0) if (emfile_fd >= 0)
...@@ -533,15 +539,15 @@ void uv__server_io(uv_loop_t* loop, uv__io_t* w, unsigned int events) { ...@@ -533,15 +539,15 @@ void uv__server_io(uv_loop_t* loop, uv__io_t* w, unsigned int events) {
err = uv__accept(uv__stream_fd(stream)); err = uv__accept(uv__stream_fd(stream));
if (err < 0) { if (err < 0) {
if (err == -EAGAIN || err == -EWOULDBLOCK) if (err == UV_EAGAIN || err == UV__ERR(EWOULDBLOCK))
return; /* Not an error. */ return; /* Not an error. */
if (err == -ECONNABORTED) if (err == UV_ECONNABORTED)
continue; /* Ignore. Nothing we can do about that. */ continue; /* Ignore. Nothing we can do about that. */
if (err == -EMFILE || err == -ENFILE) { if (err == UV_EMFILE || err == UV_ENFILE) {
err = uv__emfile_trick(loop, uv__stream_fd(stream)); err = uv__emfile_trick(loop, uv__stream_fd(stream));
if (err == -EAGAIN || err == -EWOULDBLOCK) if (err == UV_EAGAIN || err == UV__ERR(EWOULDBLOCK))
break; break;
} }
...@@ -577,7 +583,7 @@ int uv_accept(uv_stream_t* server, uv_stream_t* client) { ...@@ -577,7 +583,7 @@ int uv_accept(uv_stream_t* server, uv_stream_t* client) {
assert(server->loop == client->loop); assert(server->loop == client->loop);
if (server->accepted_fd == -1) if (server->accepted_fd == -1)
return -EAGAIN; return UV_EAGAIN;
switch (client->type) { switch (client->type) {
case UV_NAMED_PIPE: case UV_NAMED_PIPE:
...@@ -601,7 +607,7 @@ int uv_accept(uv_stream_t* server, uv_stream_t* client) { ...@@ -601,7 +607,7 @@ int uv_accept(uv_stream_t* server, uv_stream_t* client) {
break; break;
default: default:
return -EINVAL; return UV_EINVAL;
} }
client->flags |= UV_HANDLE_BOUND; client->flags |= UV_HANDLE_BOUND;
...@@ -649,7 +655,7 @@ int uv_listen(uv_stream_t* stream, int backlog, uv_connection_cb cb) { ...@@ -649,7 +655,7 @@ int uv_listen(uv_stream_t* stream, int backlog, uv_connection_cb cb) {
break; break;
default: default:
err = -EINVAL; err = UV_EINVAL;
} }
if (err == 0) if (err == 0)
...@@ -680,7 +686,7 @@ static void uv__drain(uv_stream_t* stream) { ...@@ -680,7 +686,7 @@ static void uv__drain(uv_stream_t* stream) {
err = 0; err = 0;
if (shutdown(uv__stream_fd(stream), SHUT_WR)) if (shutdown(uv__stream_fd(stream), SHUT_WR))
err = -errno; err = UV__ERR(errno);
if (err == 0) if (err == 0)
stream->flags |= UV_STREAM_SHUT; stream->flags |= UV_STREAM_SHUT;
...@@ -792,7 +798,7 @@ start: ...@@ -792,7 +798,7 @@ start:
} scratch; } scratch;
if (uv__is_closing(req->send_handle)) { if (uv__is_closing(req->send_handle)) {
err = -EBADF; err = UV_EBADF;
goto error; goto error;
} }
...@@ -859,8 +865,8 @@ start: ...@@ -859,8 +865,8 @@ start:
} }
if (n < 0) { if (n < 0) {
if (errno != EAGAIN && errno != EWOULDBLOCK && errno != ENOBUFS) { if (!WRITE_RETRY_ON_ERROR(req->send_handle)) {
err = -errno; err = UV__ERR(errno);
goto error; goto error;
} else if (stream->flags & UV_STREAM_BLOCKING) { } else if (stream->flags & UV_STREAM_BLOCKING) {
/* If this is a blocking stream, try again. */ /* If this is a blocking stream, try again. */
...@@ -1029,7 +1035,7 @@ static int uv__stream_queue_fd(uv_stream_t* stream, int fd) { ...@@ -1029,7 +1035,7 @@ static int uv__stream_queue_fd(uv_stream_t* stream, int fd) {
queued_fds = uv__malloc((queue_size - 1) * sizeof(*queued_fds->fds) + queued_fds = uv__malloc((queue_size - 1) * sizeof(*queued_fds->fds) +
sizeof(*queued_fds)); sizeof(*queued_fds));
if (queued_fds == NULL) if (queued_fds == NULL)
return -ENOMEM; return UV_ENOMEM;
queued_fds->size = queue_size; queued_fds->size = queue_size;
queued_fds->offset = 0; queued_fds->offset = 0;
stream->queued_fds = queued_fds; stream->queued_fds = queued_fds;
...@@ -1046,7 +1052,7 @@ static int uv__stream_queue_fd(uv_stream_t* stream, int fd) { ...@@ -1046,7 +1052,7 @@ static int uv__stream_queue_fd(uv_stream_t* stream, int fd) {
* NOTE: if it is fatal - sockets will be closed in uv__stream_close * NOTE: if it is fatal - sockets will be closed in uv__stream_close
*/ */
if (queued_fds == NULL) if (queued_fds == NULL)
return -ENOMEM; return UV_ENOMEM;
queued_fds->size = queue_size; queued_fds->size = queue_size;
stream->queued_fds = queued_fds; stream->queued_fds = queued_fds;
} }
...@@ -1192,7 +1198,7 @@ static void uv__read(uv_stream_t* stream) { ...@@ -1192,7 +1198,7 @@ static void uv__read(uv_stream_t* stream) {
#endif #endif
} else { } else {
/* Error. User should call uv_close(). */ /* Error. User should call uv_close(). */
stream->read_cb(stream, -errno, &buf); stream->read_cb(stream, UV__ERR(errno), &buf);
if (stream->flags & UV_STREAM_READING) { if (stream->flags & UV_STREAM_READING) {
stream->flags &= ~UV_STREAM_READING; stream->flags &= ~UV_STREAM_READING;
uv__io_stop(stream->loop, &stream->io_watcher, POLLIN); uv__io_stop(stream->loop, &stream->io_watcher, POLLIN);
...@@ -1269,7 +1275,7 @@ int uv_shutdown(uv_shutdown_t* req, uv_stream_t* stream, uv_shutdown_cb cb) { ...@@ -1269,7 +1275,7 @@ int uv_shutdown(uv_shutdown_t* req, uv_stream_t* stream, uv_shutdown_cb cb) {
stream->flags & UV_STREAM_SHUT || stream->flags & UV_STREAM_SHUT ||
stream->flags & UV_STREAM_SHUTTING || stream->flags & UV_STREAM_SHUTTING ||
uv__is_closing(stream)) { uv__is_closing(stream)) {
return -ENOTCONN; return UV_ENOTCONN;
} }
assert(uv__stream_fd(stream) >= 0); assert(uv__stream_fd(stream) >= 0);
...@@ -1368,10 +1374,10 @@ static void uv__stream_connect(uv_stream_t* stream) { ...@@ -1368,10 +1374,10 @@ static void uv__stream_connect(uv_stream_t* stream) {
SO_ERROR, SO_ERROR,
&error, &error,
&errorsize); &errorsize);
error = -error; error = UV__ERR(error);
} }
if (error == -EINPROGRESS) if (error == UV__ERR(EINPROGRESS))
return; return;
stream->connect_req = NULL; stream->connect_req = NULL;
...@@ -1388,7 +1394,7 @@ static void uv__stream_connect(uv_stream_t* stream) { ...@@ -1388,7 +1394,7 @@ static void uv__stream_connect(uv_stream_t* stream) {
return; return;
if (error < 0) { if (error < 0) {
uv__stream_flush_write_queue(stream, -ECANCELED); uv__stream_flush_write_queue(stream, UV_ECANCELED);
uv__write_callbacks(stream); uv__write_callbacks(stream);
} }
} }
...@@ -1409,11 +1415,11 @@ int uv_write2(uv_write_t* req, ...@@ -1409,11 +1415,11 @@ int uv_write2(uv_write_t* req,
"uv_write (unix) does not yet support other types of streams"); "uv_write (unix) does not yet support other types of streams");
if (uv__stream_fd(stream) < 0) if (uv__stream_fd(stream) < 0)
return -EBADF; return UV_EBADF;
if (send_handle) { if (send_handle) {
if (stream->type != UV_NAMED_PIPE || !((uv_pipe_t*)stream)->ipc) if (stream->type != UV_NAMED_PIPE || !((uv_pipe_t*)stream)->ipc)
return -EINVAL; return UV_EINVAL;
/* XXX We abuse uv_write2() to send over UDP handles to child processes. /* XXX We abuse uv_write2() to send over UDP handles to child processes.
* Don't call uv__stream_fd() on those handles, it's a macro that on OS X * Don't call uv__stream_fd() on those handles, it's a macro that on OS X
...@@ -1422,12 +1428,12 @@ int uv_write2(uv_write_t* req, ...@@ -1422,12 +1428,12 @@ int uv_write2(uv_write_t* req,
* which works but only by accident. * which works but only by accident.
*/ */
if (uv__handle_fd((uv_handle_t*) send_handle) < 0) if (uv__handle_fd((uv_handle_t*) send_handle) < 0)
return -EBADF; return UV_EBADF;
#if defined(__CYGWIN__) || defined(__MSYS__) #if defined(__CYGWIN__) || defined(__MSYS__)
/* Cygwin recvmsg always sets msg_controllen to zero, so we cannot send it. /* Cygwin recvmsg always sets msg_controllen to zero, so we cannot send it.
See https://github.com/mirror/newlib-cygwin/blob/86fc4bf0/winsup/cygwin/fhandler_socket.cc#L1736-L1743 */ See https://github.com/mirror/newlib-cygwin/blob/86fc4bf0/winsup/cygwin/fhandler_socket.cc#L1736-L1743 */
return -ENOSYS; return UV_ENOSYS;
#endif #endif
} }
...@@ -1452,7 +1458,7 @@ int uv_write2(uv_write_t* req, ...@@ -1452,7 +1458,7 @@ int uv_write2(uv_write_t* req,
req->bufs = uv__malloc(nbufs * sizeof(bufs[0])); req->bufs = uv__malloc(nbufs * sizeof(bufs[0]));
if (req->bufs == NULL) if (req->bufs == NULL)
return -ENOMEM; return UV_ENOMEM;
memcpy(req->bufs, bufs, nbufs * sizeof(bufs[0])); memcpy(req->bufs, bufs, nbufs * sizeof(bufs[0]));
req->nbufs = nbufs; req->nbufs = nbufs;
...@@ -1516,7 +1522,7 @@ int uv_try_write(uv_stream_t* stream, ...@@ -1516,7 +1522,7 @@ int uv_try_write(uv_stream_t* stream,
/* Connecting or already writing some data */ /* Connecting or already writing some data */
if (stream->connect_req != NULL || stream->write_queue_size != 0) if (stream->connect_req != NULL || stream->write_queue_size != 0)
return -EAGAIN; return UV_EAGAIN;
has_pollout = uv__io_active(&stream->io_watcher, POLLOUT); has_pollout = uv__io_active(&stream->io_watcher, POLLOUT);
...@@ -1547,7 +1553,7 @@ int uv_try_write(uv_stream_t* stream, ...@@ -1547,7 +1553,7 @@ int uv_try_write(uv_stream_t* stream,
} }
if (written == 0 && req_size != 0) if (written == 0 && req_size != 0)
return -EAGAIN; return UV_EAGAIN;
else else
return written; return written;
} }
...@@ -1560,7 +1566,7 @@ int uv_read_start(uv_stream_t* stream, ...@@ -1560,7 +1566,7 @@ int uv_read_start(uv_stream_t* stream,
stream->type == UV_TTY); stream->type == UV_TTY);
if (stream->flags & UV_CLOSING) if (stream->flags & UV_CLOSING)
return -EINVAL; return UV_EINVAL;
/* The UV_STREAM_READING flag is irrelevant of the state of the tcp - it just /* The UV_STREAM_READING flag is irrelevant of the state of the tcp - it just
* expresses the desired state of the user. * expresses the desired state of the user.
......
...@@ -73,7 +73,7 @@ int uv__platform_loop_init(uv_loop_t* loop) { ...@@ -73,7 +73,7 @@ int uv__platform_loop_init(uv_loop_t* loop) {
fd = port_create(); fd = port_create();
if (fd == -1) if (fd == -1)
return -errno; return UV__ERR(errno);
err = uv__cloexec(fd, 1); err = uv__cloexec(fd, 1);
if (err) { if (err) {
...@@ -132,7 +132,7 @@ void uv__platform_invalidate_fd(uv_loop_t* loop, int fd) { ...@@ -132,7 +132,7 @@ void uv__platform_invalidate_fd(uv_loop_t* loop, int fd) {
int uv__io_check_fd(uv_loop_t* loop, int fd) { int uv__io_check_fd(uv_loop_t* loop, int fd) {
if (port_associate(loop->backend_fd, PORT_SOURCE_FD, fd, POLLIN, 0)) if (port_associate(loop->backend_fd, PORT_SOURCE_FD, fd, POLLIN, 0))
return -errno; return UV__ERR(errno);
if (port_dissociate(loop->backend_fd, PORT_SOURCE_FD, fd)) if (port_dissociate(loop->backend_fd, PORT_SOURCE_FD, fd))
abort(); abort();
...@@ -342,7 +342,7 @@ int uv_exepath(char* buffer, size_t* size) { ...@@ -342,7 +342,7 @@ int uv_exepath(char* buffer, size_t* size) {
char buf[128]; char buf[128];
if (buffer == NULL || size == NULL || *size == 0) if (buffer == NULL || size == NULL || *size == 0)
return -EINVAL; return UV_EINVAL;
snprintf(buf, sizeof(buf), "/proc/%lu/path/a.out", (unsigned long) getpid()); snprintf(buf, sizeof(buf), "/proc/%lu/path/a.out", (unsigned long) getpid());
...@@ -351,7 +351,7 @@ int uv_exepath(char* buffer, size_t* size) { ...@@ -351,7 +351,7 @@ int uv_exepath(char* buffer, size_t* size) {
res = readlink(buf, buffer, res); res = readlink(buf, buffer, res);
if (res == -1) if (res == -1)
return -errno; return UV__ERR(errno);
buffer[res] = '\0'; buffer[res] = '\0';
*size = res; *size = res;
...@@ -378,14 +378,14 @@ void uv_loadavg(double avg[3]) { ...@@ -378,14 +378,14 @@ void uv_loadavg(double avg[3]) {
static int uv__fs_event_rearm(uv_fs_event_t *handle) { static int uv__fs_event_rearm(uv_fs_event_t *handle) {
if (handle->fd == -1) if (handle->fd == -1)
return -EBADF; return UV_EBADF;
if (port_associate(handle->loop->fs_fd, if (port_associate(handle->loop->fs_fd,
PORT_SOURCE_FILE, PORT_SOURCE_FILE,
(uintptr_t) &handle->fo, (uintptr_t) &handle->fo,
FILE_ATTRIB | FILE_MODIFIED, FILE_ATTRIB | FILE_MODIFIED,
handle) == -1) { handle) == -1) {
return -errno; return UV__ERR(errno);
} }
handle->fd = PORT_LOADED; handle->fd = PORT_LOADED;
...@@ -462,13 +462,13 @@ int uv_fs_event_start(uv_fs_event_t* handle, ...@@ -462,13 +462,13 @@ int uv_fs_event_start(uv_fs_event_t* handle,
int err; int err;
if (uv__is_active(handle)) if (uv__is_active(handle))
return -EINVAL; return UV_EINVAL;
first_run = 0; first_run = 0;
if (handle->loop->fs_fd == -1) { if (handle->loop->fs_fd == -1) {
portfd = port_create(); portfd = port_create();
if (portfd == -1) if (portfd == -1)
return -errno; return UV__ERR(errno);
handle->loop->fs_fd = portfd; handle->loop->fs_fd = portfd;
first_run = 1; first_run = 1;
} }
...@@ -521,7 +521,7 @@ void uv__fs_event_close(uv_fs_event_t* handle) { ...@@ -521,7 +521,7 @@ void uv__fs_event_close(uv_fs_event_t* handle) {
#else /* !defined(PORT_SOURCE_FILE) */ #else /* !defined(PORT_SOURCE_FILE) */
int uv_fs_event_init(uv_loop_t* loop, uv_fs_event_t* handle) { int uv_fs_event_init(uv_loop_t* loop, uv_fs_event_t* handle) {
return -ENOSYS; return UV_ENOSYS;
} }
...@@ -529,12 +529,12 @@ int uv_fs_event_start(uv_fs_event_t* handle, ...@@ -529,12 +529,12 @@ int uv_fs_event_start(uv_fs_event_t* handle,
uv_fs_event_cb cb, uv_fs_event_cb cb,
const char* filename, const char* filename,
unsigned int flags) { unsigned int flags) {
return -ENOSYS; return UV_ENOSYS;
} }
int uv_fs_event_stop(uv_fs_event_t* handle) { int uv_fs_event_stop(uv_fs_event_t* handle) {
return -ENOSYS; return UV_ENOSYS;
} }
...@@ -552,10 +552,10 @@ int uv_resident_set_memory(size_t* rss) { ...@@ -552,10 +552,10 @@ int uv_resident_set_memory(size_t* rss) {
fd = open("/proc/self/psinfo", O_RDONLY); fd = open("/proc/self/psinfo", O_RDONLY);
if (fd == -1) if (fd == -1)
return -errno; return UV__ERR(errno);
/* FIXME(bnoordhuis) Handle EINTR. */ /* FIXME(bnoordhuis) Handle EINTR. */
err = -EINVAL; err = UV_EINVAL;
if (read(fd, &psinfo, sizeof(psinfo)) == sizeof(psinfo)) { if (read(fd, &psinfo, sizeof(psinfo)) == sizeof(psinfo)) {
*rss = (size_t)psinfo.pr_rssize * 1024; *rss = (size_t)psinfo.pr_rssize * 1024;
err = 0; err = 0;
...@@ -575,7 +575,7 @@ int uv_uptime(double* uptime) { ...@@ -575,7 +575,7 @@ int uv_uptime(double* uptime) {
kc = kstat_open(); kc = kstat_open();
if (kc == NULL) if (kc == NULL)
return -EPERM; return UV_EPERM;
ksp = kstat_lookup(kc, (char*) "unix", 0, (char*) "system_misc"); ksp = kstat_lookup(kc, (char*) "unix", 0, (char*) "system_misc");
if (kstat_read(kc, ksp, NULL) == -1) { if (kstat_read(kc, ksp, NULL) == -1) {
...@@ -599,7 +599,7 @@ int uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) { ...@@ -599,7 +599,7 @@ int uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) {
kc = kstat_open(); kc = kstat_open();
if (kc == NULL) if (kc == NULL)
return -EPERM; return UV_EPERM;
/* Get count of cpus */ /* Get count of cpus */
lookup_instance = 0; lookup_instance = 0;
...@@ -610,7 +610,7 @@ int uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) { ...@@ -610,7 +610,7 @@ int uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) {
*cpu_infos = uv__malloc(lookup_instance * sizeof(**cpu_infos)); *cpu_infos = uv__malloc(lookup_instance * sizeof(**cpu_infos));
if (!(*cpu_infos)) { if (!(*cpu_infos)) {
kstat_close(kc); kstat_close(kc);
return -ENOMEM; return UV_ENOMEM;
} }
*count = lookup_instance; *count = lookup_instance;
...@@ -692,7 +692,7 @@ void uv_free_cpu_info(uv_cpu_info_t* cpu_infos, int count) { ...@@ -692,7 +692,7 @@ 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) {
return -ENOSYS; return UV_ENOSYS;
} }
#else /* SUNOS_NO_IFADDRS */ #else /* SUNOS_NO_IFADDRS */
/* /*
...@@ -730,11 +730,11 @@ static int uv__set_phys_addr(uv_interface_address_t* address, ...@@ -730,11 +730,11 @@ static int uv__set_phys_addr(uv_interface_address_t* address,
sockfd = socket(AF_INET, SOCK_DGRAM, 0); sockfd = socket(AF_INET, SOCK_DGRAM, 0);
if (sockfd < 0) if (sockfd < 0)
return -errno; return UV__ERR(errno);
if (ioctl(sockfd, SIOCGARP, (char*)&arpreq) == -1) { if (ioctl(sockfd, SIOCGARP, (char*)&arpreq) == -1) {
uv__close(sockfd); uv__close(sockfd);
return -errno; return UV__ERR(errno);
} }
memcpy(address->phys_addr, arpreq.arp_ha.sa_data, sizeof(address->phys_addr)); memcpy(address->phys_addr, arpreq.arp_ha.sa_data, sizeof(address->phys_addr));
uv__close(sockfd); uv__close(sockfd);
...@@ -759,7 +759,7 @@ int uv_interface_addresses(uv_interface_address_t** addresses, int* count) { ...@@ -759,7 +759,7 @@ int uv_interface_addresses(uv_interface_address_t** addresses, int* count) {
struct ifaddrs* ent; struct ifaddrs* ent;
if (getifaddrs(&addrs)) if (getifaddrs(&addrs))
return -errno; return UV__ERR(errno);
*count = 0; *count = 0;
...@@ -773,7 +773,7 @@ int uv_interface_addresses(uv_interface_address_t** addresses, int* count) { ...@@ -773,7 +773,7 @@ int uv_interface_addresses(uv_interface_address_t** addresses, int* count) {
*addresses = uv__malloc(*count * sizeof(**addresses)); *addresses = uv__malloc(*count * sizeof(**addresses));
if (!(*addresses)) { if (!(*addresses)) {
freeifaddrs(addrs); freeifaddrs(addrs);
return -ENOMEM; return UV_ENOMEM;
} }
address = *addresses; address = *addresses;
......
...@@ -89,7 +89,7 @@ static int maybe_new_socket(uv_tcp_t* handle, int domain, unsigned long flags) { ...@@ -89,7 +89,7 @@ static int maybe_new_socket(uv_tcp_t* handle, int domain, unsigned long flags) {
slen = sizeof(saddr); slen = sizeof(saddr);
memset(&saddr, 0, sizeof(saddr)); memset(&saddr, 0, sizeof(saddr));
if (getsockname(uv__stream_fd(handle), (struct sockaddr*) &saddr, &slen)) if (getsockname(uv__stream_fd(handle), (struct sockaddr*) &saddr, &slen))
return -errno; return UV__ERR(errno);
if ((saddr.ss_family == AF_INET6 && if ((saddr.ss_family == AF_INET6 &&
((struct sockaddr_in6*) &saddr)->sin6_port != 0) || ((struct sockaddr_in6*) &saddr)->sin6_port != 0) ||
...@@ -102,7 +102,7 @@ static int maybe_new_socket(uv_tcp_t* handle, int domain, unsigned long flags) { ...@@ -102,7 +102,7 @@ static int maybe_new_socket(uv_tcp_t* handle, int domain, unsigned long flags) {
/* Bind to arbitrary port */ /* Bind to arbitrary port */
if (bind(uv__stream_fd(handle), (struct sockaddr*) &saddr, slen)) if (bind(uv__stream_fd(handle), (struct sockaddr*) &saddr, slen))
return -errno; return UV__ERR(errno);
} }
handle->flags |= flags; handle->flags |= flags;
...@@ -119,10 +119,10 @@ int uv_tcp_init_ex(uv_loop_t* loop, uv_tcp_t* tcp, unsigned int flags) { ...@@ -119,10 +119,10 @@ int uv_tcp_init_ex(uv_loop_t* loop, uv_tcp_t* tcp, unsigned int flags) {
/* Use the lower 8 bits for the domain */ /* Use the lower 8 bits for the domain */
domain = flags & 0xFF; domain = flags & 0xFF;
if (domain != AF_INET && domain != AF_INET6 && domain != AF_UNSPEC) if (domain != AF_INET && domain != AF_INET6 && domain != AF_UNSPEC)
return -EINVAL; return UV_EINVAL;
if (flags & ~0xFF) if (flags & ~0xFF)
return -EINVAL; return UV_EINVAL;
uv__stream_init(loop, (uv_stream_t*)tcp, UV_TCP); uv__stream_init(loop, (uv_stream_t*)tcp, UV_TCP);
...@@ -156,7 +156,7 @@ int uv__tcp_bind(uv_tcp_t* tcp, ...@@ -156,7 +156,7 @@ int uv__tcp_bind(uv_tcp_t* tcp,
/* Cannot set IPv6-only mode on non-IPv6 socket. */ /* Cannot set IPv6-only mode on non-IPv6 socket. */
if ((flags & UV_TCP_IPV6ONLY) && addr->sa_family != AF_INET6) if ((flags & UV_TCP_IPV6ONLY) && addr->sa_family != AF_INET6)
return -EINVAL; return UV_EINVAL;
err = maybe_new_socket(tcp, err = maybe_new_socket(tcp,
addr->sa_family, addr->sa_family,
...@@ -166,7 +166,7 @@ int uv__tcp_bind(uv_tcp_t* tcp, ...@@ -166,7 +166,7 @@ int uv__tcp_bind(uv_tcp_t* tcp,
on = 1; on = 1;
if (setsockopt(tcp->io_watcher.fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on))) if (setsockopt(tcp->io_watcher.fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)))
return -errno; return UV__ERR(errno);
#ifdef IPV6_V6ONLY #ifdef IPV6_V6ONLY
if (addr->sa_family == AF_INET6) { if (addr->sa_family == AF_INET6) {
...@@ -178,9 +178,9 @@ int uv__tcp_bind(uv_tcp_t* tcp, ...@@ -178,9 +178,9 @@ int uv__tcp_bind(uv_tcp_t* tcp,
sizeof on) == -1) { sizeof on) == -1) {
#if defined(__MVS__) #if defined(__MVS__)
if (errno == EOPNOTSUPP) if (errno == EOPNOTSUPP)
return -EINVAL; return UV_EINVAL;
#endif #endif
return -errno; return UV__ERR(errno);
} }
} }
#endif #endif
...@@ -190,10 +190,10 @@ int uv__tcp_bind(uv_tcp_t* tcp, ...@@ -190,10 +190,10 @@ int uv__tcp_bind(uv_tcp_t* tcp,
if (errno == EAFNOSUPPORT) if (errno == EAFNOSUPPORT)
/* OSX, other BSDs and SunoS fail with EAFNOSUPPORT when binding a /* OSX, other BSDs and SunoS fail with EAFNOSUPPORT when binding a
* socket created with AF_INET to an AF_INET6 address or vice versa. */ * socket created with AF_INET to an AF_INET6 address or vice versa. */
return -EINVAL; return UV_EINVAL;
return -errno; return UV__ERR(errno);
} }
tcp->delayed_error = -errno; tcp->delayed_error = UV__ERR(errno);
tcp->flags |= UV_HANDLE_BOUND; tcp->flags |= UV_HANDLE_BOUND;
if (addr->sa_family == AF_INET6) if (addr->sa_family == AF_INET6)
...@@ -214,7 +214,7 @@ int uv__tcp_connect(uv_connect_t* req, ...@@ -214,7 +214,7 @@ int uv__tcp_connect(uv_connect_t* req,
assert(handle->type == UV_TCP); assert(handle->type == UV_TCP);
if (handle->connect_req != NULL) if (handle->connect_req != NULL)
return -EALREADY; /* FIXME(bnoordhuis) -EINVAL or maybe -EBUSY. */ return UV_EALREADY; /* FIXME(bnoordhuis) UV_EINVAL or maybe UV_EBUSY. */
err = maybe_new_socket(handle, err = maybe_new_socket(handle,
addr->sa_family, addr->sa_family,
...@@ -242,9 +242,9 @@ int uv__tcp_connect(uv_connect_t* req, ...@@ -242,9 +242,9 @@ int uv__tcp_connect(uv_connect_t* req,
* error. Solaris wants to report immediately--other unixes want to * error. Solaris wants to report immediately--other unixes want to
* wait. * wait.
*/ */
handle->delayed_error = -errno; handle->delayed_error = UV__ERR(errno);
else else
return -errno; return UV__ERR(errno);
} }
uv__req_init(handle->loop, req, UV_CONNECT); uv__req_init(handle->loop, req, UV_CONNECT);
...@@ -284,13 +284,13 @@ int uv_tcp_getsockname(const uv_tcp_t* handle, ...@@ -284,13 +284,13 @@ int uv_tcp_getsockname(const uv_tcp_t* handle,
return handle->delayed_error; return handle->delayed_error;
if (uv__stream_fd(handle) < 0) if (uv__stream_fd(handle) < 0)
return -EINVAL; /* FIXME(bnoordhuis) -EBADF */ return UV_EINVAL; /* FIXME(bnoordhuis) UV_EBADF */
/* sizeof(socklen_t) != sizeof(int) on some systems. */ /* sizeof(socklen_t) != sizeof(int) on some systems. */
socklen = (socklen_t) *namelen; socklen = (socklen_t) *namelen;
if (getsockname(uv__stream_fd(handle), name, &socklen)) if (getsockname(uv__stream_fd(handle), name, &socklen))
return -errno; return UV__ERR(errno);
*namelen = (int) socklen; *namelen = (int) socklen;
return 0; return 0;
...@@ -306,13 +306,13 @@ int uv_tcp_getpeername(const uv_tcp_t* handle, ...@@ -306,13 +306,13 @@ int uv_tcp_getpeername(const uv_tcp_t* handle,
return handle->delayed_error; return handle->delayed_error;
if (uv__stream_fd(handle) < 0) if (uv__stream_fd(handle) < 0)
return -EINVAL; /* FIXME(bnoordhuis) -EBADF */ return UV_EINVAL; /* FIXME(bnoordhuis) UV_EBADF */
/* sizeof(socklen_t) != sizeof(int) on some systems. */ /* sizeof(socklen_t) != sizeof(int) on some systems. */
socklen = (socklen_t) *namelen; socklen = (socklen_t) *namelen;
if (getpeername(uv__stream_fd(handle), name, &socklen)) if (getpeername(uv__stream_fd(handle), name, &socklen))
return -errno; return UV__ERR(errno);
*namelen = (int) socklen; *namelen = (int) socklen;
return 0; return 0;
...@@ -348,7 +348,7 @@ int uv_tcp_listen(uv_tcp_t* tcp, int backlog, uv_connection_cb cb) { ...@@ -348,7 +348,7 @@ int uv_tcp_listen(uv_tcp_t* tcp, int backlog, uv_connection_cb cb) {
return err; return err;
if (listen(tcp->io_watcher.fd, backlog)) if (listen(tcp->io_watcher.fd, backlog))
return -errno; return UV__ERR(errno);
tcp->connection_cb = cb; tcp->connection_cb = cb;
tcp->flags |= UV_HANDLE_BOUND; tcp->flags |= UV_HANDLE_BOUND;
...@@ -363,18 +363,18 @@ int uv_tcp_listen(uv_tcp_t* tcp, int backlog, uv_connection_cb cb) { ...@@ -363,18 +363,18 @@ int uv_tcp_listen(uv_tcp_t* tcp, int backlog, uv_connection_cb cb) {
int uv__tcp_nodelay(int fd, int on) { int uv__tcp_nodelay(int fd, int on) {
if (setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &on, sizeof(on))) if (setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &on, sizeof(on)))
return -errno; return UV__ERR(errno);
return 0; return 0;
} }
int uv__tcp_keepalive(int fd, int on, unsigned int delay) { int uv__tcp_keepalive(int fd, int on, unsigned int delay) {
if (setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &on, sizeof(on))) if (setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &on, sizeof(on)))
return -errno; return UV__ERR(errno);
#ifdef TCP_KEEPIDLE #ifdef TCP_KEEPIDLE
if (on && setsockopt(fd, IPPROTO_TCP, TCP_KEEPIDLE, &delay, sizeof(delay))) if (on && setsockopt(fd, IPPROTO_TCP, TCP_KEEPIDLE, &delay, sizeof(delay)))
return -errno; return UV__ERR(errno);
#endif #endif
/* Solaris/SmartOS, if you don't support keep-alive, /* Solaris/SmartOS, if you don't support keep-alive,
...@@ -383,7 +383,7 @@ int uv__tcp_keepalive(int fd, int on, unsigned int delay) { ...@@ -383,7 +383,7 @@ int uv__tcp_keepalive(int fd, int on, unsigned int delay) {
/* FIXME(bnoordhuis) That's possibly because sizeof(delay) should be 1. */ /* FIXME(bnoordhuis) That's possibly because sizeof(delay) should be 1. */
#if defined(TCP_KEEPALIVE) && !defined(__sun) #if defined(TCP_KEEPALIVE) && !defined(__sun)
if (on && setsockopt(fd, IPPROTO_TCP, TCP_KEEPALIVE, &delay, sizeof(delay))) if (on && setsockopt(fd, IPPROTO_TCP, TCP_KEEPALIVE, &delay, sizeof(delay)))
return -errno; return UV__ERR(errno);
#endif #endif
return 0; return 0;
......
...@@ -200,7 +200,7 @@ int uv_thread_create(uv_thread_t *tid, void (*entry)(void *arg), void *arg) { ...@@ -200,7 +200,7 @@ int uv_thread_create(uv_thread_t *tid, void (*entry)(void *arg), void *arg) {
if (attr != NULL) if (attr != NULL)
pthread_attr_destroy(attr); pthread_attr_destroy(attr);
return -err; return UV__ERR(err);
} }
...@@ -209,7 +209,7 @@ uv_thread_t uv_thread_self(void) { ...@@ -209,7 +209,7 @@ uv_thread_t uv_thread_self(void) {
} }
int uv_thread_join(uv_thread_t *tid) { int uv_thread_join(uv_thread_t *tid) {
return -pthread_join(*tid, NULL); return UV__ERR(pthread_join(*tid, NULL));
} }
...@@ -220,7 +220,7 @@ int uv_thread_equal(const uv_thread_t* t1, const uv_thread_t* t2) { ...@@ -220,7 +220,7 @@ int uv_thread_equal(const uv_thread_t* t1, const uv_thread_t* t2) {
int uv_mutex_init(uv_mutex_t* mutex) { int uv_mutex_init(uv_mutex_t* mutex) {
#if defined(NDEBUG) || !defined(PTHREAD_MUTEX_ERRORCHECK) #if defined(NDEBUG) || !defined(PTHREAD_MUTEX_ERRORCHECK)
return -pthread_mutex_init(mutex, NULL); return UV__ERR(pthread_mutex_init(mutex, NULL));
#else #else
pthread_mutexattr_t attr; pthread_mutexattr_t attr;
int err; int err;
...@@ -236,7 +236,7 @@ int uv_mutex_init(uv_mutex_t* mutex) { ...@@ -236,7 +236,7 @@ int uv_mutex_init(uv_mutex_t* mutex) {
if (pthread_mutexattr_destroy(&attr)) if (pthread_mutexattr_destroy(&attr))
abort(); abort();
return -err; return UV__ERR(err);
#endif #endif
} }
...@@ -256,7 +256,7 @@ int uv_mutex_init_recursive(uv_mutex_t* mutex) { ...@@ -256,7 +256,7 @@ int uv_mutex_init_recursive(uv_mutex_t* mutex) {
if (pthread_mutexattr_destroy(&attr)) if (pthread_mutexattr_destroy(&attr))
abort(); abort();
return -err; return UV__ERR(err);
} }
...@@ -279,7 +279,7 @@ int uv_mutex_trylock(uv_mutex_t* mutex) { ...@@ -279,7 +279,7 @@ int uv_mutex_trylock(uv_mutex_t* mutex) {
if (err) { if (err) {
if (err != EBUSY && err != EAGAIN) if (err != EBUSY && err != EAGAIN)
abort(); abort();
return -EBUSY; return UV_EBUSY;
} }
return 0; return 0;
...@@ -293,7 +293,7 @@ void uv_mutex_unlock(uv_mutex_t* mutex) { ...@@ -293,7 +293,7 @@ void uv_mutex_unlock(uv_mutex_t* mutex) {
int uv_rwlock_init(uv_rwlock_t* rwlock) { int uv_rwlock_init(uv_rwlock_t* rwlock) {
return -pthread_rwlock_init(rwlock, NULL); return UV__ERR(pthread_rwlock_init(rwlock, NULL));
} }
...@@ -316,7 +316,7 @@ int uv_rwlock_tryrdlock(uv_rwlock_t* rwlock) { ...@@ -316,7 +316,7 @@ int uv_rwlock_tryrdlock(uv_rwlock_t* rwlock) {
if (err) { if (err) {
if (err != EBUSY && err != EAGAIN) if (err != EBUSY && err != EAGAIN)
abort(); abort();
return -EBUSY; return UV_EBUSY;
} }
return 0; return 0;
...@@ -342,7 +342,7 @@ int uv_rwlock_trywrlock(uv_rwlock_t* rwlock) { ...@@ -342,7 +342,7 @@ int uv_rwlock_trywrlock(uv_rwlock_t* rwlock) {
if (err) { if (err) {
if (err != EBUSY && err != EAGAIN) if (err != EBUSY && err != EAGAIN)
abort(); abort();
return -EBUSY; return UV_EBUSY;
} }
return 0; return 0;
...@@ -369,12 +369,12 @@ int uv_sem_init(uv_sem_t* sem, unsigned int value) { ...@@ -369,12 +369,12 @@ int uv_sem_init(uv_sem_t* sem, unsigned int value) {
if (err == KERN_SUCCESS) if (err == KERN_SUCCESS)
return 0; return 0;
if (err == KERN_INVALID_ARGUMENT) if (err == KERN_INVALID_ARGUMENT)
return -EINVAL; return UV_EINVAL;
if (err == KERN_RESOURCE_SHORTAGE) if (err == KERN_RESOURCE_SHORTAGE)
return -ENOMEM; return UV_ENOMEM;
abort(); abort();
return -EINVAL; /* Satisfy the compiler. */ return UV_EINVAL; /* Satisfy the compiler. */
} }
...@@ -413,10 +413,10 @@ int uv_sem_trywait(uv_sem_t* sem) { ...@@ -413,10 +413,10 @@ int uv_sem_trywait(uv_sem_t* sem) {
if (err == KERN_SUCCESS) if (err == KERN_SUCCESS)
return 0; return 0;
if (err == KERN_OPERATION_TIMED_OUT) if (err == KERN_OPERATION_TIMED_OUT)
return -EAGAIN; return UV_EAGAIN;
abort(); abort();
return -EINVAL; /* Satisfy the compiler. */ return UV_EINVAL; /* Satisfy the compiler. */
} }
#elif defined(__MVS__) #elif defined(__MVS__)
...@@ -433,14 +433,14 @@ int uv_sem_init(uv_sem_t* sem, unsigned int value) { ...@@ -433,14 +433,14 @@ int uv_sem_init(uv_sem_t* sem, unsigned int value) {
semid = semget(IPC_PRIVATE, 1, S_IRUSR | S_IWUSR); semid = semget(IPC_PRIVATE, 1, S_IRUSR | S_IWUSR);
if (semid == -1) if (semid == -1)
return -errno; return UV__ERR(errno);
arg.val = value; arg.val = value;
if (-1 == semctl(semid, 0, SETVAL, arg)) { if (-1 == semctl(semid, 0, SETVAL, arg)) {
err = errno; err = errno;
if (-1 == semctl(*sem, 0, IPC_RMID)) if (-1 == semctl(*sem, 0, IPC_RMID))
abort(); abort();
return -err; return UV__ERR(err);
} }
*sem = semid; *sem = semid;
...@@ -493,7 +493,7 @@ int uv_sem_trywait(uv_sem_t* sem) { ...@@ -493,7 +493,7 @@ int uv_sem_trywait(uv_sem_t* sem) {
if (op_status) { if (op_status) {
if (errno == EAGAIN) if (errno == EAGAIN)
return -EAGAIN; return UV_EAGAIN;
abort(); abort();
} }
...@@ -504,7 +504,7 @@ int uv_sem_trywait(uv_sem_t* sem) { ...@@ -504,7 +504,7 @@ int uv_sem_trywait(uv_sem_t* sem) {
int uv_sem_init(uv_sem_t* sem, unsigned int value) { int uv_sem_init(uv_sem_t* sem, unsigned int value) {
if (sem_init(sem, 0, value)) if (sem_init(sem, 0, value))
return -errno; return UV__ERR(errno);
return 0; return 0;
} }
...@@ -542,7 +542,7 @@ int uv_sem_trywait(uv_sem_t* sem) { ...@@ -542,7 +542,7 @@ int uv_sem_trywait(uv_sem_t* sem) {
if (r) { if (r) {
if (errno == EAGAIN) if (errno == EAGAIN)
return -EAGAIN; return UV_EAGAIN;
abort(); abort();
} }
...@@ -555,7 +555,7 @@ int uv_sem_trywait(uv_sem_t* sem) { ...@@ -555,7 +555,7 @@ int uv_sem_trywait(uv_sem_t* sem) {
#if defined(__APPLE__) && defined(__MACH__) || defined(__MVS__) #if defined(__APPLE__) && defined(__MACH__) || defined(__MVS__)
int uv_cond_init(uv_cond_t* cond) { int uv_cond_init(uv_cond_t* cond) {
return -pthread_cond_init(cond, NULL); return UV__ERR(pthread_cond_init(cond, NULL));
} }
#else /* !(defined(__APPLE__) && defined(__MACH__)) */ #else /* !(defined(__APPLE__) && defined(__MACH__)) */
...@@ -566,7 +566,7 @@ int uv_cond_init(uv_cond_t* cond) { ...@@ -566,7 +566,7 @@ int uv_cond_init(uv_cond_t* cond) {
err = pthread_condattr_init(&attr); err = pthread_condattr_init(&attr);
if (err) if (err)
return -err; return UV__ERR(err);
#if !(defined(__ANDROID_API__) && __ANDROID_API__ < 21) #if !(defined(__ANDROID_API__) && __ANDROID_API__ < 21)
err = pthread_condattr_setclock(&attr, CLOCK_MONOTONIC); err = pthread_condattr_setclock(&attr, CLOCK_MONOTONIC);
...@@ -588,7 +588,7 @@ error: ...@@ -588,7 +588,7 @@ error:
pthread_cond_destroy(cond); pthread_cond_destroy(cond);
error2: error2:
pthread_condattr_destroy(&attr); pthread_condattr_destroy(&attr);
return -err; return UV__ERR(err);
} }
#endif /* defined(__APPLE__) && defined(__MACH__) */ #endif /* defined(__APPLE__) && defined(__MACH__) */
...@@ -646,13 +646,22 @@ void uv_cond_wait(uv_cond_t* cond, uv_mutex_t* mutex) { ...@@ -646,13 +646,22 @@ void uv_cond_wait(uv_cond_t* cond, uv_mutex_t* mutex) {
int uv_cond_timedwait(uv_cond_t* cond, uv_mutex_t* mutex, uint64_t timeout) { int uv_cond_timedwait(uv_cond_t* cond, uv_mutex_t* mutex, uint64_t timeout) {
int r; int r;
struct timespec ts; struct timespec ts;
#if defined(__MVS__)
struct timeval tv;
#endif
#if defined(__APPLE__) && defined(__MACH__) #if defined(__APPLE__) && defined(__MACH__)
ts.tv_sec = timeout / NANOSEC; ts.tv_sec = timeout / NANOSEC;
ts.tv_nsec = timeout % NANOSEC; ts.tv_nsec = timeout % NANOSEC;
r = pthread_cond_timedwait_relative_np(cond, mutex, &ts); r = pthread_cond_timedwait_relative_np(cond, mutex, &ts);
#else
#if defined(__MVS__)
if (gettimeofday(&tv, NULL))
abort();
timeout += tv.tv_sec * NANOSEC + tv.tv_usec * 1e3;
#else #else
timeout += uv__hrtime(UV_CLOCK_PRECISE); timeout += uv__hrtime(UV_CLOCK_PRECISE);
#endif
ts.tv_sec = timeout / NANOSEC; ts.tv_sec = timeout / NANOSEC;
ts.tv_nsec = timeout % NANOSEC; ts.tv_nsec = timeout % NANOSEC;
#if defined(__ANDROID_API__) && __ANDROID_API__ < 21 #if defined(__ANDROID_API__) && __ANDROID_API__ < 21
...@@ -672,15 +681,15 @@ int uv_cond_timedwait(uv_cond_t* cond, uv_mutex_t* mutex, uint64_t timeout) { ...@@ -672,15 +681,15 @@ int uv_cond_timedwait(uv_cond_t* cond, uv_mutex_t* mutex, uint64_t timeout) {
return 0; return 0;
if (r == ETIMEDOUT) if (r == ETIMEDOUT)
return -ETIMEDOUT; return UV_ETIMEDOUT;
abort(); abort();
return -EINVAL; /* Satisfy the compiler. */ return UV_EINVAL; /* Satisfy the compiler. */
} }
int uv_barrier_init(uv_barrier_t* barrier, unsigned int count) { int uv_barrier_init(uv_barrier_t* barrier, unsigned int count) {
return -pthread_barrier_init(barrier, NULL, count); return UV__ERR(pthread_barrier_init(barrier, NULL, count));
} }
...@@ -699,7 +708,7 @@ int uv_barrier_wait(uv_barrier_t* barrier) { ...@@ -699,7 +708,7 @@ int uv_barrier_wait(uv_barrier_t* barrier) {
int uv_key_create(uv_key_t* key) { int uv_key_create(uv_key_t* key) {
return -pthread_key_create(key, NULL); return UV__ERR(pthread_key_create(key, NULL));
} }
......
...@@ -66,7 +66,7 @@ int uv_timer_start(uv_timer_t* handle, ...@@ -66,7 +66,7 @@ int uv_timer_start(uv_timer_t* handle,
uint64_t clamped_timeout; uint64_t clamped_timeout;
if (cb == NULL) if (cb == NULL)
return -EINVAL; return UV_EINVAL;
if (uv__is_active(handle)) if (uv__is_active(handle))
uv_timer_stop(handle); uv_timer_stop(handle);
...@@ -105,7 +105,7 @@ int uv_timer_stop(uv_timer_t* handle) { ...@@ -105,7 +105,7 @@ int uv_timer_stop(uv_timer_t* handle) {
int uv_timer_again(uv_timer_t* handle) { int uv_timer_again(uv_timer_t* handle) {
if (handle->timer_cb == NULL) if (handle->timer_cb == NULL)
return -EINVAL; return UV_EINVAL;
if (handle->repeat) { if (handle->repeat) {
uv_timer_stop(handle); uv_timer_stop(handle);
......
...@@ -106,7 +106,7 @@ int uv_tty_init(uv_loop_t* loop, uv_tty_t* tty, int fd, int readable) { ...@@ -106,7 +106,7 @@ int uv_tty_init(uv_loop_t* loop, uv_tty_t* tty, int fd, int readable) {
*/ */
type = uv_guess_handle(fd); type = uv_guess_handle(fd);
if (type == UV_FILE || type == UV_UNKNOWN_HANDLE) if (type == UV_FILE || type == UV_UNKNOWN_HANDLE)
return -EINVAL; return UV_EINVAL;
flags = 0; flags = 0;
newfd = -1; newfd = -1;
...@@ -142,7 +142,7 @@ int uv_tty_init(uv_loop_t* loop, uv_tty_t* tty, int fd, int readable) { ...@@ -142,7 +142,7 @@ int uv_tty_init(uv_loop_t* loop, uv_tty_t* tty, int fd, int readable) {
newfd = r; newfd = r;
r = uv__dup2_cloexec(newfd, fd); r = uv__dup2_cloexec(newfd, fd);
if (r < 0 && r != -EINVAL) { if (r < 0 && r != UV_EINVAL) {
/* EINVAL means newfd == fd which could conceivably happen if another /* EINVAL means newfd == fd which could conceivably happen if another
* thread called close(fd) between our calls to isatty() and open(). * thread called close(fd) between our calls to isatty() and open().
* That's a rather unlikely event but let's handle it anyway. * That's a rather unlikely event but let's handle it anyway.
...@@ -163,7 +163,7 @@ int uv_tty_init(uv_loop_t* loop, uv_tty_t* tty, int fd, int readable) { ...@@ -163,7 +163,7 @@ int uv_tty_init(uv_loop_t* loop, uv_tty_t* tty, int fd, int readable) {
if (saved_flags == -1) { if (saved_flags == -1) {
if (newfd != -1) if (newfd != -1)
uv__close(newfd); uv__close(newfd);
return -errno; return UV__ERR(errno);
} }
#endif #endif
...@@ -234,7 +234,7 @@ int uv_tty_set_mode(uv_tty_t* tty, uv_tty_mode_t mode) { ...@@ -234,7 +234,7 @@ int uv_tty_set_mode(uv_tty_t* tty, uv_tty_mode_t mode) {
fd = uv__stream_fd(tty); fd = uv__stream_fd(tty);
if (tty->mode == UV_TTY_MODE_NORMAL && mode != UV_TTY_MODE_NORMAL) { if (tty->mode == UV_TTY_MODE_NORMAL && mode != UV_TTY_MODE_NORMAL) {
if (tcgetattr(fd, &tty->orig_termios)) if (tcgetattr(fd, &tty->orig_termios))
return -errno; return UV__ERR(errno);
/* This is used for uv_tty_reset_mode() */ /* This is used for uv_tty_reset_mode() */
uv_spinlock_lock(&termios_spinlock); uv_spinlock_lock(&termios_spinlock);
...@@ -264,7 +264,7 @@ int uv_tty_set_mode(uv_tty_t* tty, uv_tty_mode_t mode) { ...@@ -264,7 +264,7 @@ int uv_tty_set_mode(uv_tty_t* tty, uv_tty_mode_t mode) {
/* Apply changes after draining */ /* Apply changes after draining */
if (tcsetattr(fd, TCSADRAIN, &tmp)) if (tcsetattr(fd, TCSADRAIN, &tmp))
return -errno; return UV__ERR(errno);
tty->mode = mode; tty->mode = mode;
return 0; return 0;
...@@ -280,7 +280,7 @@ int uv_tty_get_winsize(uv_tty_t* tty, int* width, int* height) { ...@@ -280,7 +280,7 @@ int uv_tty_get_winsize(uv_tty_t* tty, int* width, int* height) {
while (err == -1 && errno == EINTR); while (err == -1 && errno == EINTR);
if (err == -1) if (err == -1)
return -errno; return UV__ERR(errno);
*width = ws.ws_col; *width = ws.ws_col;
*height = ws.ws_row; *height = ws.ws_row;
...@@ -358,12 +358,12 @@ int uv_tty_reset_mode(void) { ...@@ -358,12 +358,12 @@ int uv_tty_reset_mode(void) {
saved_errno = errno; saved_errno = errno;
if (!uv_spinlock_trylock(&termios_spinlock)) if (!uv_spinlock_trylock(&termios_spinlock))
return -EBUSY; /* In uv_tty_set_mode(). */ return UV_EBUSY; /* In uv_tty_set_mode(). */
err = 0; err = 0;
if (orig_termios_fd != -1) if (orig_termios_fd != -1)
if (tcsetattr(orig_termios_fd, TCSANOW, &orig_termios)) if (tcsetattr(orig_termios_fd, TCSANOW, &orig_termios))
err = -errno; err = UV__ERR(errno);
uv_spinlock_unlock(&termios_spinlock); uv_spinlock_unlock(&termios_spinlock);
errno = saved_errno; errno = saved_errno;
......
...@@ -72,7 +72,7 @@ void uv__udp_finish_close(uv_udp_t* handle) { ...@@ -72,7 +72,7 @@ void uv__udp_finish_close(uv_udp_t* handle) {
QUEUE_REMOVE(q); QUEUE_REMOVE(q);
req = QUEUE_DATA(q, uv_udp_send_t, queue); req = QUEUE_DATA(q, uv_udp_send_t, queue);
req->status = -ECANCELED; req->status = UV_ECANCELED;
QUEUE_INSERT_TAIL(&handle->write_completed_queue, &req->queue); QUEUE_INSERT_TAIL(&handle->write_completed_queue, &req->queue);
} }
...@@ -189,7 +189,7 @@ static void uv__udp_recvmsg(uv_udp_t* handle) { ...@@ -189,7 +189,7 @@ static void uv__udp_recvmsg(uv_udp_t* handle) {
if (errno == EAGAIN || errno == EWOULDBLOCK) if (errno == EAGAIN || errno == EWOULDBLOCK)
handle->recv_cb(handle, 0, &buf, NULL, 0); handle->recv_cb(handle, 0, &buf, NULL, 0);
else else
handle->recv_cb(handle, -errno, &buf, NULL, 0); handle->recv_cb(handle, UV__ERR(errno), &buf, NULL, 0);
} }
else { else {
const struct sockaddr *addr; const struct sockaddr *addr;
...@@ -242,7 +242,7 @@ static void uv__udp_sendmsg(uv_udp_t* handle) { ...@@ -242,7 +242,7 @@ static void uv__udp_sendmsg(uv_udp_t* handle) {
break; break;
} }
req->status = (size == -1 ? -errno : size); req->status = (size == -1 ? UV__ERR(errno) : size);
/* Sending a datagram is an atomic operation: either all data /* Sending a datagram is an atomic operation: either all data
* is written or nothing is (and EMSGSIZE is raised). That is * is written or nothing is (and EMSGSIZE is raised). That is
...@@ -270,11 +270,11 @@ static int uv__set_reuse(int fd) { ...@@ -270,11 +270,11 @@ static int uv__set_reuse(int fd) {
#if defined(SO_REUSEPORT) && !defined(__linux__) #if defined(SO_REUSEPORT) && !defined(__linux__)
yes = 1; yes = 1;
if (setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, &yes, sizeof(yes))) if (setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, &yes, sizeof(yes)))
return -errno; return UV__ERR(errno);
#else #else
yes = 1; yes = 1;
if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes))) if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes)))
return -errno; return UV__ERR(errno);
#endif #endif
return 0; return 0;
...@@ -291,11 +291,11 @@ int uv__udp_bind(uv_udp_t* handle, ...@@ -291,11 +291,11 @@ int uv__udp_bind(uv_udp_t* handle,
/* Check for bad flags. */ /* Check for bad flags. */
if (flags & ~(UV_UDP_IPV6ONLY | UV_UDP_REUSEADDR)) if (flags & ~(UV_UDP_IPV6ONLY | UV_UDP_REUSEADDR))
return -EINVAL; return UV_EINVAL;
/* Cannot set IPv6-only mode on non-IPv6 socket. */ /* Cannot set IPv6-only mode on non-IPv6 socket. */
if ((flags & UV_UDP_IPV6ONLY) && addr->sa_family != AF_INET6) if ((flags & UV_UDP_IPV6ONLY) && addr->sa_family != AF_INET6)
return -EINVAL; return UV_EINVAL;
fd = handle->io_watcher.fd; fd = handle->io_watcher.fd;
if (fd == -1) { if (fd == -1) {
...@@ -316,21 +316,21 @@ int uv__udp_bind(uv_udp_t* handle, ...@@ -316,21 +316,21 @@ int uv__udp_bind(uv_udp_t* handle,
#ifdef IPV6_V6ONLY #ifdef IPV6_V6ONLY
yes = 1; yes = 1;
if (setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, &yes, sizeof yes) == -1) { if (setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, &yes, sizeof yes) == -1) {
err = -errno; err = UV__ERR(errno);
return err; return err;
} }
#else #else
err = -ENOTSUP; err = UV_ENOTSUP;
return err; return err;
#endif #endif
} }
if (bind(fd, addr, addrlen)) { if (bind(fd, addr, addrlen)) {
err = -errno; err = UV__ERR(errno);
if (errno == EAFNOSUPPORT) if (errno == EAFNOSUPPORT)
/* OSX, other BSDs and SunoS fail with EAFNOSUPPORT when binding a /* OSX, other BSDs and SunoS fail with EAFNOSUPPORT when binding a
* socket created with AF_INET to an AF_INET6 address or vice versa. */ * socket created with AF_INET to an AF_INET6 address or vice versa. */
err = -EINVAL; err = UV_EINVAL;
return err; return err;
} }
...@@ -418,7 +418,7 @@ int uv__udp_send(uv_udp_send_t* req, ...@@ -418,7 +418,7 @@ int uv__udp_send(uv_udp_send_t* req,
if (req->bufs == NULL) { if (req->bufs == NULL) {
uv__req_unregister(handle->loop, req); uv__req_unregister(handle->loop, req);
return -ENOMEM; return UV_ENOMEM;
} }
memcpy(req->bufs, bufs, nbufs * sizeof(bufs[0])); memcpy(req->bufs, bufs, nbufs * sizeof(bufs[0]));
...@@ -457,7 +457,7 @@ int uv__udp_try_send(uv_udp_t* handle, ...@@ -457,7 +457,7 @@ int uv__udp_try_send(uv_udp_t* handle,
/* already sending a message */ /* already sending a message */
if (handle->send_queue_count != 0) if (handle->send_queue_count != 0)
return -EAGAIN; return UV_EAGAIN;
err = uv__udp_maybe_deferred_bind(handle, addr->sa_family, 0); err = uv__udp_maybe_deferred_bind(handle, addr->sa_family, 0);
if (err) if (err)
...@@ -475,9 +475,9 @@ int uv__udp_try_send(uv_udp_t* handle, ...@@ -475,9 +475,9 @@ int uv__udp_try_send(uv_udp_t* handle,
if (size == -1) { if (size == -1) {
if (errno == EAGAIN || errno == EWOULDBLOCK || errno == ENOBUFS) if (errno == EAGAIN || errno == EWOULDBLOCK || errno == ENOBUFS)
return -EAGAIN; return UV_EAGAIN;
else else
return -errno; return UV__ERR(errno);
} }
return size; return size;
...@@ -512,7 +512,7 @@ static int uv__udp_set_membership4(uv_udp_t* handle, ...@@ -512,7 +512,7 @@ static int uv__udp_set_membership4(uv_udp_t* handle,
optname = IP_DROP_MEMBERSHIP; optname = IP_DROP_MEMBERSHIP;
break; break;
default: default:
return -EINVAL; return UV_EINVAL;
} }
if (setsockopt(handle->io_watcher.fd, if (setsockopt(handle->io_watcher.fd,
...@@ -522,9 +522,9 @@ static int uv__udp_set_membership4(uv_udp_t* handle, ...@@ -522,9 +522,9 @@ static int uv__udp_set_membership4(uv_udp_t* handle,
sizeof(mreq))) { sizeof(mreq))) {
#if defined(__MVS__) #if defined(__MVS__)
if (errno == ENXIO) if (errno == ENXIO)
return -ENODEV; return UV_ENODEV;
#endif #endif
return -errno; return UV__ERR(errno);
} }
return 0; return 0;
...@@ -543,7 +543,7 @@ static int uv__udp_set_membership6(uv_udp_t* handle, ...@@ -543,7 +543,7 @@ static int uv__udp_set_membership6(uv_udp_t* handle,
if (interface_addr) { if (interface_addr) {
if (uv_ip6_addr(interface_addr, 0, &addr6)) if (uv_ip6_addr(interface_addr, 0, &addr6))
return -EINVAL; return UV_EINVAL;
mreq.ipv6mr_interface = addr6.sin6_scope_id; mreq.ipv6mr_interface = addr6.sin6_scope_id;
} else { } else {
mreq.ipv6mr_interface = 0; mreq.ipv6mr_interface = 0;
...@@ -559,7 +559,7 @@ static int uv__udp_set_membership6(uv_udp_t* handle, ...@@ -559,7 +559,7 @@ static int uv__udp_set_membership6(uv_udp_t* handle,
optname = IPV6_DROP_MEMBERSHIP; optname = IPV6_DROP_MEMBERSHIP;
break; break;
default: default:
return -EINVAL; return UV_EINVAL;
} }
if (setsockopt(handle->io_watcher.fd, if (setsockopt(handle->io_watcher.fd,
...@@ -569,9 +569,9 @@ static int uv__udp_set_membership6(uv_udp_t* handle, ...@@ -569,9 +569,9 @@ static int uv__udp_set_membership6(uv_udp_t* handle,
sizeof(mreq))) { sizeof(mreq))) {
#if defined(__MVS__) #if defined(__MVS__)
if (errno == ENXIO) if (errno == ENXIO)
return -ENODEV; return UV_ENODEV;
#endif #endif
return -errno; return UV__ERR(errno);
} }
return 0; return 0;
...@@ -586,10 +586,10 @@ int uv_udp_init_ex(uv_loop_t* loop, uv_udp_t* handle, unsigned int flags) { ...@@ -586,10 +586,10 @@ int uv_udp_init_ex(uv_loop_t* loop, uv_udp_t* handle, unsigned int flags) {
/* Use the lower 8 bits for the domain */ /* Use the lower 8 bits for the domain */
domain = flags & 0xFF; domain = flags & 0xFF;
if (domain != AF_INET && domain != AF_INET6 && domain != AF_UNSPEC) if (domain != AF_INET && domain != AF_INET6 && domain != AF_UNSPEC)
return -EINVAL; return UV_EINVAL;
if (flags & ~0xFF) if (flags & ~0xFF)
return -EINVAL; return UV_EINVAL;
if (domain != AF_UNSPEC) { if (domain != AF_UNSPEC) {
err = uv__socket(domain, SOCK_DGRAM, 0); err = uv__socket(domain, SOCK_DGRAM, 0);
...@@ -622,7 +622,7 @@ int uv_udp_open(uv_udp_t* handle, uv_os_sock_t sock) { ...@@ -622,7 +622,7 @@ int uv_udp_open(uv_udp_t* handle, uv_os_sock_t sock) {
/* Check for already active socket. */ /* Check for already active socket. */
if (handle->io_watcher.fd != -1) if (handle->io_watcher.fd != -1)
return -EBUSY; return UV_EBUSY;
err = uv__nonblock(sock, 1); err = uv__nonblock(sock, 1);
if (err) if (err)
...@@ -656,7 +656,7 @@ int uv_udp_set_membership(uv_udp_t* handle, ...@@ -656,7 +656,7 @@ int uv_udp_set_membership(uv_udp_t* handle,
return err; return err;
return uv__udp_set_membership6(handle, &addr6, interface_addr, membership); return uv__udp_set_membership6(handle, &addr6, interface_addr, membership);
} else { } else {
return -EINVAL; return UV_EINVAL;
} }
} }
...@@ -680,7 +680,7 @@ static int uv__setsockopt(uv_udp_t* handle, ...@@ -680,7 +680,7 @@ static int uv__setsockopt(uv_udp_t* handle,
val, val,
size); size);
if (r) if (r)
return -errno; return UV__ERR(errno);
return 0; return 0;
} }
...@@ -698,7 +698,7 @@ static int uv__setsockopt_maybe_char(uv_udp_t* handle, ...@@ -698,7 +698,7 @@ static int uv__setsockopt_maybe_char(uv_udp_t* handle,
#endif #endif
if (val < 0 || val > 255) if (val < 0 || val > 255)
return -EINVAL; return UV_EINVAL;
return uv__setsockopt(handle, option4, option6, &arg, sizeof(arg)); return uv__setsockopt(handle, option4, option6, &arg, sizeof(arg));
} }
...@@ -710,7 +710,7 @@ int uv_udp_set_broadcast(uv_udp_t* handle, int on) { ...@@ -710,7 +710,7 @@ int uv_udp_set_broadcast(uv_udp_t* handle, int on) {
SO_BROADCAST, SO_BROADCAST,
&on, &on,
sizeof(on))) { sizeof(on))) {
return -errno; return UV__ERR(errno);
} }
return 0; return 0;
...@@ -719,11 +719,11 @@ int uv_udp_set_broadcast(uv_udp_t* handle, int on) { ...@@ -719,11 +719,11 @@ int uv_udp_set_broadcast(uv_udp_t* handle, int on) {
int uv_udp_set_ttl(uv_udp_t* handle, int ttl) { int uv_udp_set_ttl(uv_udp_t* handle, int ttl) {
if (ttl < 1 || ttl > 255) if (ttl < 1 || ttl > 255)
return -EINVAL; return UV_EINVAL;
#if defined(__MVS__) #if defined(__MVS__)
if (!(handle->flags & UV_HANDLE_IPV6)) if (!(handle->flags & UV_HANDLE_IPV6))
return -ENOTSUP; /* zOS does not support setting ttl for IPv4 */ return UV_ENOTSUP; /* zOS does not support setting ttl for IPv4 */
#endif #endif
/* /*
...@@ -817,7 +817,7 @@ int uv_udp_set_multicast_interface(uv_udp_t* handle, const char* interface_addr) ...@@ -817,7 +817,7 @@ int uv_udp_set_multicast_interface(uv_udp_t* handle, const char* interface_addr)
} else if (uv_ip6_addr(interface_addr, 0, addr6) == 0) { } else if (uv_ip6_addr(interface_addr, 0, addr6) == 0) {
/* nothing, address was parsed */ /* nothing, address was parsed */
} else { } else {
return -EINVAL; return UV_EINVAL;
} }
if (addr_st.ss_family == AF_INET) { if (addr_st.ss_family == AF_INET) {
...@@ -826,7 +826,7 @@ int uv_udp_set_multicast_interface(uv_udp_t* handle, const char* interface_addr) ...@@ -826,7 +826,7 @@ int uv_udp_set_multicast_interface(uv_udp_t* handle, const char* interface_addr)
IP_MULTICAST_IF, IP_MULTICAST_IF,
(void*) &addr4->sin_addr, (void*) &addr4->sin_addr,
sizeof(addr4->sin_addr)) == -1) { sizeof(addr4->sin_addr)) == -1) {
return -errno; return UV__ERR(errno);
} }
} else if (addr_st.ss_family == AF_INET6) { } else if (addr_st.ss_family == AF_INET6) {
if (setsockopt(handle->io_watcher.fd, if (setsockopt(handle->io_watcher.fd,
...@@ -834,7 +834,7 @@ int uv_udp_set_multicast_interface(uv_udp_t* handle, const char* interface_addr) ...@@ -834,7 +834,7 @@ int uv_udp_set_multicast_interface(uv_udp_t* handle, const char* interface_addr)
IPV6_MULTICAST_IF, IPV6_MULTICAST_IF,
&addr6->sin6_scope_id, &addr6->sin6_scope_id,
sizeof(addr6->sin6_scope_id)) == -1) { sizeof(addr6->sin6_scope_id)) == -1) {
return -errno; return UV__ERR(errno);
} }
} else { } else {
assert(0 && "unexpected address family"); assert(0 && "unexpected address family");
...@@ -851,13 +851,13 @@ int uv_udp_getsockname(const uv_udp_t* handle, ...@@ -851,13 +851,13 @@ int uv_udp_getsockname(const uv_udp_t* handle,
socklen_t socklen; socklen_t socklen;
if (handle->io_watcher.fd == -1) if (handle->io_watcher.fd == -1)
return -EINVAL; /* FIXME(bnoordhuis) -EBADF */ return UV_EINVAL; /* FIXME(bnoordhuis) UV_EBADF */
/* sizeof(socklen_t) != sizeof(int) on some systems. */ /* sizeof(socklen_t) != sizeof(int) on some systems. */
socklen = (socklen_t) *namelen; socklen = (socklen_t) *namelen;
if (getsockname(handle->io_watcher.fd, name, &socklen)) if (getsockname(handle->io_watcher.fd, name, &socklen))
return -errno; return UV__ERR(errno);
*namelen = (int) socklen; *namelen = (int) socklen;
return 0; return 0;
...@@ -870,10 +870,10 @@ int uv__udp_recv_start(uv_udp_t* handle, ...@@ -870,10 +870,10 @@ int uv__udp_recv_start(uv_udp_t* handle,
int err; int err;
if (alloc_cb == NULL || recv_cb == NULL) if (alloc_cb == NULL || recv_cb == NULL)
return -EINVAL; return UV_EINVAL;
if (uv__io_active(&handle->io_watcher, POLLIN)) if (uv__io_active(&handle->io_watcher, POLLIN))
return -EALREADY; /* FIXME(bnoordhuis) Should be -EBUSY. */ return UV_EALREADY; /* FIXME(bnoordhuis) Should be UV_EBUSY. */
err = uv__udp_maybe_deferred_bind(handle, AF_INET, 0); err = uv__udp_maybe_deferred_bind(handle, AF_INET, 0);
if (err) if (err)
......
...@@ -41,6 +41,12 @@ ...@@ -41,6 +41,12 @@
#include "tree.h" #include "tree.h"
#include "queue.h" #include "queue.h"
#if EDOM > 0
# define UV__ERR(x) (-(x))
#else
# define UV__ERR(x) (x)
#endif
#if !defined(snprintf) && defined(_MSC_VER) && _MSC_VER < 1900 #if !defined(snprintf) && defined(_MSC_VER) && _MSC_VER < 1900
extern int snprintf(char*, size_t, const char*, ...); extern int snprintf(char*, size_t, const char*, ...);
#endif #endif
......
This diff is collapsed.
...@@ -245,6 +245,7 @@ INLINE static void uv_fs_req_init(uv_loop_t* loop, uv_fs_t* req, ...@@ -245,6 +245,7 @@ INLINE static void uv_fs_req_init(uv_loop_t* loop, uv_fs_t* req,
req->ptr = NULL; req->ptr = NULL;
req->path = NULL; req->path = NULL;
req->cb = cb; req->cb = cb;
req->fs.info.bufs = NULL;
memset(&req->fs, 0, sizeof(req->fs)); memset(&req->fs, 0, sizeof(req->fs));
} }
...@@ -1785,7 +1786,7 @@ static void fs__symlink(uv_fs_t* req) { ...@@ -1785,7 +1786,7 @@ static void fs__symlink(uv_fs_t* req) {
} }
if (req->fs.info.file_flags & UV_FS_SYMLINK_DIR) if (req->fs.info.file_flags & UV_FS_SYMLINK_DIR)
flags = SYMBOLIC_LINK_FLAG_DIRECTORY; flags = SYMBOLIC_LINK_FLAG_DIRECTORY | uv__file_symlink_usermode_flag;
else else
flags = uv__file_symlink_usermode_flag; flags = uv__file_symlink_usermode_flag;
......
...@@ -1061,11 +1061,16 @@ int uv_spawn(uv_loop_t* loop, ...@@ -1061,11 +1061,16 @@ 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) {
/* Avoid creating console window if stdio is not inherited. */
for (i = 0; i < options->stdio_count; i++) {
if (options->stdio[i].flags & UV_INHERIT_FD)
break;
if (i == options->stdio_count - 1)
process_flags |= CREATE_NO_WINDOW;
}
/* 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;
/* Hide console windows. */
process_flags |= CREATE_NO_WINDOW;
} else { } else {
startup.wShowWindow = SW_SHOWDEFAULT; startup.wShowWindow = SW_SHOWDEFAULT;
} }
...@@ -1173,6 +1178,10 @@ int uv_spawn(uv_loop_t* loop, ...@@ -1173,6 +1178,10 @@ int uv_spawn(uv_loop_t* loop,
static int uv__kill(HANDLE process_handle, int signum) { static int uv__kill(HANDLE process_handle, int signum) {
if (signum < 0 || signum >= NSIG) {
return UV_EINVAL;
}
switch (signum) { switch (signum) {
case SIGTERM: case SIGTERM:
case SIGKILL: case SIGKILL:
...@@ -1237,8 +1246,15 @@ int uv_process_kill(uv_process_t* process, int signum) { ...@@ -1237,8 +1246,15 @@ int uv_process_kill(uv_process_t* process, int signum) {
int uv_kill(int pid, int signum) { int uv_kill(int pid, int signum) {
int err; int err;
HANDLE process_handle = OpenProcess(PROCESS_TERMINATE | HANDLE process_handle;
PROCESS_QUERY_INFORMATION, FALSE, pid);
if (pid == 0) {
process_handle = GetCurrentProcess();
} else {
process_handle = OpenProcess(PROCESS_TERMINATE | PROCESS_QUERY_INFORMATION,
FALSE,
pid);
}
if (process_handle == NULL) { if (process_handle == NULL) {
err = GetLastError(); err = GetLastError();
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
...@@ -187,4 +187,7 @@ typedef struct _IP_ADAPTER_UNICAST_ADDRESS_LH { ...@@ -187,4 +187,7 @@ typedef struct _IP_ADAPTER_UNICAST_ADDRESS_LH {
#endif #endif
int uv__convert_to_localhost_if_unspecified(const struct sockaddr* addr,
struct sockaddr_storage* storage);
#endif /* UV_WIN_WINSOCK_H_ */ #endif /* UV_WIN_WINSOCK_H_ */
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment