Commit Graph

1638 Commits

Author SHA1 Message Date
Sai Ke WANG
d0a27baa7d sunos: fix cmpxchgi and cmpxchgl type error
atomic_cas_ptr() is for compare-and-swap pointer addresses.
So when building 64 bit:

1. `ptr` is used casted to a pointer value (4-byte into 8-byte).
2. atomic_cas_ptr reads 8-byte at `ptr` and returns

In the case of `uv_async_send`, if handle->pending is 0, cmpxchgi()
actually returns the value of the 4-bytes past handle->pending,
causing uv__async_send to never be called.

The modified test-async-null-cb.c hangs at uv_run in this case.

PR-URL: https://github.com/libuv/libuv/pull/1361
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2017-07-01 00:24:42 +02:00
Sebastian Wiedenroth
26daa99e2c sunos: filter out non-IPv4/IPv6 interfaces
Filter out anything that is not an IPv4 or IPv6 interface in
uv_interface_addresses().

PR-URL: https://github.com/libuv/libuv/pull/1387
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2017-06-28 20:17:31 +02:00
John Barboza
d5fc593b5f
zos: avoid compiler warnings
Some of these compiler flags are not supported. So don't
use them.

PR-URL: https://github.com/libuv/libuv/pull/1373
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2017-06-23 09:47:16 +02:00
Santiago Gimeno
404ee42706
unix,stream: return error on closed handle passing
Return `EBADF` when trying to send a handle which, while enqueued, was
closed.

Fixes: https://github.com/libuv/libuv/issues/806
PR-URL: https://github.com/libuv/libuv/pull/1352
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2017-06-23 09:38:15 +02:00
Michele Caini
f2756500ed unix: avoid segfault in uv_get_process_title
Fixes: https://github.com/libuv/libuv/issues/1359
PR-URL: https://github.com/libuv/libuv/pull/1360
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2017-05-31 08:46:56 +02:00
Juan Cruz Viotti
e133923e93 win: make uv__get_osfhandle() public
The uv__get_osfhandle() function is a private functio of the
Windows subsystem, and its used to get a Windows HANDLE out
of a file descriptor number.

The motivation behind making this function public is to
allow Node.js programs to pass file descriptors created
using fs.open() to native Node.js C++ add-ons, and be able to
successfully convert them to Windows HANDLEs.

Refs: https://github.com/libuv/libuv/pull/1166
Refs: https://github.com/nodejs/node/issues/6369
Fixes: https://github.com/libuv/libuv/issues/1291
PR-URL: https://github.com/libuv/libuv/pull/1323
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Bartosz Sosnowski <bartosz@janeasystems.com>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2017-05-30 11:53:31 -04:00
Brad King
580f032737 cygwin: disable non-functional ipc handle send
On Cygwin `recvmsg` always sets `msg_controllen` to zero on a
message received from a named pipe.  Therefore we cannot use
`sendmsg` to send handles for ipc.  Return failure early from
this code path as `ENOSYS`.

Skip tests requiring this feature since it is not available.

PR-URL: https://github.com/libuv/libuv/pull/1312
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
2017-05-21 16:12:28 +02:00
Brad King
317fc756a5 cygwin: fix uv_pipe_connect report of ENOTSOCK
On Cygwin a `connect` to a file that is not a socket fails
with `EBADF` instead of `ENOTSOCK` even though the former is
supposed to be for a bad socket fd.  Translate the error.

This fixes the `pipe_connect_to_file` to file test.

PR-URL: https://github.com/libuv/libuv/pull/1312
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
2017-05-21 16:12:26 +02:00
Brad King
2e197418c3 cygwin: recognize EOF on named pipe closure
On Cygwin a named pipe closed by terminating a child process
may be reported via `ECONNRESET` on the next read.  Teach
`uv__read` to interpret this as end of file.

This fixes the `spawn_and_kill_with_std` test.

PR-URL: https://github.com/libuv/libuv/pull/1312
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
2017-05-21 16:12:24 +02:00
Brad King
6398251aff cygwin: implement support for cygwin and msys2
Cygwin and MSYS2 are POSIX layers implemented on top of Windows.
Use our POSIX `poll(2)` implementation of our poll abstraction.
For most other components we already have dedicated sources
implementing them in terms of APIs available on Cygwin or
providing non-implementations of components not supported.

This leaves only three components that need Cygwin-specific
implementations:

* uv_uptime: implement using sysinfo
* uv_resident_set_memory: add a placeholder returning UV_ENOSYS
* uv_cpu_info: add a placeholder returning UV_ENOSYS

Update our test suite to account for features not available
due to Cygwin platform limitations or our placeholders.

PR-URL: https://github.com/libuv/libuv/pull/1312
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
2017-05-21 16:12:21 +02:00
Brad King
c108137d7c unix: add a uv__io_poll impl using POSIX poll(2)
POSIX defines `poll()` as a portable way to wait on file descriptors.
Use it to provide an implementation of our poll abstraction for use
on platforms that do not provide a more specialized polling method.

PR-URL: https://github.com/libuv/libuv/pull/1312
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
2017-05-21 16:12:19 +02:00
Brad King
77326e86a2 unix: factor out reusable procfs exepath impl
On Linux we read `/proc/self/exe` for the path to the executable.
Factor out a dedicated source file to make this implementation
available for use on other platforms that support it.

PR-URL: https://github.com/libuv/libuv/pull/1312
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
2017-05-21 16:12:18 +02:00
Brad King
76bcf9f91d unix: factor out reusable sysinfo loadavg impl
On Linux we use `sysinfo(2)` to look up the load average.
Factor out a dedicated source file to make this implementation
available for use on other platforms that support it.

PR-URL: https://github.com/libuv/libuv/pull/1312
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
2017-05-21 16:12:16 +02:00
Brad King
ea795b29ef unix: factor out reusable sysinfo memory lookup
On Linux we use `sysinfo(2)` to look up available memory.
Factor out a dedicated source file to make this implementation
available for use on other platforms that support it.

PR-URL: https://github.com/libuv/libuv/pull/1312
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
2017-05-21 16:12:14 +02:00
Brad King
32ef58bf72 unix: factor out reusable no-fsevents impl
On os390 we implement no support for fsevents.  Other platforms may not
support fsevents either, so provide a dedicated source file to use in
this case.

PR-URL: https://github.com/libuv/libuv/pull/1312
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
2017-05-21 16:12:11 +02:00
Brad King
470b0258b0 unix: factor out reusable no-proctitle impl
On SunOS we implement no support for proctitle.  Other platforms may not
support proctitle either, so provide a dedicated source file to use in
this case.

PR-URL: https://github.com/libuv/libuv/pull/1312
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
2017-05-21 16:11:33 +02:00
John Barboza
ff360e7f14
zos: do not inline OOB data by default
It was previously assumed that OOB data had to be
inlined but that is incorrect.

PR-URL: https://github.com/libuv/libuv/pull/1347
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
2017-05-19 12:14:08 +02:00
cjihrig
d8cd08bd98 unix,win: add uv_os_gethostname()
Fixes: https://github.com/libuv/libuv/issues/1315
PR-URL: https://github.com/libuv/libuv/pull/1342
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
2017-05-18 10:27:47 -04:00
James McCoy
22fc92856d
build,openbsd: remove kvm-related code
Remove the kvm.h include since 38323c9fb replaced the use of kvm_open()
with sysctl(),

Conditionally check for kvm_open() on non-OpenBSD platforms so LIBS (and
libuv.pc) does not unnecessarily contain "-lkvm".

Fixes: https://github.com/libuv/libuv/issues/1340
PR-URL: https://github.com/libuv/libuv/pull/1344
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
2017-05-17 17:50:58 +02:00
cjihrig
1217832e6f unix: remove FSEventStreamFlushSync() call
This call, in the context of file watching, appears to trigger
assertion warnings on some macOS configurations.

Refs: https://github.com/nodejs/node/issues/854
Fixes: https://github.com/libuv/libuv/issues/1334
PR-URL: https://github.com/libuv/libuv/pull/1349
Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2017-05-16 13:03:55 -04:00
Marc Schlaich
e11dcd4377 unix: do not close udp sockets on bind error
This makes Unix behave in the same way as Windows.

Fixes: https://github.com/libuv/libuv/issues/1336
PR-URL: https://github.com/libuv/libuv/pull/1337
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
2017-05-09 15:51:26 -04:00
John Barboza
cb0cc7346d
zos: implement uv__io_fork, skip fs event tests
Basic implementation of uv__io_fork on z/OS.
As of now, since filesystem events are not supported,
skip all of those tests on z/OS.

PR-URL: https://github.com/libuv/libuv/pull/1303
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2017-05-03 11:58:16 +02:00
Jameson Nash
fd39cec4b8
build: add -Wstrict-prototypes
Fixes: https://github.com/libuv/libuv/pull/1320
PR-URL: https://github.com/libuv/libuv/pull/1326
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
2017-05-02 23:00:33 +02:00
Ben Noordhuis
710989b087 zos: use proper prototype for epoll_init()
`int epoll_init()` declares a function that takes any number of
arguments, use `int epoll_init(void)` instead.

PR-URL: https://github.com/libuv/libuv/pull/1314
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: John Barboza <jbarboza@ca.ibm.com>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2017-04-25 17:15:26 +02:00
Fedor Indutny
0cbad54f18 udp: fix fast path in uv_udp_send() on unix
"Fast" path in `uv_udp_send()` attempts to write the data straight away
without queueing the fd with epoll/kqueue/... However, in some cases
this is not possible when `sendmsg()` returns `EAGAIN`. In such event
libuv has to queue the fd anyway.

PR-URL: https://github.com/libuv/libuv/pull/1308
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
2017-04-20 18:10:43 -04:00
Rasmus Christian Pedersen
cd676e2dbc unix,test: deadstore fixes
Fixes deadstore in uv_pipe_bind as 'sockfd' is no longer used.
Fixes deadstore in test related to unused variables or missing
assert.

PR-URL: https://github.com/libuv/libuv/pull/1288
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
2017-04-05 09:57:20 -04:00
cjihrig
36d6b1f445 unix: inline uv_pipe_bind() err_bind goto target
This goto target is only one line, and is only reached from
one place.

PR-URL: https://github.com/libuv/libuv/pull/1289
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2017-04-05 09:52:13 -04:00
Ben Noordhuis
87df1448a4 unix,windows: refactor request init logic
Fixes a TODO in src/threadpool.c.  Updates the Windows code to drop the
unused `loop` parameter in calls to uv_req_init().

PR-URL: https://github.com/libuv/libuv/pull/1091
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2017-03-21 16:14:09 +01:00
cjihrig
463800ffc1 win,sunos: stop handle on uv_fs_event_start() err
This commit stops the handle in uv_fs_event_start() when an
error occurs.

Fixes: https://github.com/libuv/libuv/issues/1253
PR-URL: https://github.com/libuv/libuv/pull/1257
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
2017-03-21 10:35:53 -04:00
Jason Madden
fd7ce57f2b unix: make loops and watchers usable after fork()
Added the uv_loop_fork() API that must be called in a child process to
continue using an existing loop. Internally this calls a uv__io_fork
function for each supported platform, similar to the way
uv__platform_loop_init works.

After this call, existing and new IO, async and signal watchers will
contiue working as before on all platforms, as will the
threadpool (although any threads it was using are of course gone).

On Linux and BSDs that use kqueue, existing and new fsevent watchers
will also continue to work as expected. On OS X, though, directory
fsevents will not be able to use the optimized CoreFoundation path if
they had already been used in the parent process, instead falling back
to the kqueue path used on other BSDs.

Existing fsevent watchers will not function on AIX or SunOS. This
could be relatively easily fixed by someone with AIX knowledge in the
future, but SunOS will require some additional work to keep track if
the watchers.

A new test file, test/test-fork.c, was added to contain fork-related
tests to verify functionality in the child process.

PR-URL: https://github.com/libuv/libuv/pull/846
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2017-03-21 12:23:44 +01:00
Ben Noordhuis
5fc8aecd81 unix: simplify async watcher dispatch logic
Remove the unused `nevents` parameter from `uv__async_event()`
and remove the indirection of having a separate `uv__async`
type.  There is only one instance per event loop these days.

This incidentally removes the `assert(n == sizeof(val))` in a
Linux-specific code path that some users seem to hit from time
to time.  The cause is not well-understood and I've never been
able to reproduce it myself.  Presumably libuv gets an EAGAIN
when trying to read from the eventfd but when and why that
happens is unclear.

Since the byte count is unused, removing the assert seems safe.
Worst case, libuv sometimes iterates over the async watcher list
when it doesn't have to.

Fixes: https://github.com/libuv/libuv/issues/1171
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
Supersedes: https://github.com/libuv/libuv/pull/1214
2017-03-15 10:03:10 +01:00
jBarz
d7cf771072 unix: use union to follow strict aliasing rules
With strict-aliasing rules, a char* type can be cast to any other
pointer type. However, that does not necessarily mean char array
type. So instead of de-referencing a char array, use a union with an
additional char member for aliasing.

PR-URL: https://github.com/libuv/libuv/pull/1211
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2017-03-14 08:42:39 +01:00
Brad King
f277cb6f92 unix: factor out reusable BSD ifaddrs impl
Create a dedicated source file to share among platforms on which we find
ifaddrs using the BSD getifaddrs API.  De-duplicate our existing copies
of this implementation on such platforms.

PR-URL: https://github.com/libuv/libuv/pull/1240
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2017-03-14 08:33:43 +01:00
Brad King
0f84c305e0 unix: factor out getifaddrs result filter
On platforms using getifaddrs we iterate over the interfaces two or
three times.  First we count them, then we enumerate them, and then we
fill in physical addresses.  Each loop needs to do the same filtering,
so factor out the exclusion test into a helper function for each
platform.

PR-URL: https://github.com/libuv/libuv/pull/1240
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2017-03-14 08:33:28 +01:00
Brad King
80c4cf6b62 unix: filter getifaddrs results consistently
We loop over getifaddrs results multiple times.  Fix the filter
conditions to be consistent for all passes.

PR-URL: https://github.com/libuv/libuv/pull/1240
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2017-03-14 08:32:32 +01:00
jBarz
399b08aa9f unix: return UV_EINVAL for NULL env name
"setenv" on z/OS returns successfully on a NULL ptr argument
for name. Check for this on all unixes.

PR-URL: https://github.com/libuv/libuv/pull/1243
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2017-03-14 08:28:46 +01:00
cjihrig
ee02f60c90 unix,win: add uv_os_{get,set,unset}env()
These functions are used to create, retrieve, update, and delete
environment variables.

Fixes: https://github.com/libuv/libuv/issues/1198
PR-URL: https://github.com/libuv/libuv/pull/1234
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
2017-03-08 20:39:33 -05:00
Brad King
2ba39be67e
unix: factor out reusable POSIX hrtime impl
Create a dedicated source file to share among platforms on which we
implement hrtime using POSIX `clock_gettime`.  De-duplicate our
existing copies of this implementation on such platforms.

PR-URL: https://github.com/libuv/libuv/pull/1239
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2017-03-03 15:52:42 +01:00
Santiago Gimeno
45616f542d
signal: add uv_signal_start_oneshot method
It behaves as `uv_signal_start` but it resets the signal handler as soon
as the signal is received.

Fixes: https://github.com/libuv/libuv/issues/1104
PR-URL: https://github.com/libuv/libuv/pull/1106
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
Reviewed-By: Bartosz Sosnowski <bartosz@janeasystems.com>
2017-02-28 14:16:54 +01:00
Fedor Indutny
52ae826492 unix: remove unused code in uv__io_start
The code path in `uv__io_start` cannot be reached because `pevents` is
always non-zero at that point.

PR-URL: https://github.com/libuv/libuv/pull/1227
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2017-02-21 15:36:43 -05:00
Santiago Gimeno
c355c8b1a6
test: fix tests on OpenBSD
It fixes `process_title`, `poll_bad_fdtype` and `poll_nested_kqueue`
tests.

Fixes: https://github.com/libuv/libuv/issues/1216
PR-URL: https://github.com/libuv/libuv/pull/1218
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2017-02-07 17:47:17 +01:00
Gireesh Punathil
fb0f87b6d7 aix: re-enable fs watch facility
On AIX, watch feature depends on AHAFS based Event infrastructure.
While in principle the watch use case is same across platforms, there
are subtle differences in the way AIX deals with this, with few
behavioral changes (external).

This commit opens up the AIX code for watch feature which was masked
under a macro HAVE_SYS_AHAFS_EVPRODS_H and addresses an assertion
failure on folder watch.

PR-URL: https://github.com/libuv/libuv/pull/1156
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
2017-01-30 21:20:10 +01:00
Chris Araman
f35674fe7f Revert "darwin: use clock_gettime in macOS 10.12"
This reverts commit f8d4805087,
which causes run-time link errors when compiled with macOS 10.12
SDK, but run on 10.11 or earlier.

Refs: https://github.com/libuv/libuv/pull/1073
PR-URL: https://github.com/libuv/libuv/pull/1202
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2017-01-28 21:20:10 -05:00
John Barboza
f9484cf515 zos: use built-in proctitle implementation
Use built-in proctitle implementation because there is no such thing as
a process title on zOS.

PR-URL: https://github.com/libuv/libuv/pull/1208
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2017-01-27 18:08:28 +01:00
Howard Hellyer
d6427e4beb
aix: enable uv_get/set_process_title
This patch enables querying and setting the process title on AIX.
libuv takes ownership of the memory for argv and returns a deep copy
of the array and its contents.
It also enables the process_title test case.

The process title can be changed on AIX but is handled differently
to Linux/Mac. Commands like ps read the original argv array passed
to the process instead of the memory at argv[0]. To change the process
title we need to update argv[0] to point at a new string and set
argv[1] to NULL (if it exists). This means the process title
can be set to a string of any length.

PR-URL: https://github.com/libuv/libuv/pull/1187
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
2017-01-26 12:50:49 +01:00
John Barboza
011e02e3e5 zos: make platform functional
Fix all functional test cases:

* use PLO compare,swap,store for atomic instruction
* do not use semaphore.h
* use xplink flag when linking
* scandir implementation
* nanosleep implementation
* add proctitle
* uv_loadavg
* uv_fs_event_init/start
* uv_fs_event_stop
* uv_exepath using __getthent syscall
* read free/total memory from mvs data areas
* uv_resident_set_memory implementation
* network interfaces implementation
* cpu_info implementation
* implement uv__hrtime
* make uv__fs_mkdtemp implementation
* epoll implementation for asyncio
* uv__fs_event_close implementation
* set process title
* read ancillary data that remains on queue
* ancillary data
* implement uv__fs_access
* use /dev/urandom for temporary directory name
* disable proctitle on zos completely

PR-URL: https://github.com/libuv/libuv/pull/1037
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2017-01-18 08:42:59 -06:00
Ben Noordhuis
36ba7eb6bc sunos: fix SUNOS_NO_IFADDRS build
Don't compile uv__set_phys_addr() if SUNOS_NO_IFADDRS is defined,
it has been reported to break the build on Solaris 10.

