Commit Graph

101 Commits

Author SHA1 Message Date
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
Brian White
e3a657c662 unix, windows: add MAC to uv_interface_addresses()
Make uv_interface_addresses() return the MAC address as a 48 bits
binary value in the phys_addr field of the uv_interface_address_t
struct.
2013-07-25 13:49:39 +02:00
Ben Noordhuis
3ee4d3f183 unix, windows: return error codes directly
This commit changes the libuv API to return error codes directly rather
than storing them in a loop-global field.

A code snippet like this one:

    if (uv_foo(loop) < 0) {
      uv_err_t err = uv_last_error(loop);
      fprintf(stderr, "%s\n", uv_strerror(err));
    }

Should be rewritten like this:

    int err = uv_foo(loop);
    if (err < 0)
      fprintf(stderr, "%s\n", uv_strerror(err));

The rationale for this change is that it should make creating bindings
for other languages a lot easier: dealing with struct return values is
painful with most FFIs and often downright buggy.
2013-07-07 09:51:00 +02:00
Ben Noordhuis
7e8d0e6d9c Merge remote-tracking branch 'origin/v0.10' 2013-06-13 09:05:12 +02:00
Andrei Sedoi
5096f1e096 linux: add support for MIPS 2013-06-13 09:04:15 +02:00
Linus Mårtensson
3fdd2a1128 uv: support android libuv standalone build
Tested most of my compilation in the previous patch on NodeJS
and extracted the patches from there. This patch ensures libuv
will be capable of building standalone as well, both with gyp
and Makefiles.

Build documentation was added to the README.md file.

Some tests are failing, and I have not heavily investigated
the reasons. The failures are generally on errors, and are
likely related to differences between fully POSIX-compatible
systems and android.
2013-05-31 13:25:17 +02:00
Ben Noordhuis
b93cf8b594 linux: don't ignore OOM errors in uv_cpu_info() 2013-05-29 01:43:05 +02:00
Ben Noordhuis
31282a97e7 linux: fix memory leak in uv_cpu_info() error path
Any memory allocated to hold CPU model strings wasn't freed on error.
2013-05-29 01:43:05 +02:00
Ben Noordhuis
92c72f58bf linux: fix cpu model parsing on newer arm kernels
The format of /proc/cpuinfo on ARM kernels >= 3.8 has changed. Scan for
the string "model name" (like x86) first, "Processor" second.

Fixes #812.
2013-05-29 01:40:09 +02:00
Linus Mårtensson
fc6a2ad24f unix: support for android builds
Adds targets and fixes to ensure building for android works.

To build on android, refer to the android standalone toolchain.
2013-05-25 21:16:52 +02:00
Ben Noordhuis
8ef9592a95 Merge remote-tracking branch 'origin/v0.10'
Conflicts:
	ChangeLog
	src/unix/stream.c
	src/version.c
2013-05-29 23:32:07 +02:00
Ben Noordhuis
ebdeaed2e3 Merge remote-tracking branch 'origin/v0.10'
Conflicts:
	ChangeLog
	src/version.c
2013-05-02 09:22:39 +02:00
Ben Noordhuis
cd10637d0b linux: don't use fopen() in uv_resident_set_memory()
RSS is a reflection of the number of pages that a process has mapped.
glibc implements fopen() in terms of mmap() which means that trying
to read the number of mapped pages changes it. Switch to open().
2013-04-22 08:26:53 +02:00
Ben Noordhuis
8041c52fcd unix: style fixups 2013-04-10 14:59:02 +02:00
Ben Kelly
14aa6153be unix, win: add netmask to uv_interface_address
Include the netmask when returning information about the OS network
interfaces.

This commit provides implementations for windows and those unix
platforms using getifaddrs().

AIX was not implemented because it requires the use of ioctls and I do
not have an AIX development/test environment.  The windows code was
developed using mingw on winxp as I do not have access to visual studio.

Tested on darwin (ipv4/ipv6) and winxp (ipv4 only).  Needs testing on
newer windows using ipv6 and other unix platforms.
2013-04-10 14:48:23 +02:00
Ben Noordhuis
0635e29714 unix, windows: remove ngx-queue.h
Avoids an extra #include in public headers and stops the ngx_queue_*
types and macros from leaking into user code.
2013-03-27 00:09:36 +01:00
Ben Noordhuis
7e59f9bb53 linux: make uv_cpu_info() handle absent procfs
Return an error when reading from /proc files fails because the procfs
isn't mounted.
2013-03-02 01:48:44 +01:00
Ben Noordhuis
e89aced8d6 darwin: implement uv_set_process_title, part 2
Make changes to the process title visible to tools like `ps`.

The argv clobber technique is reasonably portable across Unices;
the common code has been moved into src/unix/proctitle.c and is used
on Linux and OS X. Other platforms will probably follow in the future.
2013-02-24 03:56:02 +01:00
Ben Noordhuis
c98083ef26 unix: short-circuit on no-op io watcher changes
Don't add the io watcher to the watcher queue if the requested change
is effectively a no-op, that is, when the event mask doesn't change.

The exception here is sunos because the event ports backend requires
that watched file descriptors are re-added on every turn of the event
loop.

This commit is a micro-optimization, it does not change the event
loop's observable behavior in any way.
2013-02-22 17:02:05 +01:00
Ben Noordhuis
26fa6f8031 linux: fix abort() on epoll_ctl() race condition
Don't check the return value of epoll_ctl(EPOLL_CTL_DEL). When the
file descriptor is closed, we're potentially racing with another
thread and that means the errno is not a reliable indicator of
the actual error.

The other event mechanisms (kqueue, event ports) are not affected
because:

* kqueue returns either EBADF or ENOENT. Both are handled by libuv.
* event ports rearms all file descriptors on each call to port_getn().

Fixes joyent/node#4558.
2013-02-20 21:28:39 +01:00
Ben Noordhuis
b607a7fed7 linux: move files out of src/unix/linux
Flattens the source tree and simplifies the Makefile.
2013-01-29 17:07:41 +01:00