Bug introduced in commit d75e334 ("sunos: set phys_addr of
interface_address using ARP") from last June.

Fixes: https://github.com/nodejs/node/issues/9856
PR-URL: https://github.com/libuv/libuv/pull/1155
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2017-01-17 21:37:16 -06:00
jBarz
449933623d unix: use async-signal safe functions between fork and exec
Refs: https://github.com/libuv/libuv/issues/998
PR-URL: https://github.com/libuv/libuv/pull/1167
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2017-01-17 21:29:15 -06:00
Santiago Gimeno
d251dee33b fs: cleanup uv__fs_scandir
The `out` section is only reachable now if `scandir` returns 0.

PR-URL: https://github.com/libuv/libuv/pull/1189
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2017-01-17 21:10:43 -06:00
jBarz
8f43417f0e unix: move function call out of assert
assert expressions should only be scalar

PR-URL: https://github.com/libuv/libuv/pull/1196
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2017-01-17 21:08:36 -06:00
Santiago Gimeno
c02176a230
fs: fix uv__to_stat on BSD platforms
Fix the #ifdef logic to make sure all the available fields filled in the
`stat` struct are correcly copied into the `uv_stat_t` struct. Before
this change, the `n_sec` were being set to 0.

PR-URL: https://github.com/libuv/libuv/pull/1152
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2016-12-06 12:08:18 +01:00
Saúl Ibarra Corretgé
f8d4805087 darwin: use clock_gettime in macOS 10.12
PR-URL: https://github.com/libuv/libuv/pull/1073
Reviewed-By: Fedor Indutny <fedor@indutny.com>
Reviewed-By: Imran Iqbal <imran@imraniqbal.org>
2016-12-06 09:44:48 +01:00
Joran Dirk Greef
c1c55ee1aa
darwin: fix fsync and fdatasync
Apple's fsync and fdatasync explicitly do NOT flush the drive write
cache to the drive platters. This is in contrast to Linux's fsync and
fdatasync which do, according to recent man pages. F_FULLFSYNC is
Apple's equivalent for flushing buffered data to permanent storage.

PR-URL: https://github.com/libuv/libuv/pull/1124
Refs: https://github.com/nodejs/node/issues/9439
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
2016-11-17 09:41:58 +01:00
Santiago Gimeno
668d24d88e
unix: use uv__is_closing everywhere
PR-URL: https://github.com/libuv/libuv/pull/1117
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2016-11-03 11:11:16 +01:00
Saúl Ibarra Corretgé
b2e13b9f00 Revert "unix,win: simplify calculating polling timeout"
This reverts commit a35308306f.
The original commit introduced unforeseen regressions. See
https://github.com/libuv/libuv/pull/1096.

Fixes: https://github.com/libuv/libuv/pull/1096
PR-URL: https://github.com/libuv/libuv/pull/1102
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2016-10-21 11:51:54 -04:00
Saúl Ibarra Corretgé
a35308306f unix,win: simplify calculating polling timeout
PR-URL: https://github.com/libuv/libuv/pull/1096
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
2016-10-17 12:20:33 +01:00
Santiago Gimeno
31e5d665d5
signal: replace pthread_once with uv_once
So it aborts in case `pthread_once` fails.

PR-URL: https://github.com/libuv/libuv/pull/1098
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2016-10-17 12:13:59 +02:00
Philippe Laferriere
f1863dae6b unix,win: add uv_translate_sys_error() public API
uv_translate_sys_error() was a private function for Windows.
This commit adds an equivalent function on other platforms, and
exposes it as public API.

Exposing this is useful in scenarios where the application uses
both libuv functions and platform-specific system calls and wants
to report errors uniformly as libuv errors.

Fixes: https://github.com/libuv/libuv/issues/79
PR-URL: https://github.com/libuv/libuv/pull/1060
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2016-10-16 17:47:42 -04:00
Brad King
6b35ca8616 unix: don't include CoreServices globally on macOS
In unix/internal.h, CoreServices is included for AvailabilityMacros.h.
This commit just includes AvailabilityMacros.h directly instead.

PR-URL: https://github.com/libuv/libuv/pull/1092
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2016-10-16 13:35:47 -04:00
Ben Noordhuis
3064ae98e5 unix: don't malloc in uv_thread_create()
Simplify and optimize uv_thread_create() by casting the function pointer
to the prototype that pthread_create() wants.  Avoids the indirection of
an intermediate callback and heap-allocating custom state that is really
only there to placate the compiler.

PR-URL: https://github.com/libuv/libuv/pull/1094
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2016-10-16 19:28:17 +02:00
Ben Noordhuis
e7bc260c42 unix: don't use alphasort in uv_fs_scandir()
alphasort() uses strcoll() in some libcs (notably glibc and musl) which
makes it locale-sensitive.

Replace it with a simple strcmp-based lexicographic comparison for
consistent behavior across platforms.

Remove the special-casing for OpenBSD.  It has been exporting function
prototypes conforming to POSIX.1-2008 since OpenBSD 5.3 and that was
released more than three years ago.

OS X 10.7 is now the only special case left.

Fixes: https://github.com/libuv/libuv/issues/1045
PR-URL: https://github.com/libuv/libuv/pull/1046
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2016-09-12 15:50:58 +02:00
Santiago Gimeno
0d7f72f219 fs: fix uv_fs_fstat on platforms using musl libc
In `musl` libc, defining `_GNU_SOURCE` doesn't automatically define the
other feature definitions, causing that `uv_fs_fstat` would not fill the
`nsec` fields. For the same reason, compile the tests on linux with
`-D_GNU_SOURCE` so the `fs_fstat` tests passes on `musl` platforms.

PR-URL: https://github.com/libuv/libuv/pull/1039
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2016-09-10 10:28:14 +02:00
John Barboza
afc93d1ed6 unix: unneccessary use const qualifier in container_of
The type parameter in the "container_of(ptr, type, member)" macro
which uses builtin "offsetof(type, member)" should not require cv
qualifier. Also note that for some platforms, the "offsetof" builtin
does not recognize the cv qualifier in the type.

PR-URL: https://github.com/libuv/libuv/pull/948
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2016-08-25 22:45:33 +01:00
John Barboza
9e641d251f zos: implement uv__io_check_fd
This method uses the poll syscall to determine whether POLLNVAL is
flagged or not.

PR-URL: https://github.com/libuv/libuv/pull/957
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2016-08-25 13:04:04 +01:00
John Barboza
f4ef897666 zos: track unbound handles and bind before listen
On zOS the listen call does not bind automatically if the socket
is unbound. Hence the manual binding to an arbitrary port is
required to be done manually.

PR-URL: https://github.com/libuv/libuv/pull/949
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2016-08-24 10:02:41 +01:00
John Barboza
404025721f zos: implement uv__fs_futime
We do this using __fchattr syscall to change file attributes.

PR-URL: https://github.com/libuv/libuv/pull/956
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2016-08-24 09:56:24 +01:00
John Barboza
841edfcd40 zos: use PLO instruction for atomic operations
Use builtins provided that perform compare and swap operations
using the PLO instruction.

PR-URL: https://github.com/libuv/libuv/pull/1008
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2016-08-24 09:47:57 +01:00
Jeffrey Clark
0a4b51fcb4 build: GNU/kFreeBSD support
autotools support only, gvp does not support kfreebsd detection.

PR-URL: https://github.com/libuv/libuv/pull/960
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2016-08-20 08:55:30 +02:00
John Barboza
1cff5b7557 zos: add support for new platform
- zos: disable test cases not applicable
- zos: build options
- zos: semaphore implementation
- zos: use compare and swap builtins
- zos: struct rusage not the same as other platforms
- zos: backlog<=0 produces undefined behaviour
    Will redefine backlog in the following way
    * if backlog == 0, set it to 1
    * if backlog < 0, set it to SOMAXCONN
- zos: define IMAXBEL as empty flag and implement uv__tty_make_raw
- zos: use udp multicast operations from aix
- zos: ESC in ebcdic
- zos: use LIBPATH for dynamic linker path
- zos: uv_udp_set_ttl only works for ipv6
- zos: increase pthread stack size by factor of 4
- zos: return ENODEV instead of ENXIO errors for setsockopt
- zos: use uv_cond_init the same way as aix
- test: enable oob test for zos
- zos: return EINVAL for zos error code EOPNOTSUPP

PR-URL: https://github.com/libuv/libuv/pull/937
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2016-08-19 01:34:29 +02:00
Saúl Ibarra Corretgé
d796bedf5b unix,win: make on_alloc_cb failures more resilient
Treat both the base being NULL or the length being 0 as ENOBUFS.

PR-URL: https://github.com/libuv/libuv/pull/997
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2016-08-17 09:57:55 +02:00
Ben Noordhuis
39ee4121a1 darwin: handle EINTR in /dev/tty workaround
On OS X, special files like /dev/null and /dev/tty don't work with
kqueue.  Libuv falls back to select() in that case but the initial
probe didn't handle EINTR.

Introduced in August 2012 in commit 731adaca ("unix: use select()
for specific fds on OS X"), this bug was only ten days away from
celebrating its fourth birthday.

PR-URL: https://github.com/libuv/libuv/pull/979
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2016-08-06 10:27:26 +02:00
Ben Noordhuis
ff0ae10496 unix: preserve loop->data across loop init/done
Libuv leaves loop->data unchanged in uv_loop_init() and uv_loop_done()
on Windows but it clobbered it on UNIX platforms.  This commit fixes
that inconsistency.

PR-URL: https://github.com/libuv/libuv/pull/951
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2016-07-30 10:49:19 +02:00
liuxiaobo
3a4f2d3155 unix: fix errno and retval conflict
We not only check the return value, but also check the errno != 0.
Because in rare cases connect() will return -1 but the errno
is 0 (for example, on Android 4.3, OnePlus phone A0001_12_150227)
and actually the tcp three-way handshake is completed.

PR-URL: https://github.com/libuv/libuv/pull/936
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Imran Iqbal <imran@imraniqbal.org>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2016-07-18 10:28:48 +01:00
cjihrig
840a8c599e unix,win: make uv_get_process_title() stricter
This commit causes uv_get_process_title() to:
 - return EINVAL if the buffer is null or size is 0
 - return ENOBUFS if the title is too big for the buffer
 - null terminate the buffer on success

Fixes: https://github.com/libuv/libuv/issues/315
PR-URL: https://github.com/libuv/libuv/pull/928
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2016-07-14 09:47:23 -04:00
Ben Noordhuis
70002c80bf linux: fix potential event loop stall
It was pointed out[0] that libuv could effectively enter an infinite
loop (but not a busy loop) under certain conditions when polling for
events:

1. When the architecture is 32 bits, and
2. When timeout > 0, i.e., finite, and
3. When timeout > max_safe_timeout (~30 minutes), and
4. When epoll_wait(timeout) returns 0, then
5. timeout was not properly updated on the next call to epoll_wait().

Inspection of the code uncovered a secondary bug where under a similar
set of circumstances the timeout could drift when the epoll_wait()
system call returned late.

[0] https://github.com/libuv/libuv/pull/354#discussion_r67837112

PR-URL: https://github.com/libuv/libuv/pull/922
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2016-07-04 19:10:12 +02:00
Ben Noordhuis
34ee25734f unix: don't convert stat buffer when syscall fails
Don't call uv__to_stat() when the stat/fstat/lstat system call fails;
the stack-allocated buffer contains only garbage in that case.

Not a very serious bug it's technically undefined behavior and it made
valgrind squawk.

Introduced in commit 499c7976 ("unix, windows: nanosecond resolution
for uv_fs_[fl]stat").

PR-URL: https://github.com/libuv/libuv/pull/921
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2016-06-22 17:49:28 +02:00
Brian Maher
d75e334e34 sunos: set phys_addr of interface_address using ARP
If getifaddrs() returns an all zero ifa_addr field, then use ARP to
set the phys_addr field of the uv_interface_address_t on the sunos
platform.

PR-URL: https://github.com/libuv/libuv/pull/907
Reviewed-By: Imran Iqbal <imran@imraniqbal.org>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2016-06-22 01:19:04 +02:00
Saúl Ibarra Corretgé
2fc54807fc unix: remove unneeded TODO note
It's already documented in
http://docs.libuv.org/en/v1.x/stream.html#c.uv_accept

PR-URL: https://github.com/libuv/libuv/pull/916
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Imran Iqbal <imran@imraniqbal.org>
2016-06-16 09:51:02 +02:00
Imran Iqbal
fcfe230130 unix,fs: use uint64_t instead of unsigned long
`unsigned long` is not guaranteed to be 8 bytes long. This prevents
overflow errors from occurring as seen in issue #913

Fixes: https://github.com/libuv/libuv/issues/913
PR-URL: https://github.com/libuv/libuv/pull/914
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2016-06-15 11:41:54 -04:00
Michael Neumann
96b37293a9 unix: correctly detect named pipes on DragonFly
This fixes test-stdio-over-pipes and test-pipe-sendmsg test cases.

~~~~
    Assertion failed in test/test-stdio-over-pipes.c on line 56: term_signal == 0
    Assertion failed in test/test-pipe-sendmsg.c on line 86: pending == UV_NAMED_PIPE
~~~~

This fixes a longstanding issue with nodejs on DragonFly, which was
triggered whenever spawning a process and pipes were involed.

PR-URL: https://github.com/libuv/libuv/pull/884
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Imran Iqbal <imran@imraniqbal.org>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2016-06-09 22:13:53 +02:00
Nicolas Cavallari
c4e917790e linux-core: fix uv_get_total/free_memory on uclibc
The _SC_PHYS_PAGES and _SC_AVPHYS_PAGES are not POSIX sysconf values, so
the standart C libraries have no obligation to support it, even on
Linux.  Use the Linux sysinfo() system call instead.

PR-URL: https://github.com/libuv/libuv/pull/901
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2016-06-09 22:05:45 +02:00
Saúl Ibarra Corretgé
193a6f9b93 unix: ignore EINPROGRESS in uv__close
It's just an indicator that the operation will happen later, so return
success.

PR-URL: https://github.com/libuv/libuv/pull/892
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2016-05-29 20:37:05 +02:00
Ben Noordhuis
c5c419f7c8 unix: allow nesting of kqueue fds in uv_poll_start
kqueue file descriptors don't support ioctl(FIONBIO) (or any other ioctl
for that matter) so retry using fcntl(F_GETFL) + fcntl(F_SETFL) when we
receive a ENOTTY error.

Fixes: https://github.com/libuv/libuv/issues/883
PR-URL: https://github.com/libuv/libuv/pull/885
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2016-05-24 17:12:31 +02:00
Saúl Ibarra Corretgé
c0fdc7102b darwin: fix setting fd to non-blocking in select(() trick
When the select trick is used fd is replaced with the fake fd (one end
of the socketpair) so we're not setting the original fd in non-blocking
mode.

Refs: https://github.com/nodejs/node/issues/6456#issuecomment-220018822
PR-URL: https://github.com/libuv/libuv/pull/879
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Fedor Indutny <fedor@indutny.com>
2016-05-24 13:59:50 +01:00
cjihrig
4fa89fbc61 unix: use system allocator for scandir()
On unix, scandir() uses the system allocator to allocate memory.
This commit releases the memory with free() instead of uv__free().
uv__free() is still used on Windows, which uses uv__malloc() to
request the memory.

Fixes: https://github.com/libuv/libuv/issues/873
PR-URL: https://github.com/libuv/libuv/pull/874
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2016-05-16 14:08:41 -04:00
Ben Noordhuis
28d160f3de darwin: make thread stack multiple of page size
pthread_attr_setstacksize() expects that the stack size is a multiple of
the page size so make sure that it is.

Fixes a regression introduced in commit 3db07cc ("osx: set the default
thread stack size to RLIMIT_STACK") that made the program abort under
certain configurations; GNU Emacs on OS X apparently sets RLIMIT_STACK
to odd values when executing child processes.

Fixes: https://github.com/nodejs/node/issues/6563
PR-URL: https://github.com/libuv/libuv/pull/864
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2016-05-10 18:19:46 +02:00
Ben Noordhuis
a8840fb347 darwin: work around condition variable kernel bug
It has been reported that destroying condition variables that have been
signalled but not waited on can sometimes result in application crashes.
See https://codereview.chromium.org/1323293005.

PR-URL: https://github.com/libuv/libuv/pull/860
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2016-05-06 22:26:22 +02:00
Kári Tristan Helgason
f57bfd4dca unix: fix bug in barrier fallback implementation
There was a memory corruption issue with the pthread barrier
implementation on android, where a barrier could still be in use by one
thread when being freed by another.

This fixes that issue and adds lots of missing error handling.

This implementation is now also used for the OSX fallback.

Fixes: https://github.com/libuv/libuv/issues/615
PR-URL: https://github.com/libuv/libuv/pull/790
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2016-04-26 09:35:47 +02:00
Myles Borins
f617ccc644 unix: error on realpath if PATH_MAX is undefined
Currently when PATH_MAX is undefined realpath will default to using 4096.
There is a potential stack overflow attack that can be mitigated by having
PATH_MAX defined. This change conservatively errors if a system does not
have PATH_MAX defined.

This change also explicitly includes `limits.h` to ensure that all platforms
have PATH_MAX defined if it is available.

Ref: http://pubs.opengroup.org/onlinepubs/9699919799/functions/realpath.html

Refs: https://github.com/nodejs/node/issues/2680#issuecomment-213521708
PR-URL: https://github.com/libuv/libuv/pull/843
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Fedor Indutny <fedor@indutny.com>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2016-04-26 09:22:47 +02:00
Ben Noordhuis
b9324acb75 unix: remove unneeded SAVE_ERRNO wrappers
uv__close() won't clobber errno so there is no need to guard calls with
a SAVE_ERRNO(...) wrapper.

PR-URL: https://github.com/libuv/libuv/pull/837
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2016-04-18 13:38:23 +02:00
Ben Noordhuis
322de63a9b unix: guard against clobbering errno in uv__free()
Libuv expects that free() does not clobber errno.  The system allocator
honors that assumption but custom allocators may not be so careful.

PR-URL: https://github.com/libuv/libuv/pull/837
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2016-04-18 13:38:04 +02:00
Oguz Bastemur
70d5014266 android: pthread_sigmask() does not set errno
Originally intended workaround is especially needed for Android <4.4.
However it fails to compare errno collected from pthread_sigmask.

This has been fixed separately in JXcore. See issue:
https://github.com/jxcore/jxcore-cordova/issues/55

PR-URL: https://github.com/libuv/libuv/pull/833
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2016-04-15 12:21:49 +02:00
Ben Noordhuis
4a5b3f982e unix: delay signal handling until after normal i/o
It was reported that some node.js tests fail on AIX because the exit
event sometimes comes before the final stdio output of a child process.

Work around that by deferring the signal watcher that is used for
process management until after the dispatch of regular i/o watchers.

Fixes: https://github.com/libuv/libuv/issues/610
PR-URL: https://github.com/libuv/libuv/pull/611
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2016-04-15 12:04:57 +02:00
Imran Iqbal
572d31599f unix,fs: code cleanup of uv_fs_event_start for AIX
Remove unused variables and code. Also remove some code duplication. End
result is code is cleaner, readable and easier to step through when
debugging.

PR-URL: https://github.com/libuv/libuv/pull/825
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2016-04-14 21:22:03 +02:00
Ben Noordhuis
60ef1e7f13 linux: fix long lines in linux-core.c
Introduced in commit 6798876a, "linux: fix cpu count".

PR-URL: https://github.com/libuv/libuv/pull/822
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2016-04-12 21:21:56 +02:00
Ben Noordhuis
732fb03ac6 linux: don't abort on malformed /proc/stat
Return an error instead of aborting when /proc/stat doesn't have the
expected format.

PR-URL: https://github.com/libuv/libuv/pull/822
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2016-04-12 21:21:55 +02:00
Ben Noordhuis
2bf7b3855c linux: fix fd leaks in uv_cpu_info() error paths
Introduced in commit 6798876a, "linux: fix cpu count".

PR-URL: https://github.com/libuv/libuv/pull/822
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2016-04-12 21:21:37 +02:00
Ben Noordhuis
375ba2d76d unix: use POLL{IN,OUT,etc} constants directly
Remove the UV__POLL defines and use POLL{IN,OUT,etc} directly.
On Linux, we lean on the fact that the POLL constants correspond
one-to-one to their EPOLL counterparts.

Fixes: https://github.com/libuv/libuv/issues/816
PR-URL: https://github.com/libuv/libuv/pull/817
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2016-04-11 10:51:13 +02:00
Imran Iqbal
4aeed1ac13 unix: implement uv__fs_futime for AIX 7.1
'futimens' is only implemented on AIX 7.1.  Other functions like
'utimes' and 'utimes' are merely stub functions that return ENOSYS
on AIX 6.1 and below.  Skip test fs_futime for AIX versions below 7.1.

PR-URL: https://github.com/libuv/libuv/pull/811
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2016-04-08 21:08:13 +02:00
Kári Tristan Helgason
7ed5d67133 unix: remove outdated comment
The comment removed by this commit is no longer relevant, as
the function's return type changed from int to void.

PR-URL: https://github.com/libuv/libuv/pull/804
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2016-04-04 23:42:10 -04:00
Enno Boland
387102b247 unix: open ttyname instead of /dev/tty
Find the real name of the tty using ttyname_r(3) instead of
opening "/dev/tty" which causes trouble if the fd doesn't point to the
controlling terminal.

PR-URL: https://github.com/libuv/libuv/pull/779
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2016-04-01 11:13:22 +02:00
Santiago Gimeno
643c9e9c32 process: close process pipes safely
Use `uv__close__nocheckstdio` instead of `close`.

PR-URL: https://github.com/libuv/libuv/pull/798
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2016-04-01 11:01:01 +02:00
Imran Iqbal
6ae622b0a1 aix: do not store absolute path to ahafs
We only need the absolute path to create our .mon file under /aha. So
only duplicate the passed string. This keeps behaviour similar to other
platforms.

Fixes test fs_event_getpath.

PR-URL: https://github.com/libuv/libuv/pull/776
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2016-04-01 10:53:27 +02:00
Imran Iqbal
a117fbd13b aix: fix ahafs implementation
uv__makedir_p was not processing all directories in passed string. Now
if a directory already exists (EEXIST) it simply moves onto the next
directory in the provided string.

Fixed bogus assert in uv__ahafs_event.

PR-URL: https://github.com/libuv/libuv/pull/776
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2016-04-01 10:52:01 +02:00
Santiago Gimeno
1c0281e3e2 process: fix uv_spawn edge-case
It can happen that the `parent` end of the `signal_pipe` is given a
STDIO file descriptor, so closing it using `uv__close` fails.

This problem is happening when running the `spawn_closed_process_io`
test in `SmartOS`. The reason being that when creating a socketpair in
`uv__process_init_stdio`, the `Illumos` implementation uses 3 sockets:
one is used as a listener, and the other 2 represent both ends of the
pipe. The listener socket is closed once the pipe is created. In the
test, the listener socket is assigned to the `0` fd, as it is the
first free fd in the system. So the fd `0` remained free after the call
to `socketpair`. Afterwards, when creating the `signal_pipe`, the fd `0`
is being assigned again, so closing it with `uv__close` made the test
fail. This issue is not happening in the other unixes because
`socketpair` doesn't use 3 fd's, but only 2.

To solve the issue, a new `uv__close__nocheckstdio()` function has been
added and used.

PR-URL: https://github.com/libuv/libuv/pull/796
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2016-03-31 11:53:42 +02:00
cjihrig
217f81b6a1 unix,win: add uv_get_passwd()
This commit adds the uv_get_passwd() function, which returns a
subset of the current effective user's password file entry.

Refs: https://github.com/libuv/libuv/issues/11
Fixes: https://github.com/libuv/libuv/issues/731
PR-URL: https://github.com/libuv/libuv/pull/742
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2016-03-29 08:13:59 -04:00
Ben Noordhuis
27aa81fe5a aix: fix 'POLLRDHUP undeclared' build error
AIX doesn't have POLLRDHUP.  Fixes the following compile-time error:

    src/unix/core.c: In function 'uv__io_start':
    src/unix/core.c:831:40: error: 'POLLRDHUP' undeclared
    assert(0 == (events & ~(UV__POLLIN | UV__POLLOUT | UV__POLLRDHUP)));

Fixes: https://github.com/libuv/libuv/issues/783
PR-URL: https://github.com/libuv/libuv/pull/785
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
2016-03-26 11:31:23 +01:00
Kári Tristan Helgason
02709a947f unix: use open(2) with O_CLOEXEC on OS X
PR-URL: https://github.com/libuv/libuv/pull/753
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2016-03-23 14:31:05 +01:00
Ben Noordhuis
b12624c136 unix: retry ioctl(TIOCGWINSZ) on EINTR
Some platforms (notably Solaris) can fail in this ioctl() if interrupted
by a signal.  Retry the system call when that happens.

Fixes: https://github.com/nodejs/node/issues/5737
PR-URL: https://github.com/libuv/libuv/pull/772
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2016-03-20 13:09:16 +01:00
Santiago Gimeno
c7c8e916b8 poll: add UV_DISCONNECT event
It allows detecting the remote socket closing the connection. It's
emitted when `EPOLLRDHUP`(Linux), `EV_EOF`(BSD), `POLLRDHUP`(Solaris,
AIX) and `AFD_POLL_DISCONNECT`(Windows) events are received.

PR-URL: https://github.com/libuv/libuv/pull/691
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Fedor Indutny <fedor@indutny.com>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2016-03-15 23:39:49 +01:00
Saúl Ibarra Corretgé
42ebae18d6 linux: fix error checking in uv__open_file
uv__open_cloexec returns either the fd or a libuv error, which is -errno
on Unix, not -1.

PR-URL: https://github.com/libuv/libuv/pull/760
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Fedor Indutny <fedor@indutny.com>
2016-03-10 16:26:11 +01:00
Krishnaraj Bhat
365bdec434 linux: remove redundant call to rewind()
It's already called in callee read_times()

PR-URL: https://github.com/libuv/libuv/pull/751
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2016-03-08 09:12:40 +01:00
Kári Tristan Helgason
2f02ae5f51 linux: replace calls to fopen with uv__open_file
PR-URL: https://github.com/libuv/libuv/pull/743
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2016-03-08 09:10:56 +01:00
Kári Tristan Helgason
d7910e42d0 unix: add fork-safe open file function
PR-URL: https://github.com/libuv/libuv/pull/743
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2016-03-08 09:10:26 +01:00
Kári Tristan Helgason
80d9d86e0f linux: add braces to multi-statement if
PR-URL: https://github.com/libuv/libuv/pull/750
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2016-03-05 00:30:25 +01:00
Robert Chiras
4c765d72a6 unix: fix compile error in Android using bionic
When compiling with bionic, st_atime_nsec (and the other nsec members)
canot be found.
In order to compile uv with both NDK and bionic, tv_nsec should be
accessed from st_atimensec (and the others nsec members).
See "Compatibility with glibc" in stat.h from bionic.

Signed-off-by: Robert Chiras <robert.chiras@intel.com>

PR-URL: https://github.com/libuv/libuv/pull/746
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2016-03-05 08:14:34 +01:00
Ben Noordhuis
bb77113042 linux: call fclose(), fix fdopen() memory leak
Commit 6798876 ("linux: fix cpu count") switched the /proc/stat parser
to fdopen().  Use fclose() to close the file descriptor to avoid leaking
resources associated with the FILE struct.

PR-URL: https://github.com/libuv/libuv/pull/747
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2016-03-04 00:55:46 +01:00
Imran Iqbal
a7009a0353 unix: fix uv__handle_type for AIX
'getsockname' does not handle UNIX domain sockets on AIX[1], it does not
fail but simply returns an empty structure with length 0.
If 'getsockname' does not fail (i.e. does not return -1) and the length
is 0 we know, on AIX, that the type is AF_UNIX.

This fixes test pipe_sendmsg.

[1] https://goo.gl/ozqcmS

PR-URL: https://github.com/libuv/libuv/pull/748
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2016-03-03 20:47:31 +01:00
Lukasz Jagiello
6798876a6b linux: fix cpu count
When libuv is running inside container - eg. lxc container, cpu number
is not obvious. Linux control groups (cgroups) may limit numer of cpus.

As a result of different number cpu cores inside container and
outside container, libuv is crashing.

sysconf(_SC_NPROCESSORS_ONLN) - returns num of host cpus (eg. 32)
`/proc/stat` - sees only cpus limited by cgroups (eg. 4)

When libuv is trying to operate at both numbers and they're different
it's crashing with current test:

run-tests: ../src/unix/linux-core.c:766: read_times: Assertion `num ==
numcpus' failed.

Count the number of cpus based on `/proc/stat` instead.

PR-URL: https://github.com/libuv/libuv/pull/735
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2016-03-03 09:34:30 +01:00
Saúl Ibarra Corretgé
2606ba22a7 unix, win: count null byte on UV_ENOBUFS
If an API function returns UV_ENOBUFS make sure we count the terminating
null, which we need space for. In case of success the null byte is not
included in the count, but the buffer *is* null terminated.

PR-URL: https://github.com/libuv/libuv/pull/690
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2016-03-03 09:23:10 +01:00
Saúl Ibarra Corretgé
e5f4b79809 unix, win: consistently null-terminate buffers
libuv has multiple functions which return buffers. Make them consistent
with the following rules: the returned size *does not* include the null
byte, but the buffer *is* null terminated.

There is only one exception to the above: Linux abstract sockets,
because null bytes are not used as string terminators in those.

Refs: https://github.com/libuv/libuv/pull/674
PR-URL: https://github.com/libuv/libuv/pull/690
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2016-03-03 09:20:41 +01:00
Saúl Ibarra Corretgé
a4213b7699 darwin: replace F_FULLFSYNC with fdatasync syscall
Refs: https://github.com/nodejs/node/pull/5402
PR-URL: https://github.com/libuv/libuv/pull/732
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2016-02-24 12:44:46 +01:00
Saúl Ibarra Corretgé
befe1550b9 linux: fix compilation with musl
PR-URL: https://github.com/libuv/libuv/pull/720
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2016-02-09 23:51:44 +01:00
Samuel Lorétan
7dc1bd9230 osx: protected use of potentially undefined macro
The `__FreeBSD__` macro is not defined by default on OSX, and building
with `-Wundef` will cause a warning to be emitted. This change makes
sure that the macro is only used if defined, removing the warning.

PR-URL: https://github.com/libuv/libuv/pull/710
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2016-02-05 22:49:49 +01:00
Ben Noordhuis
a0b56059cf unix: report errors for unpollable fds
Libuv would abort() when trying to watch a file descriptor that is
not compatible with epoll-style polling; file descriptors referring
to on-disk files fall into this category.

File descriptors that libuv creates itself are not an issue but
external ones that come in through the uv_poll_init() API are.

Make uv_poll_init() check whether the file descriptor is accepted by
the underlying system call and return an error when it's not.

Fixes: https://github.com/libuv/libuv/issues/658
PR-URL: https://github.com/libuv/libuv/pull/659
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2016-01-21 17:57:00 +01:00
Didiet
db680a1dff ios: fix undefined PTHREAD_STACK_MIN
PR-URL: https://github.com/libuv/libuv/pull/692
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2016-01-21 09:22:36 +01:00
cjihrig
c0fa2e7518 unix,win: add uv_os_tmpdir()
PR-URL: https://github.com/libuv/libuv/pull/672
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2016-01-21 09:11:56 +01:00
Saúl Ibarra Corretgé
f1a13e9b4a osx: avoid compilation warning with Clang
~~~~
src/unix/stream.c:1089:19: warning: variable length array folded to
constant array as an extension [-Wgnu-folding-constant]
  char cmsg_space[CMSG_SPACE(UV__CMSG_FD_SIZE)];
~~~~

PR-URL: https://github.com/libuv/libuv/pull/677
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2016-01-06 12:09:59 +01:00
Saúl Ibarra Corretgé
3db07cc379 osx: set the default thread stack size to RLIMIT_STACK
Fixes: https://github.com/libuv/libuv/issues/669
PR-URL: https://github.com/libuv/libuv/pull/671
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2016-01-05 09:06:15 +01:00
Dave
a564ef09dc fs: don't nullify req->bufs on EINTR
uv__fs_buf_iter currently sets req->bufs to NULL after it is done, but
if the operation fails with EINTR then it will be retried, at which
point it expects the bufs to not be NULL, causing a seg fault as in
https://github.com/nodejs/node/issues/4291.

uv__fs_buf_iter should not set req->bufs to NULL if the operation
fails with EINTR.

Also, when it sets req->bufs to NULL, it should set req->nbufs to 0 as
well, so we don't have the messy situation of a positive nbufs with no
actual bufs.

PR-URL: https://github.com/libuv/libuv/pull/661
Reviewed-By: Fedor Indutny <fedor@indutny.com>
2016-01-04 14:07:50 -05:00
Martin Bark
c861972140 unix: fix support for uClibc-ng
uClibc-ng is currently at v1.0.9.  The patch corrects the uClibc
version test so that HAVE_IFADDRS_H is defined for uClibc versions
after v0.9.32.

Signed-off-by: Martin Bark <martin@barkynet.com>

PR-URL: https://github.com/libuv/libuv/pull/653
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2015-12-16 12:11:56 +01:00
sztomi
b4126dd6db src: remove non ascii character
PR-URL: https://github.com/libuv/libuv/pull/651
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2015-12-13 11:52:49 +01:00
Andrey Mazo
46343764d5 unix: fix uv_fs_event_stop() from fs_event_cb
The following changeset
442b8a5a84 "unix: use QUEUE_MOVE when iterating over lists"
introduced a new assert failure:
`queue_foreach_delete` failed: exit code 6
Output from process `queue_foreach_delete`:
run-tests: src/unix/linux-inotify.c:244: uv_fs_event_stop: Assertion `w != ((void *)0)' failed.

Simplest test case for this:
1. create and start two uv_fs_event_t for the same path;
2. in the callback for the first one, call uv_close() on it;
3. assert/segfault while accessing the second uv_fs_event_t from uv__inotify_read().

PR-URL: https://github.com/libuv/libuv/pull/621
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2015-12-08 10:03:01 +01:00
Yuval Brik
e76b8838e5 fs: add uv_fs_realpath()
Equivalent to realpath(3), returns the full resolved absolute path of a
file or directory.

PR-URL: https://github.com/libuv/libuv/pull/531
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2015-12-05 11:32:58 +01:00
Saúl Ibarra Corretgé
176fdc7352 linux,fs: fix p{read,write}v with a 64bit offset
According to [0] we need to pass it in 2 32bit registers on some
platforms such as MIPS. Fix inspired by the musl libc implementation [1].

[0]: http://man7.org/linux/man-pages/man2/syscall.2.html#NOTES
[1]: http://git.musl-libc.org/cgit/musl/tree/src/unistd/preadv.c

Fixes: https://github.com/libuv/libuv/issues/473
Refs: https://github.com/libuv/libuv/pull/498
Refs: https://github.com/libuv/libuv/pull/627
PR-URL: https://github.com/libuv/libuv/pull/638
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2015-12-03 08:50:28 +01:00
Fedor Indutny
0761bfe6a3 fsevents: fix race on simultaneous init+close
When `uv_fsevents_t` handle is closed immediately after initializing,
there is a possibility that the `CFRunLoop`'s thread will process both
of these events at the same time. `uv__is_active(handle)` will return
`0`, and the `uv_close()` semaphore will be unblocked, leading
to the use after free in node.js.

See: https://github.com/nodejs/node/issues/4091
PR-URL: https://github.com/libuv/libuv/pull/637
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2015-12-02 19:01:28 -05:00
kkdaemon
43994b4e3c android: support api level less than 21
Remove restriction to Android API level >= 21, now libuv can be used with
Android API level at least 14.

Direct use of getpwuid_r function resulted in linker errors in applications
were built against API level below 21. That function was 'officially'
introduced in Android API level 21, but it exists in libc beginning from API
level at least 14.

So try to get a pointer to getpwuid_r at runtime using dlsym when building
libuv with API level < 21.

PR-URL: https://github.com/libuv/libuv/pull/633
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2015-12-02 09:49:21 +01:00
Ben Noordhuis
9bbc1137ee unix: don't retry dup2/dup3 on EINTR
Like the previous commit, but this time for UNIX platforms other than
Linux.

As far as I have been able to establish, dup2 and dup3 never return
EINTR on OS X and FreeBSD.  Even if other platforms do return EINTR,
it's probably still better not to retry because it's unspecified
whether the file descriptor has been closed.

Fixes: https://github.com/libuv/libuv/issues/462
PR-URL: https://github.com/libuv/libuv/pull/608
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2015-11-17 10:48:00 +01:00
Ben Noordhuis
af7a3614d0 linux: don't retry dup2/dup3 on EINTR
Retrying seems like a bad idea in a multi-threaded program because the
man page leaves it unspecified whether the file descriptor is closed
after EINTR.

It's probably an academic issue because as far as I have been able to
establish by checking the kernel sources, dup2 and dup3 never actually
return EINTR.  For dup3, this appears to have been the case since its
introduction in v2.6.27; for dup2, it goes back to at least v2.6.18.

Fixes: https://github.com/libuv/libuv/issues/462
PR-URL: https://github.com/libuv/libuv/pull/608
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2015-11-17 10:47:31 +01:00
Ian Kronquist
81072b98f5 misc: remove unnecessary null pointer checks
Fixes: https://github.com/libuv/libuv/issues/595
PR-URL: https://github.com/libuv/libuv/pull/604
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2015-11-17 09:18:55 +01:00
Ben Noordhuis
a6da5d7d65 darwin: abort() if (un)locking fs mutex fails
The pthread_mutex_lock() and pthread_mutex_unlock() calls logically
cannot fail in uv__fs_write() but let's check the return value anyway:
cosmic rays and memory corruption do happen.

PR-URL: https://github.com/libuv/libuv/pull/603
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2015-11-05 13:28:13 +01:00
Nathan Corvino
bda29cf808 unix: skip prohibited syscalls on tvOS and watchOS
fork and the exec functions are marked prohibited on tvOS and watchOS,
so referencing them causes compile errors.

This adds preprocessor conditionals to avoid calling them for those
targets.

PR-URL: https://github.com/libuv/libuv/pull/580
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2015-10-21 00:40:33 +02:00
Adam Stylinski
ef47e8b212 unix: make work with Solaris Studio.
The atomics that are in place of a lack of x86 cmpxchg are a GCC
specific intrinsic.  When compiling for Solaris on a SPARC platform
with a non-gcc compiler, this prevents a successful build.  This commit
will rely on a Solaris Studio specific preprocessor macro to redefine
the GCC intrinsic name to be the Solaris Studio one instead.

PR-URL: https://github.com/libuv/libuv/pull/569
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2015-10-13 18:07:28 +02:00
HungMingWu
9fbcca0481 unix: fix uv__getiovmax return value
On some embedded devices (arm-linux-uclibc based ip camera),
sysconf(_SC_IOV_MAX) can not get the correct value. The return
value is -1 and the errno is EINPROGRESS. Degrade the value to 1.

PR-URL: https://github.com/libuv/libuv/pull/573
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2015-10-13 17:49:41 +02:00
Ben Noordhuis
bf52579f92 unix: only undo fs req registration in async mode
Commit 0199955 ("fs: undo uv__req_init when uv__malloc failed")
mistakingly unregisters the requests unconditionally in a few places,
resulting in memory corruption when it hasn't been registered first.

Fixes: https://github.com/libuv/libuv/pull/543
PR-URL: https://github.com/libuv/libuv/pull/567
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2015-10-09 21:35:13 +02:00
Ben Noordhuis
1457496452 unix: squelch harmless valgrind warning
Valgrind complains that the msg_control pointer points to uninitialized
memory.  While the memory is only used for writing data to, not for
reading data from, and the warning is therefore bogus, it's still
annoying enough that I decided to squelch it by zeroing the memory.

The performance implications should be minimal because this code path
is only used when sending over a handle to another process.

The warning:

    ==14859== Syscall param sendmsg(msg.msg_control) points to
    uninitialised byte(s)
      ==14859==    at 0x5AF1A80: __sendmsg_nocancel (in
          /usr/lib64/libpthread-2.21.so)
      ==14859==    by 0x46350E: uv__write (stream.c:810)
      ==14859==    by 0x464B24: uv_write2 (stream.c:1398)
      ==14859==    by 0x421ACE: run_test (test-ipc-send-recv.c:104)
      ==14859==    by 0x421DD1: run_test_ipc_send_recv_tcp
      (test-ipc-send-recv.c:156)
      ==14859==    by 0x406D2F: run_test_part (runner.c:404)
      ==14859==    by 0x4058CD: main (run-tests.c:58)
      ==14859==  Address 0xffefff934 is on thread 1's stack
      ==14859==  in frame #1, created by uv__write (stream.c:742)

PR-URL: https://github.com/libuv/libuv/pull/565
Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2015-10-08 21:47:45 +02:00
Ben Noordhuis
442b8a5a84 unix: use QUEUE_MOVE when iterating over lists
Replace uses of QUEUE_FOREACH when the list can get modified while
iterating over it, in particular when a callback is made into the
user's code.  This should fix a number of spurious failures that
people have been reporting.

PR-URL: https://github.com/libuv/libuv/pull/565
Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2015-10-08 21:47:43 +02:00
Ben Noordhuis
1867a6c1ce src: replace QUEUE_SPLIT with QUEUE_MOVE
All uses of QUEUE_SPLIT in libuv split the list at the head so introduce
a QUEUE_MOVE macro that automates that.

PR-URL: https://github.com/libuv/libuv/pull/565
Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2015-10-08 21:46:48 +02:00
Jianghua Yang
26917ddf7a unix: fix request handle leak in uv__udp_send
PR-URL: https://github.com/libuv/libuv/pull/561
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2015-10-07 15:12:26 +02:00
Fedor Indutny
5e761a5f81 stream: support empty uv_try_write on unix
PR-URL: https://github.com/libuv/libuv/pull/558
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2015-10-04 18:06:08 -04:00
Jianghua Yang
01999559cf fs: undo uv__req_init when uv__malloc failed
PR-URL: https://github.com/libuv/libuv/pull/543
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2015-09-24 09:48:43 +02:00
Gireesh Punathil
25506bb331 unix: make uv_guess_handle work properly for AIX
On AIX, the getsockname API does not operate on the UNIX domain sockets
Please see: https://www-01.ibm.com/support/knowledgecenter/ssw_aix_61/
com.ibm.aix.commtrf2/getsockname.htm

This means that the internal helper routine uv_guess_handle in tty.c
fails in AIX, for common use cases.

There is no direct API support which helps identifying a UNIX domain
socket in AIX. getpeername() retrieves the information pertinent to
connected UNIX domain socket pairs, and using getpeername where
getsockname fails was a good workaround. However, there are edge cases
where one end of a socketpair comes for introspection while the other
end has been closed, which causes getpeername to fail.

A better solution is derived based on these facts:

1.getsockname() on a broken / un-broken socketpair does not actually
fail with -1, instead it returns 0. However, the API does not modify
the socketaddr structure passed to it, with the socket information.

2.This behavior of getsockname is observed only for UNIX domain socket,
among all possible types of sockets which I tested - ~30 of them.

So a practical and stable workaround for AIX is to return
UV_UNKNOWN_HANDLE if getsockname fails.  If it passes and the length
of the structure returned is 0 then we know that the type is AF_UNIX
and return UV_NAMED_PIPE , otherwise we inspect in the same way as for
other platforms to derive the type.

PR-URL: https://github.com/libuv/libuv/pull/539
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2015-09-23 16:09:07 +02:00
Jianghua Yang
25c369d4cf unix: fix memory leak in uv_interface_addresses
PR-URL: https://github.com/libuv/libuv/pull/537
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2015-09-23 08:16:20 +02:00
Jianghua Yang
9c307cc630 darwin: fix memory leak in uv_cpu_info
PR-URL: https://github.com/libuv/libuv/pull/538
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2015-09-22 12:11:45 +02:00
Saúl Ibarra Corretgé
bd1777fd53 unix, win: consolidate mutex trylock errors
Fold EAGAIN into EBUSY, and make it the only acceptable error.

PR-URL: https://github.com/libuv/libuv/pull/535
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2015-09-22 00:08:05 +02:00
Saúl Ibarra Corretgé
85adf43e03 unix: consolidate rwlock tryrdlock trywrlock errors
Fold EAGAIN and EBUSY into EBUSY. This makes it consistent across all
Unix platforms and Windows.

Refs: https://github.com/libuv/libuv/pull/525
PR-URL: https://github.com/libuv/libuv/pull/535
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2015-09-22 00:07:28 +02:00
nmushell
cf0e5b4db2 unix: Support atomic compare & swap xlC on AIX
On AIX with the native xlC compiler, the compiler supports sync
compare swap and compare in two flavors:
 1 __compare_and_swap
 2 __compare_and_swaplp

This differs from the gcc version of this function in name. The
second version of this function supports 8-byte boundary for
a doubleword. Therefore, the macro logic checks:
 if (AIX OS AND using xlC compiler)
    if (64bit)
       __compare_and_swaplp /* 64 bit version */
    else
       __compare_and_swap
    endif
 endif

Signed-off-by: Neil Mushell <nmushell@bloomberg.net>

PR-URL: https://github.com/libuv/libuv/pull/521
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2015-09-11 18:00:33 +02:00
Ben Noordhuis
e95960cc68 unix: fix error check when closing process pipe fd
uv__close() does not set errno, it returns the error.  It also never
returns EINTR, it always maps it to EINPROGRESS.

PR-URL: https://github.com/libuv/libuv/pull/512
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2015-09-07 13:33:27 +02:00
Michael Neumann
8b90faff6c fs: fix bug in sendfile for DragonFly
The code made an implicit assumption that the 'len` variable passed
to the sendfile(2) syscall is not modified by the operating system
in case of an error other than EAGAIN or EINTR.

The man page leaves this unspecified on FreeBSD, DragonFly and
Darwin, so better check the error code which returns a valid
value in `len` explicitly (only EAGAIN and EINTR).

This fixes the test case for sendfile on DragonFly.

PR-URL: https://github.com/libuv/libuv/pull/466
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2015-09-01 09:22:43 +02:00
Jianghua Yang
030b6e1a40 freebsd: obtain true uptime through clock_gettime()
Obtain true uptime through clock_gettime() instead of subtracting
'bootime' from 'now'.

PR-URL: https://github.com/libuv/libuv/pull/497
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2015-08-31 10:05:48 +02:00
Willem Thiart
2a51b61e46 unix, win: make uv_loop_init return on error
Makes uv_loop_init return an error code instead of aborting.

Currently uv_loop_init aborts if there are insufficient resources
available. As a user I want to be able to check the return code from
uv_loop_init and decide how I respond rather than having my process die.

PR-URL: https://github.com/libuv/libuv/pull/405
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2015-08-20 17:39:21 +02:00
Brian White
406961385d stream: retry write on EPROTOTYPE on OSX
At least on OS X 10.10 "Yosemite", an EPROTOTYPE can occur
when trying to write to a socket that is shutting down.
By retrying the write after EPROTOTYPE, we correctly get EPIPE.

PR-URL: https://github.com/libuv/libuv/pull/482
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2015-08-19 09:25:41 +02:00
Ben Noordhuis
df62b54aa2 unix,windows: allow NULL loop for sync fs requests
Synchronous file operations don't need an event loop.  Permit NULL as
the event loop parameter.

Fixes: https://github.com/libuv/libuv/issues/469
PR-URL: https://github.com/libuv/libuv/pull/479
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2015-08-18 15:39:21 +02:00
Ben Noordhuis
e19764f75a unix: don't copy arguments for sync fs requests
For synchronous file operation requests (ones without a callback), there
is no need to make a copy of the arguments because they don't outlive
the scope of the function call.

PR-URL: https://github.com/libuv/libuv/pull/479
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2015-08-18 15:39:16 +02:00
Ben Noordhuis
3ed7fcee5b unix: remove superfluous parentheses in fs macros
The parentheses are unnecessary because what they wrap are not macro
arguments but function arguments that aren't evaluated by the macro.

PR-URL: https://github.com/libuv/libuv/pull/479
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2015-08-18 15:38:42 +02:00
Karl Skomski
939ea06f45 unix,win: return EINVAL on nullptr args in uv_fs_{read,write}
PR-URL: https://github.com/libuv/libuv/pull/470
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2015-08-11 13:35:54 +02:00
Zachary Hamm
3869f2a8c0 unix: OpenBSD's setsockopt needs an unsigned char for multicast
PR-URL: https://github.com/libuv/libuv/pull/477
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2015-08-10 09:27:53 +02:00
Saúl Ibarra Corretgé
01544d861b Revert "stream: squelch ECONNRESET error if already closed"
This reverts commit 05a003a3f7.

This commit triggerd "test-tls-hello-parser-failure" failure in io.js.
See the reference below for a more thorough explanation.

Refs: https://github.com/nodejs/io.js/pull/2310
PR-URL: https://github.com/libuv/libuv/pull/475
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2015-08-07 14:19:08 +02:00
ronkorving
2bf782777f unix: allow nbufs > IOV_MAX in uv_fs_{read,write}
This allows writing and reading any amount of buffers,
regardless of what IOV_MAX may be defined as.

It also moves the IOV_MAX test from stream to core.

This is based on the excellent work of @bwijen in #269.

Refs: https://github.com/libuv/libuv/pull/269
PR-URL: https://github.com/libuv/libuv/pull/448
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2015-08-04 11:31:04 +02:00
Richard Lau
ab9776098e aix: fix uv_exepath with relative paths
uv_exepath() was not behaving correctly on AIX when the process was
invoked with a relative path.

The logic has been reworked to:

1) Use getargs() to retrieve the process arguments
2) Use realpath() to handle absolute and relative paths and
   symbolic links
3) Check that a match when searching the PATH is executable (if
   not search will continue)

PR-URL: https://github.com/libuv/libuv/pull/464
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2015-07-30 23:31:36 +02:00
RossBencina
3b0f85fd23 android: add missing include to pthread-fixes.c
PR-URL: https://github.com/libuv/libuv/pull/436
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2015-07-15 10:18:52 +02:00
Santiago Gimeno
05a003a3f7 stream: squelch ECONNRESET error if already closed
Add new UV__POLLRDHUP event to be emitted when EPOLLRDHUP(in Linux) or
EV_EOF(in BSD / OSX) is detected and only if UV_READABLE is set.

When a read returns ECONNRESET after a UV__POLLRDHUP event, emit EOF instead
of the error.

Add tcp-squelch-connreset test. Not to be run on Windows as it returns
ECONNRESET error.

Fixes in test-poll and test-tcp-open so they pass after these changes.

PR-URL: https://github.com/libuv/libuv/pull/403
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2015-07-10 09:25:01 +02:00
Saúl Ibarra Corretgé
7980f1359d darwin: save a fd when FSEvents is used
Refs: https://github.com/libuv/libuv/issues/387
PR-URL: https://github.com/libuv/libuv/pull/413
Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com>
2015-06-30 12:15:41 +02:00
Saúl Ibarra Corretgé
60fca01705 tty: cleanup handle if uv_tty_init fails
Once we are past uv__stream_init, the handle has been added to
loop->handle_queue, it needs to be undone in case of failure.

PR-URL: https://github.com/libuv/libuv/pull/414
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2015-06-30 01:25:53 +02:00
Saúl Ibarra Corretgé
d377435b5e unix: consolidate tcp and udp bind error
OSX, other BSDs and SunoS fail with EAFNOSUPPORT when binding a socket created
with AF_INET to an AF_INET6 address or vice versa.

PR-URL: https://github.com/libuv/libuv/pull/407
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2015-06-28 11:53:52 +02:00
Saúl Ibarra Corretgé
f8f59824c4 unix, win: add ability to create tcp/udp sockets early
Introduce two new APIs:

int uv_tcp_init_ex(uv_loop_t*, uv_tcp_t* handle, int flags)
int uv_udp_init_ex(uv_loop_t*, uv_udp_t* handle, int flags)

The lower 8 bits of the flags field are used for the socket domain.
AF_INET, AF_INET6 and AF_UNSPEC are supported. If AF_UNSPEC is specified
the socket is created lazily, just like uv_{tcp,udp}_init.

Some Windows notes:

getsockname fails with WSAEINVAL if the socket is not bound. This could
potentially be improved by detecting the socket family and filling
the sockaddr_in/6 struct manually.

bind returns WSAEFAULT if we try to bind a socket to the wrong family.
Unix returns EINVAL.

PR-URL: https://github.com/libuv/libuv/pull/400
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2015-06-19 09:37:19 +02:00
Saúl Ibarra Corretgé
fb5df542ac unix, win: prevent replacing fd in uv_{udp,tcp,pipe}_t
PR-URL: https://github.com/libuv/libuv/pull/400
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2015-06-19 09:36:41 +02:00
Michael Neumann
c8eebc93a9 dragonflybsd: fix uv_exepath
This fixes a bug I have noticed with nodejs:

> cat test.js
  console.log(process.execPath);

> node test.js (on DragonFly)
  node test.js

> node test.js (on Linux)
  node

PR-URL: https://github.com/libuv/libuv/pull/399
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2015-06-16 22:54:33 +02:00
Michael Neumann
db8c812a3d dragonflybsd: use sendfile(2) for uv_fs_sendfile
PR-URL: https://github.com/libuv/libuv/pull/399
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2015-06-16 22:54:33 +02:00
Michael Neumann
94ba71b9eb dragonflybsd: fixes for nonblocking and cloexec
Use the same code path as FreeBSD does.

PR-URL: https://github.com/libuv/libuv/pull/399
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2015-06-16 22:54:27 +02:00
cjihrig
d82e47a60f unix: handle invalid _SC_GETPW_R_SIZE_MAX values
Some systems, FreeBSD for example, may return negative values.
sysconf() returns a long, which was being converted to a size_t.
This conversion lead to large allocations, and subsequent out of
memory failures. This commit checks the long value returned by
sysconf() properly, and uses a default value of 4096 if a negative
number is returned.

PR-URL: https://github.com/libuv/libuv/pull/389
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2015-06-05 19:44:31 +02:00
Saúl Ibarra Corretgé
bddd6a8489 core: add ability to customize memory allocator
This patch is composed by the work done in
https://github.com/libuv/libuv/pull/231 and
https://github.com/libuv/libuv/pull/287 plus some changes by yours
truly.

Thanks @beevik and @mattsta for their work on this!

PR-URL: https://github.com/libuv/libuv/pull/368
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2015-06-02 12:05:20 +02:00
Andrew Paprocki
bb2632b339 aix: add ahafs autoconf detection and README notes
The libuv filesystem events API on AIX requires the non-default IBM
`bos.ahafs` package to be installed.  The library should still compile
and work on systems without this package.  This patch adds proper
detection to `configure.ac` and makes the API return `-ENOSYS` at
runtime if the system does not support it.

PR-URL: https://github.com/libuv/libuv/pull/372
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2015-05-28 11:16:00 +02:00
Saúl Ibarra Corretgé
1816dbc85f unix: make sure UDP send callbacks are asynchronous
Fixes: https://github.com/libuv/libuv/issues/301
PR-URL: https://github.com/libuv/libuv/pull/371
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2015-05-28 11:05:45 +02:00
Saúl Ibarra Corretgé
3ceb260c65 unix: prevent infinite loop in uv__run_pending
If any of the callbacks called in uv__run_pending calls
uv__io_feed we enter an infinite loop, because we add the handle to the
same queue we are iterating over.

Refs: https://github.com/libuv/libuv/issues/301
PR-URL: https://github.com/libuv/libuv/pull/371
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2015-05-28 11:05:30 +02:00
Fedor Indutny
7005d29514 stream: fix select() race condition
Call `uv__read()`/`uv__write()` before re-entering `select` thread.
Otherwise we might get second event from it, and will block indefinitely
on `uv__read()`/`uv__write()`.

Fix: https://github.com/libuv/libuv/issues/304
PR-URL: https://github.com/libuv/libuv/pull/365
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2015-05-25 23:18:07 +02:00
cjihrig
a62c2d5928 unix,win: add uv_os_homedir()
PR-URL: https://github.com/libuv/libuv/pull/350
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2015-05-21 17:31:35 +02:00
Ben Noordhuis
d1b5008e76 linux: work around epoll bug in kernels < 2.6.37
Old 32 bits kernels (native and compat) have a bug where timeouts larger
than (LONG_MAX / CONFIG_HZ) milliseconds are treated as infinite.

Work around that by capping the timeout and polling again if necessary.

PR-URL: https://github.com/libuv/libuv/pull/354
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2015-05-19 12:28:53 +02:00
Saúl Ibarra Corretgé
a6fa3ca99a unix: don't block for io if any io handle is primed
PR-URL: https://github.com/libuv/libuv/pull/347
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2015-05-12 07:37:26 +02:00
Michael Dawson
05ef2980ee aix: fix setsockopt for multicast options
On AIX the length of socket options
for multicast and ttl options is not always sizeof(char).

AIX has the same issue as solaris which was fixed under
PR-URL: https://github.com/libuv/libuv/pull/243

This PR extends the fix to cover AIX as well.

PR-URL: https://github.com/libuv/libuv/pull/345
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2015-05-07 20:14:20 +02:00
farblue68
ee9c7bac8d aix: fix uv_interface_addresses return value
Make it consistent with other platforms.

PR-URL: https://github.com/libuv/libuv/pull/303
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2015-05-05 10:30:48 +02:00
Keno Fischer
af0d09bddc linux: intercept syscall when running under memory sanitizer
Since libuv has it's own syscall wrappers, the standard libc interception
mechanism of the sanitizers do not catch these, leading to false positives
for projects using libuv when running under memory sanitizer.

Fix this by adding the appropriate calls to unpoison manually.

PR-URL: https://github.com/libuv/libuv/pull/311
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2015-05-05 10:26:20 +02:00
Ben Noordhuis
202195c2f4 unix: clean up uv_fs_open() O_CLOEXEC logic
Move the logic out of uv__fs_work() and into a function of its own.

PR-URL: https://github.com/libuv/libuv/pull/326
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2015-04-29 15:10:08 +02:00
Saúl Ibarra Corretgé
1f711e4d6d Revert "memory: add uv_replace_allocator"
This reverts commit c272f1f1bc.

The concept will come back to libuv, but it needs some more work.
2015-04-29 09:37:02 +02:00
Alan Rogers
8fac49d0fc unix: open "/dev/null" instead of "/" for emfile_fd
We may not have permission to open "/". This fix allows libuv to be
used in a OS X app that has sandboxing enabled, without the need for
a temporary entitlement to allow reading of "/" (Which would never
pass app review).

In some rare cases "/dev" isn't mounted, so we open "/" as a
fallback.

PR-URL: https://github.com/libuv/libuv/pull/328
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2015-04-24 09:38:19 +02:00
Saúl Ibarra Corretgé
09cdc923c2 unix: fix potential bug if dup2 fails in uv_spawn
PR-URL: https://github.com/libuv/libuv/pull/309
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2015-04-10 15:27:04 +02:00
Saúl Ibarra Corretgé
009bbad4e7 unix: fix swapping fds order in uv_spawn
Alternative implementation (and test) to
https://github.com/libuv/libuv/pull/226

Fixes: https://github.com/joyent/libuv/issues/1084
PR-URL: https://github.com/libuv/libuv/pull/309
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2015-04-10 15:27:04 +02:00
Sam Roberts
55cc5bac1b unix: don't close the fds we just setup
If a descriptor was being copied to an fd that *was not its current
value*, it should get closed after being copied. But the existing code
would close the fd, even when it no longer referred to the original
descriptor. Don't do this, only close fds that are not in the desired
range for the child process.

See https://github.com/iojs/io.js/issues/862

PR-URL: https://github.com/libuv/libuv/pull/309
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2015-04-10 15:10:02 +02:00
Saúl Ibarra Corretgé
a7e7bafcc3 android: fix compilation warning
PR-URL: https://github.com/libuv/libuv/pull/285
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2015-04-10 11:32:40 +02:00
Ben Noordhuis
1d8332f7e6 linux: fix epoll_pwait() fallback on arm64
arm64 doesn't have a epoll_wait() system call but a logic error stopped
libuv from falling back to epoll_pwait().

This bug was introduced in commit 67bb2b5 ("linux: fix epoll_pwait()
regression with < 2.6.19") which sadly exchanged one regression for
another.

PR-URL: https://github.com/libuv/libuv/pull/308
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2015-04-07 15:07:28 +02:00
Ryan Phillips
3616e61439 unix: reap child on execvp() failure
Reap the forked process when execvp() fails.  Fixes leaking zombie child
processes.

PR-URL: https://github.com/libuv/libuv/pull/274
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2015-03-18 17:11:39 +01:00
Ben Noordhuis
fc9e66e555 unix: reject non-tty fds in uv_tty_init()
Reject file descriptors that correspond to regular files or char/block
devices.  Such file descriptors are incompatible with epoll and trigger
a run-time assert.

Fixes: https://github.com/libuv/libuv/issues/255
PR-URL: https://github.com/libuv/libuv/pull/259
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2015-03-11 16:45:51 +01:00
Ben Noordhuis
1df46fe478 unix: don't clobber errno in uv_tty_reset_mode()
uv_tty_reset_mode() is designed to be async signal-safe and is therefore
not allowed to clobber errno.

PR-URL: https://github.com/libuv/libuv/pull/259
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2015-03-11 16:45:50 +01:00
Julien Gilli
b27a55c3cc solaris: fix setsockopt for multicast options
On Solaris and derivatives such as SmartOS, the length of socket options
for multicast and ttl options is not always sizeof(char).

This fixes the udp_options and udp_options6 tests.

PR-URL: https://github.com/libuv/libuv/pull/243
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2015-03-11 09:02:31 +01:00
Saúl Ibarra Corretgé
ae6b590fef unix: fix compilation on Android
Thanks @julien33 for the patch.

Fixes: https://github.com/libuv/libuv/issues/252
PR-URL: https://github.com/libuv/libuv/pull/253
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2015-03-10 13:43:42 +01:00
Ole André Vadla Ravnås
d557ad73e0 darwin: fix size calculation in select() fallback
Apple's `fd_set` stores its bits in an array of 32-bit integers, which
means `FD_ISSET()` may read out of bounds if we allocate storage at
byte granularity. There's also a chance that the `select()` call could
corrupt the heap, although I didn't investigate that.

This issue was discovered by LLVM's AddressSanitizer which caught
`FD_ISSET()` trying to read out of bounds.

PR-URL: https://github.com/libuv/libuv/pull/241
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Fedor Indutny <fedor@indutny.com>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2015-03-05 21:05:00 +01:00
Brett Vickers
c272f1f1bc memory: add uv_replace_allocator
With uv_replace_allocator, it's possible to override the default
memory allocator's malloc and free calls with functions of the user's
choosing. This allows libuv to interoperate with projects requiring a
custom memory allocator.

Internally, all calls to malloc and free have been replaced with
uv__malloc and uv__free, respectively. The uv__malloc and uv__free
functions call malloc and free unless they have been overridden by a
previous call to uv_replace_allocator.

As part of this change, the special aligned memory allocations
performed in src/win/fs-event.c have been replaced with standard
allocations. The 4-byte alignment being requested in this file was
unnecessary, since standard allocators already guarantee at least an
8-byte alignment.

PR-URL: https://github.com/libuv/libuv/pull/231
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2015-03-05 20:02:16 +01:00
Ben Noordhuis
5645b2d69f linux: work around epoll bug in kernels 3.10-3.19
Work around a bug in kernels 3.10 to 3.19 where passing a struct that
has the EPOLLWAKEUP flag set generates spurious syslog audit warnings.

A bad check makes the kernel read the events field when it should not
and complain when the process lacks the CAP_BLOCK_SUSPEND capability.

PR-URL: https://github.com/libuv/libuv/pull/245
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2015-03-05 19:43:43 +01:00
Massimiliano Torromeo
fd3cf20a37 unix: fix glibc-2.20+ macro incompatibility
Since glibc-2.20 the _SVID_SOURCE macro is deprecated and the newer
_DEFAULT_SOURCE macro should be used instead.

Fixes: https://github.com/libuv/libuv/issues/173
PR-URL: https://github.com/libuv/libuv/pull/213
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2015-02-26 21:08:07 +01:00
Michael
57c4342e4f aix: always deregister closing fds from epoll
In debugging test-tls-ocsp-callback.js for the 0.12.0 Node on
AIX we discovered that there was code missing in
uv__platform_invalidate_fd() in aix.c which removes the file
descriptor from the pollset when needed.  We based the
impelementation in aix.c on the unix version in linux-core.cc.
We can see that this issue was addressed for linux in commit
780d8ad.

PR-URL: https://github.com/libuv/libuv/pull/221
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2015-02-26 11:39:51 +01:00
Fedor Indutny
19d3d506de stream: ignore EINVAL for SO_OOBINLINE on OS X
Calling `setsockopt()` on shutdown fds/stdio will result in EINVAL.
There is not much problem here as the OOB data can't be sent to already
shutdown fds. Just ignore it and go on.

PR-URL: https://github.com/libuv/libuv/pull/228
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Bert Belder <bertbelder@gmail.com>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2015-02-26 11:18:15 +01:00
Fedor Indutny
e19089f7b1 stream: use SO_OOBINLINE on OS X
In the collaboration with Ben Noordhuis <info@bnoordhuis.nl> and
Saúl Ibarra Corretgé <saghul@gmail.com>.

Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2015-02-24 22:34:01 +03:00
Michael Penick
4ed237278c unix: fix for uv_async data race
There's a data race in the consuming side of uv_async. The "pending"
flag could be trampled by producing thread causing an async send
event to be missed.

PR-URL: https://github.com/libuv/libuv/pull/189
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2015-02-18 21:44:37 +01:00
Julien Gilli
672b204799 tty: fix build for SmartOS
On Solaris derivatives, cfmakeraw is not available. Instead, set the
termios flags manually. The set of flags to use so that the behavior of
the terminal is similar to what it is after a call to cfmakeraw was
taken from
http://www.perkin.org.uk/posts/solaris-portability-cfmakeraw.html.

PR-URL: https://github.com/libuv/libuv/pull/210
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2015-02-19 09:49:12 +01:00
Ben Noordhuis
ff0316813d unix,windows: make uv_thread_create() return errno
Before this commit, UNIX returned -1 on failure.  Windows sometimes
returned a UV_E* error code and sometimes a bogus status code, courtesy
of errno values not mapping to UV_E* error codes on that platform.

PR-URL: https://github.com/libuv/libuv/pull/204
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2015-02-17 22:25:01 +01:00
Ben Noordhuis
b36d4ff930 unix: implement uv_stream_set_blocking()
Commit 393c1c5 ("unix: set non-block mode in uv_{pipe,tcp,udp}_open")
causes a regression in the io.js cluster module.

The io.js documentation states that `worker.send()` and `process.send()`
are synchronous but they no longer were after upgrading to libuv v1.2.1.

The reason they are synchronous is because of backpressure - or rather,
lack of backpressure: a slow consumer eventually causes a fast producer
to run out of memory because the backlog of pending messages in the
producer can grow unchecked.

Ergo, implement uv_stream_set_blocking() on UNIX platforms to let io.js
enable the old blocking behavior for pipes again.

Refs: https://github.com/iojs/io.js/issues/760
PR-URL: https://github.com/libuv/libuv/pull/187
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2015-02-09 13:28:52 +01:00
Leith Bade
3e75042a2b unix: check Android support for pthread_cond_timedwait_monotonic_np
Since API level 21 (Android 5.0) the non-standard pthread function
pthread_cond_timedwait_monotonic_np has been removed in favour of
the standard pthread_cond_timedwait which libuv normally uses on
Linux.

This commit changes the detection of the Android OS to account for
the removal of the function via the #define
HAVE_PTHREAD_COND_TIMEDWAIT_MONOTONIC which is only present in older
API levels.

Fixes: https://github.com/libuv/libuv/issues/172
PR-URL: https://github.com/libuv/libuv/pull/176
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2015-02-02 09:39:54 +01:00
Andrius Bentkus
39a0936fec win, unix: add pipe_peername implementation
PR-URL: https://github.com/libuv/libuv/pull/166
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2015-01-28 21:40:32 +01:00
Andrius Bentkus
2bfa2e5e22 style: rename buf to buffer and len to size for consistency
PR-URL: https://github.com/libuv/libuv/pull/159
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2015-01-27 11:31:16 +01:00
Andrius Bentkus
1e59ab1d49 fs, pipe: no trailing terminator in exact sized buffers
uv_fs_poll_getpath, uv_pipe_getsockname, uv_fs_event_getpath used
to return the trailing null terminator, even though the functions
returned the size.

Fixes: https://github.com/libuv/libuv/issues/155
PR-URL: https://github.com/libuv/libuv/pull/159
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2015-01-27 11:31:16 +01:00
Ben Noordhuis
67bb2b5f70 linux: fix epoll_pwait() regression with < 2.6.19
Linux before kernel 2.6.19 does not support epoll_pwait().  Due to a
logic error in commit 2daf944 ("unix: add flag for blocking SIGPROF
during poll"), the fallback path for ENOSYS was not taken.

This commit also adds epoll_pwait() emulation using pthread_sigmask().
The block/unblock operations are not atomic but that is fine for our
particular use case, to wit, sleep through SIGPROF signals.

PR-URL: https://github.com/libuv/libuv/pull/162
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2015-01-24 18:27:44 +01:00
Saúl Ibarra Corretgé
f2bb8d394c unix, win: add synchronous uv_get{addr,name}info
PR-URL: https://github.com/libuv/libuv/pull/156
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Bert Belder <bertbelder@gmail.com>
2015-01-23 01:12:05 +01:00
Ben Noordhuis
0b9ee2cf00 unix: fix long line introduced in commit 94e628fa
PR-URL: https://github.com/libuv/libuv/pull/150
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2015-01-21 13:04:50 +01:00
Ben Noordhuis
955b1806c7 unix: fix implicit declaration compiler warning
Include <string.h> explicitly to get the definition of strncpy().

Refs https://github.com/libuv/libuv/issues/138.

PR-URL: https://github.com/libuv/libuv/pull/150
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2015-01-21 13:04:28 +01:00
Andrius Bentkus
32747c75ce win,unix: move loop functions which have identical implementations
uv_default_loop, uv_loop_new, uv_loop_close, uv_loop_delete

PR-URL: https://github.com/libuv/libuv/pull/144
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-by: Saúl Ibarra Corretgé <saghul@gmail.com>
2015-01-20 12:22:28 +01:00
Saúl Ibarra Corretgé
b30a3e677b unix, windows: set non-block mode in uv_poll_init
libuv requires that the socket/fd is in non-blocking mode, so do it
internally so the user doesn't need to write platform specific code to
do so.

This also makes the API consistent with uv_{tcp,udp,pipe}_open, since
it's not required to pass the fd in non-blocking mode there either.

PR-URL: https://github.com/libuv/libuv/pull/136
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2015-01-16 10:41:00 +01:00
Ben Noordhuis
393c1c59a2 unix: set non-block mode in uv_{pipe,tcp,udp}_open
The contract specifies that the file descriptor should already be in
non-blocking mode before passing it to libuv.

However, node users don't really have an opportunity to do so, never
mind the fact that the call to uv_pipe_open() or uv_tcp_open() is an
implementation detail that most users won't be aware of.

Let's be nice and set the non-blocking flag explicitly.  It's a cheap
operation anyway.

Fixes: https://github.com/libuv/libuv/issues/124

PR: https://github.com/libuv/libuv/pull/134
Reviewed-by: Saúl Ibarra Corretgé <saghul@gmail.com>
2015-01-14 19:46:54 +01:00
Ben Noordhuis
bb5f5d107e unix: fix -Wsign-compare warning in tty.c
The mode argument is an enum now and the signedness of an enum is
implementation-defined when it doesn't have negative members.

Cast it to int in the comparison to tty->mode because the latter is
still an int.

PR: https://github.com/libuv/libuv/pull/134
Reviewed-by: Saúl Ibarra Corretgé <saghul@gmail.com>
2015-01-14 09:26:39 +01:00
Saúl Ibarra Corretgé
550147fd67 unix: make setting the tty mode to the same value a no-op
Closes #131

PR-URL: https://github.com/libuv/libuv/pull/132
Reviewed-By: Bert Belder <bertbelder@gmail.com>
2015-01-13 09:20:32 +01:00
Saúl Ibarra Corretgé
c3e22b7581 freebsd: make uv_exepath more resilient
PR-URL: https://github.com/libuv/libuv/pull/129
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2015-01-12 16:50:58 +01:00
Saúl Ibarra Corretgé
295fc41d29 unix: remove unused dtrace file
PR-URL: https://github.com/libuv/libuv/pull/119
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2015-01-06 18:25:08 +01:00
Ben Noordhuis
43818ade32 unix: don't unlink unix socket on bind error
Don't unlink the socket in uv_pipe_bind().  If the bind operation fails,
the socket is most likely not ours.

Fixes: https://github.com/libuv/libuv/issues/108
PR-URL: https://github.com/libuv/libuv/pull/109
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2015-01-05 09:39:04 +01:00
Ben Noordhuis
1b0ac59179 sunos: preemptively fix uv_exepath(size=1)
I'm not 100% sure whether the behavior of readlink() with size=0 is
well-defined on Solaris; it can return either 0 or fail with EINVAL.
POSIX is not explicit about the mandated behavior.

This commit adds a little caution and makes it skip the readlink()
call when size=1 and simply writes the terminating zero byte.

PR-URL: https://github.com/libuv/libuv/pull/104
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2015-01-03 23:40:34 +01:00
Ben Noordhuis
555a9647a0 linux: fix uv_exepath(size=1) UV_EINVAL error
uv_exepath() should write as much as possible to the output buffer.
In the case of size=1, skip the call to readlink() because it will
fail with EINVAL; just write the terminating zero byte.

PR-URL: https://github.com/libuv/libuv/pull/104
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2015-01-03 23:40:31 +01:00
Ben Noordhuis
d17a8e45f5 openbsd: fix uv_exepath(smallbuf) UV_EINVAL error
Write as much of the path as possible to the output buffer.  Before this
commit, passing in a buffer that was too small to hold the result failed
with a UV_EINVAL error.

PR-URL: https://github.com/libuv/libuv/pull/104
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2015-01-03 23:40:29 +01:00
Ben Noordhuis
885b1ecda0 darwin: fix uv_exepath(smallbuf) UV_EPERM error
Passing a buffer that was too small to hold the result made it fail
with UV_EPERM because the -1 status code from _NSGetExecutablePath()
was returned unmodified to the caller.

This commit rewrites uv_exepath() to:

1. Not allocate heap memory, and

2. Not clobber the result buffer on error, and

3. Handle _NSGetExecutablePath()'s and realpath()'s idiosyncracies, and

4. Store as much of the path in the output buffer as possible, don't
   fail with an error.  Makes it behave the same as other platforms.
   The result is always zero-terminated.

Fixes: https://github.com/libuv/libuv/issues/103
PR-URL: https://github.com/libuv/libuv/pull/104
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2015-01-03 23:40:24 +01:00
Ben Noordhuis
afb319215d unix: make uv_exepath(size=0) return UV_EINVAL
Make the behavior of a call to uv_exepath() with a size argument of zero
consistent with the Windows implementation where it returns UV_EINVAL.

PR-URL: https://github.com/libuv/libuv/pull/104
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2015-01-03 23:39:55 +01:00
Ben Noordhuis
af96f458e2 linux: fix support for preadv/pwritev-less kernels
The fix from commit 269ff0be is wrong in that it sniffs system headers
to determine if preadv() and pwrite() are supported.

It breaks the fs_write_multiple_bufs test on one of my ARM systems;
its glibc has preadv() and pwritev() wrappers but its kernel has no
support for the corresponding system calls.

Simply try the system call and fall back to a normal read or write
loop if not supported.  Move the no_preadv and no_pwritev variables
around to squelch two -Wpedantic warnings about mixing declarations
with code.

PR-URL: https://github.com/libuv/libuv/pull/90
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2015-01-02 18:02:34 +01:00
Saúl Ibarra Corretgé
2daee9fbeb unix: fix ttl, multicast ttl and loop options on IPv6
Fixes #93

PR-URL: https://github.com/libuv/libuv/pull/99
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2015-01-02 17:34:13 +01:00
Alexey Melnichuk
0473ac90bb common: move STATIC_ASSERT to uv-common.h
PR-URL: https://github.com/libuv/libuv/pull/82
Reviewed-By: Bert Belder <bertbelder@gmail.com>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2015-01-02 16:17:10 +01:00
Ben Noordhuis
ebc50aee1d Revert "unix: only set SO_REUSEADDR when bind() fails"
This reverts commit a9e95a33bc.

This seems to cause regressions in the test suite when IPv6 is disabled.

As optimizations go, it's a very minor one so let's not spend too much
effort trying to track down the cause of the regressions but revert the
change before it makes its way into a release.

PR-URL: https://github.com/libuv/libuv/pull/92
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2014-12-29 17:15:20 +01:00
Ben Noordhuis
a9e95a33bc unix: only set SO_REUSEADDR when bind() fails
Only call setsockopt() when the initial bind() fails with EADDRINUSE,
then retry.  Saves a system call in what is normally the common case.

PR-URL: https://github.com/libuv/libuv/pull/88
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2014-12-27 18:41:15 +01:00
Yuri D'Elia
025602da13 tty: implement binary I/O terminal mode
Introduce a uv_tty_mode_t enum for uv_tty_set_mode(), with backward
compatible values.  Add a new mode UV_TTY_MODE_IO, which uses
cfmakeraw() internally.

PR-URL: https://github.com/libuv/libuv/pull/86
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2014-12-27 18:18:24 +01:00
Ben Noordhuis
751ac48baa linux: fix epoll_pwait() sigmask size calculation
Revisit the fix from commit b705b53.  The problem with using sigset_t
and _NSIG is that the size of sigset_t and the value of _NSIG depend
on what headers libuv picks up first, <signal.h> or <asm/signal.h>.
With the former, sizeof(sigset_t) = 128; with the latter, it's 8.

Simply sidestep the issue by calculating the signal mask as a 64 bits
integer, without using sigset_t or _NSIG.

PR-URL: https://github.com/libuv/libuv/pull/83
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2014-12-25 14:37:02 +01:00
Saúl Ibarra Corretgé
e58dc26968 unix, windows: fix UV_RUN_ONCE mode if progress was made
If pending I/O callbacks were ran before polling, do a zero timeout
poll.

PR-URL: https://github.com/libuv/libuv/pull/58
Reviewed-By: Bert Belder <bertbelder@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2014-12-23 09:49:12 +01:00
Saúl Ibarra Corretgé
e37a2a0d53 unix, windows: don't treat uv_run_mode as a bitmask
The modes are not meant to be combined, and doing so may hide problems
in the future.

PR-URL: https://github.com/libuv/libuv/pull/58
Reviewed-By: Bert Belder <bertbelder@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2014-12-23 09:48:49 +01:00
Saúl Ibarra Corretgé
d4d1f32858 unix: change uv_cwd not to return a trailing slash
This aligns the behavior with the Windows implementation.

PR-URL: https://github.com/libuv/libuv/pull/63
Reviewed-By: Bert Belder <bertbelder@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2014-12-16 08:12:07 +01:00
Maciej Małecki
f87657ee08 cleanup: remove a dead increment
As pointed out by clang-analyzer.

PR-URL: https://github.com/libuv/libuv/pull/13
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2014-12-09 12:53:04 +01:00
Maciej Małecki
f86cd02a94 linux: return early if we have no interfaces
This was pointed out as possible undefined allocation of 0 bytes by
clang-analyzer. `malloc` of 0 bytes can return either `NULL` or a
valid pointer which can't be dereferenced. On systems which return
`NULL`, we would consider it a `malloc` error and return an `ENOMEM` to
the caller.

PR-URL: https://github.com/libuv/libuv/pull/13
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2014-12-09 12:52:59 +01:00
Maciej Małecki
18d58643af cleanup: remove all dead assignments
As pointed out by clang-analyzer.

PR-URL: https://github.com/libuv/libuv/pull/13
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2014-12-09 12:52:51 +01:00
Saúl Ibarra Corretgé
873b02607c unix: stop reading if an error is produced
This aligns the behavior with Windows, where users don't need to
call `uv_read_stop` or `uv_close` if they get an error in the read
callback.

PR-URL: https://github.com/libuv/libuv/pull/47
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2014-12-09 12:01:01 +01:00
Saúl Ibarra Corretgé
b1bb9053a5 unix: reset the reading flag when a stream gets EOF
PR-URL: https://github.com/libuv/libuv/pull/47
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2014-12-09 12:00:52 +01:00
Saúl Ibarra Corretgé
db6ba5b28c unix: remove overzealous assert in uv_read_stop
Also make it a noop if we weren't reading at all.

PR-URL: https://github.com/libuv/libuv/pull/47
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2014-12-09 12:00:31 +01:00
Ben Noordhuis
a6f2a4f834 Merge branch 'v0.10' into v1.x
Conflicts:
	AUTHORS
	ChangeLog
	README.md
	config-unix.mk
	include/uv.h
	src/unix/internal.h
	src/unix/kqueue.c
	src/unix/linux-core.c
	src/unix/stream.c
	src/uv-common.c
	src/uv-common.h
	src/version.c
	test/test-osx-select.c
2014-12-05 19:18:36 +01:00
Ben Noordhuis
9da5fd443e unix, windows: add uv_loop_configure() function
The only supported option right now is UV_LOOP_BLOCK_SIGNAL, which only
supports the SIGPROF signal and only on UNIX platforms.  So yes, it is
kind of limited right now.  But everything has to start somewhere.

Refs strongloop/strong-agent#3 and strongloop-internal/scrum-cs#37.

PR-URL: https://github.com/libuv/libuv/pull/15
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2014-12-05 17:39:43 +01:00
Ben Noordhuis
2daf9448b1 unix: add flag for blocking SIGPROF during poll
Add a per-event loop flag for blocking SIGPROF signals when polling for
events.

The motivation for this addition is to reduce the number of wakeups and
subsequent clock_gettime() system calls when using a sampling profiler.

On Linux, this switches from epoll_wait() to epoll_pwait() when enabled.
Other platforms bracket the poll syscall with pthread_sigmask() calls.

Refs strongloop/strong-agent#3 and strongloop-internal/scrum-cs#37.

PR-URL: https://github.com/libuv/libuv/pull/15
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2014-12-05 17:38:31 +01:00
Ben Noordhuis
484a3a92a8 Revert "unix: use cfmakeraw() for setting raw TTY mode"
This reverts commit 0f25560c8a.

This change was introduced to make it possible to use the TTY for binary
I/O but unfortunately it breaks libuv users that depend on the OPOST and
ONLCR flags, like node.js.

There is no point in adding those flags after the call to cfmakeraw()
because that would once again make the TTY unsuitable for binary I/O.
Let's revert it for now and revisit it again later.

Fixes libuv/libuv#32, reverts joyent/libuv#1567.

PR-URL: https://github.com/libuv/libuv/pull/33
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2014-12-04 21:16:06 +01:00
Joey Geralnik
3aeca36a1b unix, windows: fix typos in comments
Fix various typos and spelling mistakes in comments.
Does not affect any code, just changes comments.

PR-URL: https://github.com/libuv/libuv/pull/17
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2014-11-29 04:23:19 +01:00
Saúl Ibarra Corretgé
c0ea37cf30 unix: fix processing process handles queue
Make sure we initialize it after the handle was removed from the pending
queue so that QUEUE_REMOVE doesn't do an invalid write when the process
is closed.

Valgrind output:

==4362== Invalid write of size 8
==4362==    at 0x407DB8: uv__process_close (process.c:515)
==4362==    by 0x404F94: uv_close (core.c:138)
==4362==    by 0x4037C5: main (invalid_write.c:33)
==4362==  Address 0xffeffc820 is not stack'd, malloc'd or (recently) free'd
==4362==
==4362== Invalid write of size 8
==4362==    at 0x407DC3: uv__process_close (process.c:515)
==4362==    by 0x404F94: uv_close (core.c:138)
==4362==    by 0x4037C5: main (invalid_write.c:33)
==4362==  Address 0xffeffc828 is not stack'd, malloc'd or (recently) free'd

Refs: joyent/libuv/issues/1584
2014-11-26 11:07:24 +01:00
Helge Deller
5672bbd68a linux: handle O_NONBLOCK != SOCK_NONBLOCK case
linux-syscalls.h assumes that on all Linux platforms the value
of O_NONBLOCK is the same as SOCK_NONBLOCK.
This commit fixes it, as it is at least not true for hppa, and
resolves #1442.

Signed-off-by: Luca Bruno <lucab@debian.org>
2014-11-25 17:16:22 +01:00
Ben Noordhuis
b705b53edd linux: fix sigmask size arg in epoll_pwait() call
sizeof(sigset_t) = 128 whereas the kernel expects 8, the size of a long.

It made the system call fail with EINVAL when a non-NULL sigset was
passed in.  Fortunately, it's academic because there is just one call
site and it passes in NULL.

Fixes libuv/libuv#4.
2014-11-25 02:00:51 +01:00
Ben Noordhuis
cb5140023b build: remove dtrace probes
The existing probes, all two of them, cause a great deal of pain for
people trying to build libuv on Linux because of SystemTap's dtrace(1)
utilitity not understanding the -xnolibs flag.

We could hack around that but it's easier to just remove the probes:
they are largely useless and unused while still needing a lot of
supporting infrastructure.  This commit removes 200 lines of code
and configuration.

Refs joyent/libuv#1478.
2014-11-10 20:12:50 -03:00
Alexis Campailla
6591d000d1 win: fix uv_thread_self()
59658a8de7 changed uv_thread_self()
to return uv_thread_t, but uv_thread_t is a thread's HANDLE while
uv_thread_self() returns the current thread's id.
This means that uv_thread_equal() is also broken, as we are
potentially comparing HANDLES to ids.

Changed uv_thread_self() to return the current thread's creation handle.
Fixed small doc issue.
2014-11-10 20:03:01 -03:00
Yuri D'Elia
0f25560c8a unix: use cfmakeraw() for setting raw TTY mode 2014-11-10 20:00:23 -03:00
Michael Hudson-Doyle
ef7b783d8d linux: try epoll_pwait if epoll_wait is missing
It seems that epoll_wait is implemented in glibc in terms of epoll_pwait and
new architectures (like arm64) do not implement the epoll_wait syscall at all.
So if epoll_wait errors with ENOSYS, just call epoll_pwait.

This is a backport of 861de3d71d for v0.10
branch.
2014-10-20 23:40:28 +02:00
Tomasz Kołodziejski
59658a8de7 unix, windows: add uv_thread_equal 2014-10-20 09:51:49 +02:00
Saúl Ibarra Corretgé
8a8cff4b34 unix, windows: don't include null byte in uv_cwd size
Make it consistent with uv_exepath
2014-10-16 14:18:27 +02:00
cjihrig
c18205a1c5 unix, windows: add uv_fs_access() 2014-10-13 10:23:53 +02:00
Saúl Ibarra Corretgé
03e53f1cf7 fs: rename uv_fs_readdir to uv_fs_scandir
Closes #1431
2014-09-25 10:09:58 +02:00
Fedor Indutny
2f54947b72 fs: fix readdir on empty directory
`uv_fd_readdir()` should initialize all fields even if there are no
files. Fix the implementation and fix the test that should have been
covered it.
2014-09-23 21:06:54 +04:00
Recep ASLANTAS
94e628faf1 unix: fix warnings when loading functions with dlsym 2014-09-17 22:47:01 +02:00
Michael Hudson-Doyle
861de3d71d linux: try epoll_pwait if epoll_wait is missing
It seems that epoll_wait is implemented in glibc in terms of epoll_pwait and
new architectures (like arm64) do not implement the epoll_wait syscall at all.
So if epoll_wait errors with ENOSYS, just call epoll_pwait.
2014-09-17 00:25:46 +02:00
Fedor Indutny
c60d6af011 darwin: allocate enough space for select() hack
`fd_set`s are way too small for `select()` hack when stream's fd is
bigger than 1023. Make `fd_set`s a part of `uv__stream_select_t`
structure.

fix #1461

Conflicts:
	src/unix/stream.c
2014-09-08 09:09:21 +01:00
Fedor Indutny
145b76b894 darwin: allocate enough space for select() hack
`fd_set`s are way too small for `select()` hack when stream's fd is
bigger than 1023. Make `fd_set`s a part of `uv__stream_select_t`
structure.

fix #1461
2014-09-08 08:37:36 +01:00
Saúl Ibarra Corretgé
7ff52b836d unix, windows: don't allow a NULL callback on timers 2014-09-05 16:59:18 +02:00
Saúl Ibarra Corretgé
38cc2e39d0 unix: stop child process watcher after last one exits 2014-09-04 10:06:52 +02:00
Saúl Ibarra Corretgé
2d5eaea1cd unix: simplify how process handle queue is managed 2014-09-04 10:06:52 +02:00
Saúl Ibarra Corretgé
4ca9a36389 unix, windows: add uv_fileno
Returns the platform specific file descriptor for handles that are
backed by one. The datatype is abstracted as uv_os_fd_t, which maps to
int on Unices and HANDLE on Windows.

Users can use this function to set specific socket options, for example,
in a non portable way.

This function is essentially a shotgun, you better be careful with
whatever you do with it, don't blame me if you used it to get the fd of
a stream, close it yourself and expect things to Just Work.
2014-08-27 10:53:40 +02:00
Saúl Ibarra Corretgé
a87619ce63 unix, windows: move includes for EAI constants 2014-08-21 21:31:02 +02:00
Saúl Ibarra Corretgé
76cd67686c unix: fix exposing EAI_* glibc-isms 2014-08-21 16:48:45 +02:00
Andrius Bentkus
d5e6f4372f unix: fix tcp write after bad connect freezing
If the connect wouldn't go off (no such tcp remote or any other failure),
the subsequent writes made would not be called. Now we call the writes
in the queue with ECANCELED if the connect fails.

Fix #1432
2014-08-21 16:23:43 +02:00
Julien Gilli
1552184238 unix: read on stream even when UV__POLLHUP set.
This fixes a SmartOS specific issue that happens when reading from
a stream that is the reading end of a pipe that has been closed by
the parent process.

In this case, a UV__POLLHUP event would be set on the stream and would
prevent the event loop from closing it. As a result, the event loop
would think there are stil handles open, and leave the process
hanging.

Fixes #1419.
2014-08-18 09:06:27 -07:00
Saúl Ibarra Corretgé
fdbc8567af unix: fix colliding flag value
Fixes #1425
2014-08-18 10:14:21 +02:00
Fedor Indutny
ab2c4425a5 fs: introduce uv_readdir_next() and report types
Introduce:

    int uv_fs_readdir_next(uv_fs_t* req, uv_dirent_t* ent);

`uv_fs_readdir()` is not returning a file names list in `req->ptr`
anymore, the proper way to gather them is to call `uv_fs_readdir_next()`
in a callback.
2014-08-14 17:19:45 +04:00
Andrius Bentkus
875814adc5 unix: replace some asserts with returning errors 2014-08-11 18:42:48 +02:00
Andrius Bentkus
0ecee213ea unix, windows: add uv_recv_buffer_size and uv_send_buffer_size 2014-08-09 11:36:35 +02:00
Saúl Ibarra Corretgé
4dc0d81ccb netbsd: fix build
Thanks @ezra1!

Closes #1391
2014-08-09 11:22:41 +02:00
Alexis Campailla
c87c44fff3 windows: fix uv__getaddrinfo_translate_error
Use Windows socket error codes, as recommended by MSDN, like we already
do with GetNameInfoW.
2014-08-09 11:18:26 +02:00
Iñaki Baz Castillo
a1ff22cb7e include: avoid using C++ 'template' reserved word
Closes #1394
2014-08-06 12:52:46 +02:00
John Firebaugh
2cd91f9768 unix, windows: move uv_loop_close out of assert
Closes #1387
2014-08-02 09:41:09 +02:00
Rasmus Christian Pedersen
e72d48ddab unix, windows: const-ify handle in uv_udp_getsockname 2014-07-31 22:27:36 +02:00
Pavel Platto
e99b89f2ad unix, windows: add uv_fs_mkdtemp 2014-07-31 09:43:55 +02:00
Andrew Low
cdc979dbe0 aix: improve AIX compatibility 2014-07-22 22:57:24 +02:00
Andrius Bentkus
960eefb319 unix: guarantee write queue cb execution order in streams
The problem was that the canceled write callbacks
were being called before the already written callbacks, even
though they were queued after them.
2014-07-18 13:16:10 +02:00
Aaron Bieber
38323c9fbf openbsd: avoid requiring privileges for uv_resident_set_memory 2014-07-16 09:56:34 +02:00
Saúl Ibarra Corretgé
817c09257d unix: remove incorrect assert
After 41891222bc landed it's possible that uv__udp_sendmsg is called
even if there are no pending write nor write completed requests:

1. User calls uv_udp_send and the request is sent immediately. The
   request is the added to the completed queue and we 'feed' the uv__io
   handle so that we process the completed request in the next
   iteration.
2. User calls uv_udp_send again but the request is not completed
   immediately, so it's queued in the write_queue.
3. The uv__io handle gets a UV__POLLOUT event and uv__udp_sendmsg is
   run, which completes the send request and puts it in the
   write_completed_queue. Afterwards, uv__udp_run_completed is executed
   and the write_completed queue is drained.
4. At this point, the uv__io handle was made pending in step 3, in
   uv__udp_sendmsg, but we no longer have requests to write or to complete,
   so we skip processing.
2014-07-11 22:53:59 +02:00
Saúl Ibarra Corretgé
41891222bc unix: try to write immediately in uv_udp_send 2014-07-08 18:44:38 +02:00
Saúl Ibarra Corretgé
40ad12e5be unix: return UV_EAGAIN if uv_try_write cannot write any data 2014-07-04 20:45:09 +02:00
Andrius Bentkus
0d43992c3b unix, win: add uv_udp_try_send
The function returns UV_EAGAIN if the queue is not empty and
the message couldn't be sent immediately.
2014-07-04 18:30:33 +02:00
Andrius Bentkus
b769484ca3 unix, win: add send_queue_size and send_queue_count to uv_udp_t
This functionality is present in stream and uv_udp_t has a queue
as well so it makes sense for udp to have a send_write_size.
Since udp sends entire messages atomically, the send_queue_count field
lets the user determine how many messages are there left to send.
2014-07-04 18:28:18 +02:00
Andrius Bentkus
f63e073be2 common: use common uv__count_bufs code
Until now it was reimplemented in 2 different places (unix, win).
2014-07-04 18:28:18 +02:00
Saúl Ibarra Corretgé
4bace4d67c unix: use struct sockaddr_storage for target UDP addr 2014-06-29 23:52:46 +02:00
Saúl Ibarra Corretgé
8d11aacb79 unix, windows: use the same threadpool implementation 2014-06-27 14:27:04 +02:00
Saúl Ibarra Corretgé
570caf04db Merge branch 'v0.10'
Conflicts:
	ChangeLog
	build.mk
	src/unix/darwin.c
	src/unix/getaddrinfo.c
	src/version.c
	test/test-list.h
2014-06-25 10:31:21 +02:00
Fedor Indutny
211bf4ec37 darwin: invoke mach_timebase_info only once
According to @aktau, the call to `mach_timebase_info` costs 90% of the
total execution time of `uv_hrtime()`. The result of the call is static
on all existing platforms, so there is no need in invoking it multiple
times.

Signed-off-by: Fedor Indutny <fedor@indutny.com>
2014-06-25 01:32:05 +04:00
Andrius Bentkus
36b38cbdba style: remove trailing whitespace
Signed-off-by: Fedor Indutny <fedor@indutny.com>
2014-06-24 20:18:10 +04:00
Saúl Ibarra Corretgé
58f87691a4 unix: fix bogus structure field name 2014-06-19 09:12:52 +02:00
Saúl Ibarra Corretgé
133b9d1cc1 unix: allow uv_getnameinfo to be cancelled 2014-06-18 02:00:07 +02:00
Saúl Ibarra Corretgé
dd893814ad unix: return system error on EAI_SYSTEM 2014-06-18 01:18:55 +02:00
Saúl Ibarra Corretgé
6ffb82ef08 unix: don't run i/o callbacks after prepare callbacks
Run them after timers, like Windows does.

Closes #1317
2014-06-18 01:13:21 +02:00
Ben Noordhuis
91985d48f6 unix, windows: make uv_barrier_wait() return bool
Make uv_barrier_wait() return a boolean value indicating whether this
thread was the "serializer".

From `man pthread_barrier_wait`:

    Upon successful completion, the pthread_barrier_wait() function
    shall return PTHREAD_BARRIER_SERIAL_THREAD for a single (arbitrary)
    thread synchronized at the barrier and zero for each of the other
    threads.

Exposing that information from libuv is useful because it can make
cleanup significantly easier:

    if (uv_barrier_wait(&barrier) > 0)
      uv_barrier_destroy(&barrier);

Signed-off-by: Fedor Indutny <fedor@indutny.com>
2014-06-07 07:57:08 -07:00
Rasmus Christian Pedersen
70c42563c1 unix, windows: getnameinfo implementation
Closes #852
2014-05-20 17:33:52 +02:00
Saúl Ibarra Corretgé
1579788c50 unix, windows: avoid error in uv_fs_event_stop
For consistency with other handle types, if stop is called while the
handle wasn't started yet, it's a no-op.
2014-05-13 10:05:39 +02:00
Rasmus Christian Pedersen
ecaede660c unix, windows: uv_dlerror const argument 2014-05-13 00:00:54 +02:00
Saúl Ibarra Corretgé
4ce5470f3a unix: fix uv__open_cloexec usage
It returns the fd or the negated errno.
2014-05-12 11:23:13 +02:00
Saúl Ibarra Corretgé
386d2141e4 unix, windows: be consistent when binding implictly in UDP
Only these functions will trigger an implicit binding of a UDP handle:
- uv_udp_send
- uv_udp_recv_start
- uv_udp_set_membership

All other functions will return UV_EBADF in case the socket was not
bound.

Note: currently the socket is created and bound at the same time. This
may change in the future.
2014-05-08 15:12:09 +02:00
Saúl Ibarra Corretgé
9f51f26e96 unix: fix handling error on UDP socket creation 2014-05-08 00:35:22 +02:00
Saúl Ibarra Corretgé
f55b853be5 unix: handle case when addr is not initialized after recvmsg
If the handle was opened using `uv_udp_open` ift's possible that the
kernel doesn't fill in the msg_name field, so return NULL as the address
in that case.

fixes #1252
2014-04-23 19:19:23 +02:00
Saúl Ibarra Corretgé
9b4f2b84f1 unix, windows: validate flags on uv_udp|tcp_bind
fixes #1247
2014-04-22 22:57:01 +02:00
Chernyshev Viacheslav
886e2bcd55 unix, windows: pass const handle ptr to uv_tcp_get*name
uv_tcp_getsockname and uv_tcp_getpeername do not modify passed handle
pointer, so there is no need to keep this parameter non-const.
2014-04-18 12:07:38 +02:00
Chernyshev Viacheslav
4018f72615 osx: pass const handle pointer to uv___stream_fd
uv___stream_fd does not modify passed parameter, so non-const
pointer is not required here.
2014-04-18 12:07:38 +02:00
Ben Noordhuis
86831fe99c linux: reduce file descriptor count of async pipe
Reopen one of the pipe descriptors as read/write through the procfs.
Allows us to close the original pipe file descriptors, saving a file
descriptor on kernels that don't support eventfd(2).
2014-04-09 20:27:42 +04:00
Fedor Indutny
b48ca33019 fs: avoid using readv/writev where possible
The VirtualBox shared file system doesn't seem to be capable of
`readv()` syscall. Since we don't need them in the most of the cases
anyway, it won't hurt to just use `read()` and `write()` when we are
reading just one buffer.

see https://github.com/joyent/node/issues/7343 for details.
2014-04-07 14:20:16 +04:00
Fedor Indutny
295882ed32 error: add EMLINK mapping
fix joyent/node#7307
2014-04-03 16:37:25 +04:00
Saúl Ibarra Corretgé
7a4c42a054 unix: add UV_HANDLE_IPV6 flag to tcp and udp handles 2014-04-02 01:24:39 +02:00
Saúl Ibarra Corretgé
3558d65d2f unix, windows: do not set SO_REUSEADDR by default on udp
Add UV_UDP_REUSEADDR flag instead, which can be passed to uv_udp_bind.
If the udp handle is unbound when uv_udp_set_memberhsip or
uv_udp_set_multicast_interface is called, the handle will be bound with
UV_UDP_REUSEADDR set.
2014-04-02 01:21:35 +02:00
Saúl Ibarra Corretgé
08327a7cbd unix, windows: add IPv6 support for uv_udp_multicast_interface 2014-03-28 00:39:09 +01:00
Saúl Ibarra Corretgé
342e8c0dac unix: fallback to blocking writes if reopening a tty fails
In case reopening the file descriptor fails, fallback to the old
behavior where we do blocking writes, to avoid disrupting other
processes potentially using the file descriptor.
2014-03-27 09:14:15 +01:00
Fedor Indutny
c84796ecc2 Merge branch 'v0.10'
Conflicts:
	src/unix/process.c
2014-03-26 20:45:13 +04:00
Tonis Tiigi
fd77a5d6c6 process: don't close stdio fds during spawn
This is needed when closed stdio fd is reused for uv_spawn pipe.
Fixes #1211
2014-03-26 20:35:08 +04:00
Saúl Ibarra Corretgé
15140cebe1 unix: fix handling uv__open_cloexec failure 2014-03-20 15:50:43 +01:00
Saúl Ibarra Corretgé
0ee3ce98e4 osx: fix compilation warning
Remove leftover status argument uv_async_t callbacks
2014-03-19 09:28:44 +01:00
Saúl Ibarra Corretgé
7c5ab1a73e unix, windows: add IPv6 support to uv_udp_set_membership
Reworked from initial version by @snoj
2014-03-17 22:11:28 +01:00
Saúl Ibarra Corretgé
db2a9072bc unix, windows: removed unused status parameter
async, timer, prepare, idle and check handles don't need the status
parameter.
2014-03-17 21:42:36 +01:00
Javier Hernández
a2506c9362 android: add support of ifaddrs in android
Fixes https://github.com/joyent/node/issues/7291
2014-03-16 23:16:25 +01:00
Fedor Indutny
b597d15779 stream: do not leak alloc_cb buffers on error
Always pass previously allocated (if any) buffer, when calling
`read_cb()` on error.
2014-03-13 00:45:02 +04:00
Saúl Ibarra Corretgé
a057466c72 unix: fix setting written size on uv_wd 2014-03-11 22:19:55 +01:00
Fedor Indutny
118a0a3c9b Merge branch 'v0.10'
Conflicts:
	test/test-spawn.c
2014-03-11 02:59:48 +04:00
Fedor Indutny
9b38c01b54 kqueue: invalidate fd in uv_fs_event_t
Invalidate file descriptor when closing `uv_fs_event_t` handle. Note
that `uv__io_stop` is just removing `fd` from `loop->watchers` and not
actually invalidating all consequent events in a `kevent()` results.

fix joyent/node#1101
2014-03-11 02:44:13 +04:00
Saúl Ibarra Corretgé
b197515367 unix: reopen tty as /dev/tty
Reopen the file descriptor when it refers to a tty. This lets us put the
tty in non-blocking mode without affecting other processes that share it
with us.

This brings back commit 31f9fbc, which was reverted in 20bb1bf. The OSX
select trick is working now.

Original patch by @bnoordhuis
2014-03-10 19:37:29 +01:00
Geoffry Song
84f305915f linux: always deregister closing fds from epoll
If the same file description is open in two different processes, then
closing the file descriptor is not sufficient to deregister it from the
epoll instance (as described in epoll(7)), resulting in spurious events
that cause the event loop to spin repeatedly. So always explicitly
deregister it.

Fixes #1099.

Conflicts:
	test/test-spawn.c
2014-03-10 17:27:36 +04:00
Saúl Ibarra Corretgé
daa457b1c0 openbsd, osx: fix compilation warning on scandir
The select function takes a const struct on newer OSX versions but it
doesn't on OSX <= 10.7 or OpenBSD.
2014-03-10 09:07:44 +01:00
Saúl Ibarra Corretgé
4c47fcd787 freebsd: use accept4, introduced in version 10 2014-03-06 17:57:13 +01:00
Fedor Indutny
9aa48312bc Merge remote-tracking branch 'origin/v0.10'
Conflicts:
	AUTHORS
	ChangeLog
	include/uv.h
	src/unix/error.c
	src/unix/process.c
	src/version.c
2014-03-06 20:45:15 +04:00
Fedor Indutny
4f72f2145b error: add ENXIO for O_NONBLOCK FIFO open()
When opening FIFO with `O_NONBLOCK` flag, `ENXIO` could be returned if
the readable side hasn't yet opened this FIFO.
2014-03-06 20:36:07 +04:00
Paul Tan
347000929d unix: workaround broken pthread_sigmask on Android
On android, if a call to `pthread_sigmask` fails with EINVAL, fallback
to `sigprocmask`. This workarounds the broken behaviour of
`pthread_sigmask` on Android versions < 4.1. See:

* https://android.googlesource.com/platform/bionic/+/9bf330b5
* https://code.google.com/p/android/issues/detail?id=15337

This is implemented by replacing all calls of `pthread_sigmask` to a new
function `uv__pthread_sigmask` which implements this fallback mechanism.
2014-03-06 11:54:50 +01:00
Fedor Indutny
b05a3ee4d1 pipe: allow queueing pending handles
Introduce `int uv_pipe_pending_count(uv_pipe_t*)` and
`uv_handle_type uv_pipe_pending_type(uv_pipe_t*)`. They should be
used in IPC pipe's read cb to accept incoming handles:

    int count = uv_pipe_pending_count(pipe);
    int i;
    for (i = 0; i < count; i++) {
      uv_handle_type type = uv_pipe_pending_type(pipe);
      /* ... */
      uv_accept(...);
    }
2014-03-04 00:34:29 +04:00
Fedor Indutny
c0c9480e02 process: remove debug perror() prints
fix #1128
2014-03-03 21:04:52 +04:00
Saúl Ibarra Corretgé
422d2810b3 unix, windows: make uv_cwd be consistent with uv_exepath
Fixes #446
2014-02-27 09:44:28 +01:00
Saúl Ibarra Corretgé
2611ef43b1 unix, windows: add assertion in uv_loop_delete 2014-02-27 01:05:54 +01:00
Saúl Ibarra Corretgé
3a8767e35e unix: fix uv_fs_write when using an empty buffer 2014-02-26 23:59:29 +01:00
Brian White
269ff0beae fs: use preadv on Linux if available 2014-02-26 16:46:39 +01:00
Saúl Ibarra Corretgé
b055538d09 unix, windows: clarify what uv_stream_set_blocking does
Also replace the assert with an error on unix.
2014-02-26 00:03:30 +01:00
Saúl Ibarra Corretgé
7ad8f74302 unix, windows: set required size on UV_ENOBUFS
When the supplied buffer is not big enough and UV_ENOBUFS is
returned, hint the user about the required size by setting
the len paramemeter to the required value.

Applies to:
- uv_pipe_getsockname
- uv_fs_event_getpath
- uv_fs_poll_getpath
2014-02-25 11:56:02 +01:00
Saúl Ibarra Corretgé
6f98f4efd1 unix, windows: map ERANGE errno
This is a backport of 2f58bb6 from the master branch
2014-02-25 10:48:26 +01:00
Saúl Ibarra Corretgé
e5bdef9b59 fsevent: rename filename field to path
Also, it's now considered private.
2014-02-24 21:51:21 +01:00
Saúl Ibarra Corretgé
10f9120d78 errno: map EFBIG, ENOPROTOOPT and ETXTBSY
This is a backport of:
107be2bed3
4a023fc078
aaaefe32ca
2014-02-24 12:57:28 +01:00
Saúl Ibarra Corretgé
5ac214c712 unix, windows: add uv_pipe_getsockname 2014-02-23 20:25:20 +01:00
Benjamin Saunders
13dd3502a7 fs: vectored IO API for filesystem read/write
This improves API consistency with uv_read and uv_write and may
improve efficiency for some uses. Vectored IO is emulated when the
requisite system calls are unavailable.
2014-02-23 17:24:05 +01:00
Oleg Efimov
da9a2b1d3d unix, windows: add uv_getrusage() function 2014-02-21 18:50:15 +01:00
Saúl Ibarra Corretgé
787f5fff92 unix, windows: add uv_loop_init and uv_loop_close
These functions supersede uv_loop_new and uv_loop_delete.
uv_loop_init initialized a user allocated loop and uv_loop_close
removes all associated resources a loop uses after it has finished
execution.

uv_loop_new and uv_loop_delete are now deprecated.
2014-02-21 09:56:13 +01:00
William Light
bfba45d285 linux: include grp.h for setgroups() 2014-02-20 15:53:48 +01:00
Geoffry Song
780d8ad8e5 linux: always deregister closing fds from epoll
If the same file description is open in two different processes, then
closing the file descriptor is not sufficient to deregister it from the
epoll instance (as described in epoll(7)), resulting in spurious events
that cause the event loop to spin repeatedly. So always explicitly
deregister it.

Fixes #1099.
2014-02-19 17:13:49 +04:00
Ben Noordhuis
f17c535b73 unix: use a heap for timers
Replace the red-black tree with a heap.  The most common operation that
libuv performs on timers is looking up the first timer to expire.  With
a red-black tree, that operation is O(log n).  With a heap, it's O(1).
2014-02-19 13:36:14 +01:00
Fedor Indutny
fc40836f9a Merge branch 'v0.10'
Conflicts:
	src/unix/sunos.c
2014-02-19 00:18:25 +04:00
Fedor Indutny
703a9e601e sunos: handle rearm errors
fix #1078
2014-02-19 00:14:13 +04:00
Fedor Indutny
a03ea239db Revert "fs: vectored IO API for filesystem read/write"
This reverts commit 7df24583e5.
2014-02-18 21:48:13 +04:00
Benjamin Saunders
7df24583e5 fs: vectored IO API for filesystem read/write
This improves API consistency with uv_read and uv_write and may
improve efficiency for some uses. Vectored IO is emulated when the
requisite system calls are unavailable.
2014-02-18 12:30:20 +04:00
Saúl Ibarra Corretgé
6e2021ca11 unix: correct error when calling uv_shutdown twice
This is a backport of a284b90 for v0.10 branch
2014-02-15 16:55:06 +01:00
Keno Fischer
a284b90c03 unix: correct error when calling uv_shutdown twice
Before this one of the requests was left as a ghost in the system.
See https://github.com/JuliaLang/julia/issues/5793
2014-02-15 16:37:58 +01:00
Saúl Ibarra Corretgé
66ab38918c unix: call setgoups before calling setuid/setgid
Partial fix for #1093
2014-02-10 22:38:40 +01:00
Saúl Ibarra Corretgé
3901ec4976 unix: fix uv_tcp_nodelay return value in case of error
Fixes #1102
2014-02-10 09:00:46 +01:00
Austin Foxley
451de61b72 unix, win: add uv_udp_set_multicast_interface() 2014-02-07 09:07:11 +01:00
Fedor Indutny
6abe1e4b95 fs: uv__cloexec() opened fd
Every file descriptor opened using libuv should be automatically marked
as CLOEXEC to prevent it from leaking to a child process. Note that
since we are opening fds in a thread pool, there is a possible race
condition between `uv_spawn()` and the `open()` + `uv__cloexec()`. The
rwlock was added to avoid it.

see https://github.com/joyent/node/issues/6905
2014-02-01 01:02:37 +04:00
Fedor Indutny
513ce625ba Merge branch 'v0.10'
Conflicts:
	AUTHORS
	ChangeLog
	src/unix/stream.c
	src/version.c
2014-01-31 20:59:49 +04:00
Oguz Bastemur
a6ff04d2c4 stream: start thread after assignments
Changed the order of the member assignments since the thread
may start before the parameters are assigned. This especially
happens when the osx scheduler is very busy.
2014-01-31 20:53:06 +04:00
Fedor Indutny
923e4ec619 Merge branch 'v0.10'
Conflicts:
	ChangeLog
	src/unix/linux-core.c
	src/version.c
2014-01-29 17:02:25 +04:00
Fedor Indutny
3e2446d18d linux: fix C99/C++ comment 2014-01-29 17:01:35 +04:00
Trevor Norris
7c8ff3bc25 linux: move sscanf() out of the assert()
If asserts are turned off then the sscanf() wouldn't have run, being
placed directly in the assert() itself.
2014-01-29 17:01:26 +04:00
Trevor Norris
74b29000be linux: move sscanf() out of the assert()
If asserts are turned off then the sscanf() wouldn't have run, being
placed directly in the assert() itself.
2014-01-23 00:21:44 +04:00
Fedor Indutny
37e12bdafb Revert "linux: silence uninitialized variable warning"
This reverts commit 5008f8de08.
2014-01-23 00:06:07 +04:00
Trevor Norris
5008f8de08 linux: silence uninitialized variable warning
When building using gyp and BUILDTYPE=Release using clang 3.4 received
this warning:

../src/unix/linux-core.c:640:34: warning: variable 'n' is uninitialized
      for (len = sizeof("cpu0"); n /= 10; len++);
                                 ^

Initializing n = 0 silences this build warning.
2014-01-22 20:59:23 +01:00
Bert Belder
53effc3dd8 Merge branch 'v0.10'
Conflicts:
	ChangeLog
	src/unix/process.c
	src/version.c
2014-01-22 19:49:24 +01:00
Fedor Indutny
e403a2c486 process: close stdio after dup2'ing it
Thus allow passing the same file descriptor as the source of multiple
stdios.

Committed with the help and code parts from:

  * Sam Roberts <sam@strongloop.com>

fix #1074
2014-01-22 22:39:08 +04:00
Fedor Indutny
8bc29b6f5f openbsd: fix obvious bug in uv_cpu_info
`int which[]` should not be static here, as the function itself is
changing it

fix joyent/node#6878
2014-01-21 15:06:30 +04:00
Luca Bruno
993151bc40 linux: relax assumption on /proc/stat parsing
CPU entries in /proc/stat are not guaranteed to be monotonically
increasing, asserting on this assumption can break in cases such
as the UltraSparc II machine shown in #1080.

Signed-off-by: Luca Bruno <lucab@debian.org>
2014-01-20 08:45:34 -08:00
Fedor Indutny
8f15aae52f tcp: uv_tcp_dualstack()
Explicitly disable/enable dualstack depending on presence of flag set by
uv_tcp_dualstack() function.
2014-01-19 23:07:42 +00:00
River Tarnell
17648be234 unix: fix non-OSX builds
uv__stream_osx_interrupt_select was only defined on OS X, but is used
elsewhere on all platforms.  The intention was to implement it as a
no-op on other platforms, but the entire definition was inside
"#ifdef __APPLE__", so this didn't actually work.

Fix: move it above the #ifdef.
2013-12-28 22:17:03 +04:00
Fedor Indutny
08cafd091b stream: fix uv__stream_osx_select
Relying on `readable`/`writable` when polling will lead to the select
thread spinning in the loop and calling `uv_async_send()`, because
stream may never become not `readable`/`writable`.

We should rely on `uv__io_active()` instead and interruprt select thread
every time it changes.
2013-12-27 19:57:44 +04:00
Fedor Indutny
8b6c19e219 Revert "pipe: allow queueing pending handles"
The commit is quite broken and must be refactored before going into.

This reverts commit 08aeaf6193.
2013-12-24 02:17:12 +04:00
Fedor Indutny
08aeaf6193 pipe: allow queueing pending handles
If multiple handles arrive to the IPC pipe at the same time (happens on
some platforms), libuv will queue them internally, and call `read2_cb`
multiple times with a null-buffer and proper `handle_type`.
2013-12-23 14:15:32 +04:00
Alex Crichton
f166d6d705 osx: Fix a possible segfault in uv__io_poll
In our build infrastructure, I've seen a lot of segfaults recently that
were all only happening on OSX. Upon inspecting the coredumps, it
appearded that all segfaults happened at the same instruction, and upon
translating the assembly back to the source, I found that an array could
be indexed with a -1 index before the index was checked to be not -1.

As concrete evidence, here is the situation that I found caused the
segfault.  The instruction in question along with the relevant register
values was:

    mov    (%r8,%r15,8),%r12

    r8  = 0x7fb0ba800000
    r15 = 0xffffffffffffffff

    r8 + r15 * 8 == 0x7fb0ba7ffff8

It appears that the base of loop->watchers was page aligned, and by
going back one word I guess that the page wasn't mapped, causing our
segfaults.
2013-12-22 15:54:08 +04:00
Alex Crichton
f6422af80a osx: Fix a possible segfault in uv__io_poll
In our build infrastructure, I've seen a lot of segfaults recently that
were all only happening on OSX. Upon inspecting the coredumps, it
appearded that all segfaults happened at the same instruction, and upon
translating the assembly back to the source, I found that an array could
be indexed with a -1 index before the index was checked to be not -1.

As concrete evidence, here is the situation that I found caused the
segfault.  The instruction in question along with the relevant register
values was:

    mov    (%r8,%r15,8),%r12

    r8  = 0x7fb0ba800000
    r15 = 0xffffffffffffffff

    r8 + r15 * 8 == 0x7fb0ba7ffff8

It appears that the base of loop->watchers was page aligned, and by
going back one word I guess that the page wasn't mapped, causing our
segfaults.
2013-12-22 03:53:49 -08:00
Bert Belder
46a0602141 Merge branch 'v0.10'
Conflicts:
	AUTHORS
	ChangeLog
	src/version.c
2013-12-20 17:48:28 -08:00
Sam Roberts
ed36b85d3b unix, windows: add uv_loop_alive() function
Useful to know when the the event loop is empty, this can't be done with
uv_run() without possibly blocking, or running some events (which might
empty the event loop as a side-effect).
2013-12-19 15:35:03 -08:00
Alex Crichton
7c6bddbe2a unix: fix a possible memory leak in uv_fs_readdir
Some scandir implementations allocate the dirent struct even if the
directory is empty, so if `scandir` returns 0 there may still be memory
that needs to get deallocated. I have altered uv__fs_readdir to go to
the "deallocation exit area" when 0 files are found in the directory
and continue to return early on a return value of -1.

I went to add a test for this functionality, but it appears that one
already exists (reading an empty directory), so I imagine that the
valgrind builds must only be happening on linux instead of OSX as well?
I have confirmed manually that a program without this fix will
infinitely leak memory, and with this fix the memory usage stays
constant.
2013-12-18 12:05:47 +04:00
Fedor Indutny
17d60e3f94 stream: allow multiple buffers for uv_try_write 2013-12-13 22:59:47 +04:00
Fedor Indutny
b5e7798a89 stream: introduce uv_try_write(...)
`uv_try_write(stream, buf, size)` acts like `uv_write()`,
but without queueing actual write until UV_POLLOUT (or IOCP completion).
This is useful for doing writes using on-stack `uv_write_t` requests.

fix #1025
2013-12-13 22:29:00 +04:00
Saúl Ibarra Corretgé
15af49a7a0 unix, windows: always update loop time
Fixes #846
2013-12-10 09:13:34 +01:00
Fedor Indutny
646de34f5e unix: fix various memory leaks and undef behavior
Kindly suggested by `cppcheck`.
2013-12-07 02:29:43 +04:00
isaacs
5812e19bf6 Merge branch 'v0.10' 2013-11-29 16:25:58 -08:00
Alex Gaynor
47d98b64c4 doc: Removed use of gendered pronouns 2013-11-29 16:25:01 -08:00
Fedor Indutny
bf5038df40 fsevents: fix subfolder check
First of all, a bit of explanation of what happens there:

1. FSEvents emits absolute paths to changed files or directories
2. We cut off the first part of such paths, which is equal to handle's
   real path ('/dir/subdir/subsubdir`, without trailing slash)
3. Then, if we are running in non-recursive mode, we discard paths that
   have slashes ('/') as a non-first character in them
2013-11-26 13:24:57 +04:00
Ben Noordhuis
74457d08ba linux: fix up SO_REUSEPORT back-port
Commit 3d2c820 back-ports a patch from the master branch that disables
the use of SO_REUSEPORT on Linux for reasons mentioned in the commit
log.

Unfortunately, the back-port was incomplete; another setsockopt() call
site in src/unix/udp.c was overlooked.  This commit rectifies that.

Hat tip to Luca Bruno for helping troubleshoot the issue.
2013-11-25 16:18:01 +01:00
Ben Noordhuis
27795cfc0f unix: fix accept() EMFILE error handling
Fix a bug that was introduced in commit 3ee4d3f ("unix, windows:
return error codes directly") and add a regression test for good
measure.

Hat tip to Fedor for pointing out the issue.

Fixes #1007.
2013-11-25 01:54:47 +01:00
ci-innoq
c438e739a8 fsevents: remove kFSEventStreamCreateFlagNoDefer polyfill
The kFSEventStreamCreateFlagNoDefer flag is already
defined in CarbonCore/FSEvents.h since OS X 10.5.

Fixes #1000.
2013-11-23 12:20:30 +04:00
Ben Noordhuis
ab37249975 unix: nicer error message when kqueue() fails
Print the error message rather than just the errno.  The fact that the
errno is 24 is only informative to people that have their operating
system's error codes memorized.
2013-11-18 21:00:14 +01:00
Ben Noordhuis
f38869898d netbsd, openbsd: enable futimes() wrapper
OpenBSD and NetBSD have working futimes() implementations.  This commit
makes uv_fs_futime() work on those platforms.
2013-11-16 23:01:14 +01:00
Ben Noordhuis
e9f75fb146 unix: set close-on-exec flag on received fds
Set the close-on-exec flag on file descriptors that we've received with
recvmsg() so we don't leak them when calling fork() afterwards.

On Linux, we use the MSG_CMSG_CLOEXEC flag when supported (2.6.23 and
up.)

On older Linux versions and other platforms, we walk the received file
descriptors and set the close-on-exec flag for each fd manually.  That
won't entirely avoid race conditions when other threads call fork() or
clone() but at least we're less likely to leak file descriptors now.
2013-11-15 23:13:06 +01:00
Ben Noordhuis
17711b9053 Merge remote-tracking branch 'origin/v0.10'
Conflicts:
	AUTHORS
	ChangeLog
	src/unix/darwin.c
	src/version.c
2013-11-13 13:52:53 +01:00
Ben Noordhuis
026241ca67 unix: unbreak bsd build after bbccafb
Unbreak the build on the BSDs after commit bbccafb.  Move the new
uv__platform_invalidate_fd() function from src/unix/darwin.c to
src/unix/kqueue.c.
2013-11-13 12:20:09 +01:00
Fedor Indutny
6149b66ccb Merge branch 'v0.10'
Conflicts:
	build.mk
	src/unix/core.c
	src/unix/darwin.c
2013-11-12 15:30:54 +04:00
Fedor Indutny
f50ccd5238 core: fix fake watcher list and count preservation
Fake watcher list and count should be preserved only if
`loop->watchers` was already allocated.
2013-11-12 15:24:33 +04:00
Fedor Indutny
bbccafbe70 unix: fix reopened fd bug
When fd is closed and new one (with the same number) is opened inside
kqueue/epoll/port loop's callback - stale events might invoke callbacks
on wrong watchers.

Check if watcher was changed after invocation and invalidate all events
with the same fd.

fix #826
2013-11-12 15:02:59 +04:00
Fedor Indutny
0f5c28b684 fsevents: use FlagNoDefer for FSEventStreamCreate
Otherwise `FSEventStreamCreate()` will coalesce events, even if they're
happening in the interval, bigger than supplied `latency`. In other
words, if this flag is not set events will happen in separate callback
only if there was a delay bigger than `latency` between two consecutive
events.
2013-11-10 13:05:27 +04:00
Ben Noordhuis
0c76cdb98f linux: handle EPOLLHUP without EPOLLIN/EPOLLOUT
Work around an epoll quirk where it sometimes reports just the EPOLLERR
or EPOLLHUP event.  In order to force the event loop to move forward,
we merge in the read/write events that the watcher is interested in;
uv__read() and uv__write() will then deal with the error or hangup in
the usual fashion.

Fixes #982.

This is a back-port of commit 24bfef2 from the master branch.
2013-11-08 05:38:55 +01:00
Ben Noordhuis
24bfef2ef4 linux: handle EPOLLHUP without EPOLLIN/EPOLLOUT
Work around an epoll quirk where it sometimes reports just the EPOLLERR
or EPOLLHUP event.  In order to force the event loop to move forward,
we merge in the read/write events that the watcher is interested in;
uv__read() and uv__write() will then deal with the error or hangup in
the usual fashion.

Fixes #982.
2013-11-08 05:16:55 +01:00
Ben Noordhuis
b1b931de4e fsevents: use native character encoding file paths
Create file paths with CFStringCreateWithFileSystemRepresentation(),
not CFStringCreateWithCString().

Reapplies 3780e12 ("fsevents: support japaneese characters in path")
from the v0.10 branch.  Was dropped in the last v0.10 -> master merge
for failing to apply.
2013-11-08 14:03:57 +01:00
Ben Noordhuis
2bb3326c48 Merge remote-tracking branch 'origin/v0.10'
Drops commit 3780e12 ("fsevents: support japaneese characters in path")
for being quite inapplicable to the master branch.  Will be reworked
and applied in a follow-up commit.

Conflicts:
	README.md
	build.mk
	src/unix/fsevents.c
	src/unix/udp.c
2013-11-08 03:44:31 +01:00
Alex Crichton
f764bff699 unix: return exec errors from uv_spawn, not async
If spawning a process fails due to an exec() failure (but it succeeded
in forking), then this should be considered a spawn failure instead of
an asynchronous termination of the process. This allows to check for
common exec() failure conditions such as a bad path quickly instead of
having to rely on keeping track of the async callback.

Additionally, the meaning of the two fields returned in the callback are
now exactly what they advertise to be. The process exit argument is not
one of two values depending on what happened to the child.

Fixes #978.
2013-11-07 22:10:38 +01:00
Ben Noordhuis
7f44933c43 include: remove uv_strlcat() and uv_strlcpy()
It was pointed out that they don't quite work like their BSD namesakes
and they arguably shouldn't have been part of the API anyway.

Fixes #983.
2013-11-03 03:50:23 +01:00
Ben Noordhuis
3d2c820a4e linux: don't turn on SO_REUSEPORT socket option
On the BSDs, SO_REUSEPORT is pretty much SO_REUSEADDR with some special
casing for IP multicast.  When two processes (that don't do multicast)
bind to the same address, only the last one receives traffic.  It allows
one to "steal" the bound address from another process.  (Both processes
have to enable SO_REUSEPORT though, so it only works in a cooperative
setting.)

On Linux however, it enables port sharing, not stealing - both processes
receive a share of the traffic.  This is a desirable trait but pre-3.9
kernels don't support the socket option and a libuv program therefore
behaves differently with older kernels or on another platform.

This is a back-port of commit 9d60f1e from the master branch.

Fixes joyent/node#6454.
2013-10-30 09:41:52 +01:00
Chris Bank
3780e12823 fsevents: support japaneese characters in path 2013-11-02 05:00:50 +04:00
Fedor Indutny
29fdb3471b unix: update events from pevents between polls
Watchers could be stopped between two `kevent()`/`epoll_wait()` calls
(which may happen in the same loop in `uv__io_poll()`), in such cases
`watcher->events` could be stale and won't be updated to
`watcher->pevents`.

Try to use and rely on `watcher->pevents` instead of blindly expecting
`watcher->events` to be always correct.
2013-10-30 12:40:25 +04:00
Ben Noordhuis
21c37a7db8 linux: use CLOCK_MONOTONIC_COARSE if available
On some systems, clock_gettime(CLOCK_MONOTONIC) is only serviced from
the vDSO when the __vdso_clock_gettime() wrapper is confident enough
that the vDSO timestamp is highly accurate.  When in doubt, it falls
back to making a traditional SYS_clock_gettime system call with all
the overhead that entails.

While a commendable approach, it's overkill for our purposes because we
don't usually need high precision time. That's why this commit switches
to CLOCK_MONOTONIC_COARSE for low-precision timekeeping, provided said
clock has at least a one millisecond resolution.

This change should eliminate the system call on almost all systems,
including virtualized ones, provided the kernel is >= 2.6.32 and glibc
is new enough to find and parse the vDSO.
2013-10-29 21:24:42 +01:00
Fedor Indutny
43bef41031 fsevents: report errors to user 2013-10-31 01:06:37 +04:00
Fedor Indutny
ab0225277b Merge branch 'v0.10'
Conflicts:
	src/unix/darwin-proctitle.c
	src/version.c
2013-10-28 20:59:10 +04:00
Fedor Indutny
08e0e63f3a darwin: avoid calling GetCurrentProcess
Use some black-magic from Apple to change process name without getting
a "Not responding" tag from Activity Manager.

fix #966
2013-10-28 20:51:50 +04:00
Keno Fischer
fb36c09966 unix: move uv_shutdown() assertion
Allows uv_shutdown() to return an error as intended if the stream has
already been closed.

Fixes #972, refs JuliaLang/julia#4229.
2013-10-27 11:39:23 +01:00
Fedor Indutny
0fdd99f02b fsevents: increase stack size for OSX 10.9
Otherwise it fails with `EXC_BAD_ACCESS`.
2013-10-23 12:44:16 +04:00
Ben Noordhuis
777019b768 unix: make uv_tty_reset_mode() async signal-safe
Make it possible to call uv_tty_reset_mode() from inside a signal
handler.  The primary motivation is to make it possible to restore
the TTY from inside a SIGINT or SIGTERM signal handler.

Fixes #954.
2013-10-20 13:58:34 +02:00
Ben Noordhuis
372e9229ad unix: clean up uv_tty_set_mode() a little 2013-10-20 13:58:34 +02:00
Ben Noordhuis
150b6a71c9 unix: add spinlock.h
Add an atomic, non-blocking spinlock type.  The primary use case is to
have a mutex type that we can use while inside a signal handler.
2013-10-20 13:58:34 +02:00
Ben Noordhuis
a3c3b37bfb unix: add atomic-ops.h
Add cmpxchgi(), cmpxchgl() and cpu_relax() functions that we can use
as simple primitives to build spinlocks out of.
2013-10-20 13:58:34 +02:00
Ben Noordhuis
fe4f06261e Merge remote-tracking branch 'origin/v0.10'
Conflicts:
	include/uv-darwin.h
	src/unix/fsevents.c
	src/unix/process.c
2013-10-18 17:29:19 +02:00
Ben Noordhuis
1800efc138 unix: fix non-synchronized access in signal.c
Check the return value of uv__signal_lock(); don't mutate the signal
watcher tree in the signal handler if we failed to acquire the lock.
2013-10-18 17:10:04 +02:00
Saúl Ibarra Corretgé
9d44d786ad unix, windows: add uv_fs_event_start/stop functions
Make uv_fs_event behave like other handles, that is, it's inactive after
init, and it's active between start and stop.
2013-10-12 20:37:05 +02:00
Ben Noordhuis
5c00a0ee33 unix: fix SIGCHLD waitpid() race in process.c
Before this commit, multiple event loops raced with each other when a
SIGCHLD signal was received.  More concretely, it was possible for
event loop A to consume waitpid() events that should have been
delivered to event loop B.

This commit addresses that by doing a linear scan over the list of
child processes.  An O(n) scan is not terribly efficient but the
actual performance impact is not measurable in a benchmark that spawns
rounds of several thousands instances of /bin/false.  For the time
being, this patch will suffice; we can always revisit it later.

Fixes #887.
2013-10-09 11:18:13 +02:00
Ben Noordhuis
556fe1a659 linux: ignore fractional time in uv_uptime()
Before this commit, uv_uptime() returned the nanoseconds as the
fractional part of the uptime.  It's a bit inconsistent with the
output on other platforms because those only return whole seconds
(with the possible exception of Windows.)

This commit changes linux-core.c to only return whole seconds.
2013-10-08 23:18:00 +02:00
Fedor Indutny
429bb804ed fsevents: fix clever rescheduling
There're could be a situation, where one fsevents handle gets created
and another one is destroyed simultaneously. In such cases
`fsevent_need_reschedule` will be set to 1 twice and reset only once,
leaving handle destructor hanging in uv_sem_wait().
2013-10-05 22:18:06 +04:00
Ben Noordhuis
38df93cfed unix: revert recent FSEvent changes
This commit reverts the following commits:

    983fa68 darwin: fix 10.6 build error in fsevents.c
    684e212 fsevents: use shared FSEventStream
    ea4cb77 fsevents: FSEvents is most likely not thread-safe
    9bae606 darwin: create fsevents thread on demand

Several people have reported stability issues on OS X 10.8 and bus
errors on the 10.9 developer preview.

See also joyent/node#6296 and joyent/node#6251.
2013-10-05 18:24:33 +02:00
Ben Noordhuis
11d8011793 unix: don't close inherited fds on uv_spawn() fail
The cleanup-after-error code path in uv_spawn() was closing file
descriptors indiscriminately.  Only close file descriptors that we
created ourselves, not the ones that are passed in by the user.

Fixes joyent/node#6297.
2013-10-02 11:17:20 +02:00
Ben Noordhuis
fc3a21f943 unix: fix uv_spawn() NULL pointer deref on ENOMEM
In the cleanup-after-error section of uv_spawn(), check that the pointer
is non-NULL - we might end up in said section due to a malloc() failure.
2013-10-02 10:56:56 +02:00
Ben Noordhuis
0d435a5662 unix: remove uv__pipe_accept()
It's basically a less advanced version of uv__server_io().  Drop the
former in favor of the latter.
2013-10-01 04:14:36 +02:00
Ben Noordhuis
359d667893 unix: sanity-check fds before closing
Ensure that close() system calls don't close stdio file descriptors
because that is almost never the intention.

This is also a partial workaround for a kernel bug that seems to affect
all Linux kernels when stdin is a pipe that gets closed: fd 0 keeps
signalling EPOLLHUP but a subsequent call to epoll_ctl(EPOLL_CTL_DEL)
fails with EBADF.  See joyent/node#6271 for details and a test case.
2013-10-01 03:55:54 +02:00
Ben Noordhuis
8c9cbee1b1 Revert "unix: set O_NONBLOCK in uv_pipe_open()"
It turns out that node.js relies on the blocking behavior of pipes in
some cases, notably when forking worker processes.  Reopens #941.

This reverts commit 8fe4ca686b.
2013-09-28 20:50:45 +02:00
Ben Noordhuis
8fe4ca686b unix: set O_NONBLOCK in uv_pipe_open()
Don't rely on the caller to set the O_NONBLOCK flag on the file
descriptor.

Prevents sporadic stalls when the file descriptor is in blocking mode
and exactly as many bytes are read as there are available; in that case,
libuv will try to read again and block.  Node.js was guilty of this.

Fixes #941.
2013-09-28 10:30:09 +02:00
Ben Noordhuis
d7115f0677 unix, windows: make uv_is_*() always return 0 or 1
Ensure that the following API functions always return either 0 or 1:

  * uv_is_active()
  * uv_is_closing()
  * uv_is_readable()
  * uv_is_writable()
2013-09-12 13:30:06 +02:00
Ben Noordhuis
05822a5507 unix: wrap long lines at 80 columns 2013-09-11 17:29:43 +02:00
Ben Noordhuis
983fa68e9f darwin: fix 10.6 build error in fsevents.c
Work around an 'initializer element is not constant' build error in
src/unix/fsevents.c by turning the const int flags into #defines.

Only an issue on OS X 10.6 due to the old compiler it uses.

Fixes #908.

This is a back-port of commit 82f2472 from the master branch.
2013-09-05 21:33:59 +02:00