Commit Graph

33 Commits

Author SHA1 Message Date
Ben Noordhuis
72fe3543fe unix,win: add uv_library_shutdown()
Make it possible to explicitly tell libuv to release any resources
it's still holding onto (memory, threads, file descriptors, etc.)

Before this commit, cleanup was performed in various destructors.
This commit centralizes the cleanup logic, enabling the addition of
`uv_library_shutdown()`, but maintains the current observable behavior
of cleaning up when libuv is unloaded by means of `dlclose(3)`.

Fixes: https://github.com/libuv/libuv/issues/2763
PR-URL: https://github.com/libuv/libuv/pull/2764
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2020-04-22 12:24:36 +02:00
Ben Noordhuis
70469dcaa6 unix: fix signal handle closing deferral
The way libuv handled closing of `uv_signal_t` handles with pending
events introduced an infidelity where `uv_loop_alive()` returned false
while the signal handle was still in the closing-but-not-closed state.

Fixes: https://github.com/libuv/libuv/issues/2721
PR-URL: https://github.com/libuv/libuv/pull/2722
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
2020-03-10 10:58:29 +01:00
George Zhao
93ca478adb unix: fix -Wunused-but-set-variable warning
PR-URL: https://github.com/libuv/libuv/pull/2517
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>
2019-12-16 15:40:04 +01:00
Santiago Gimeno
1de151700d
unix,signal: keep handle active if pending signal
Keep the signal handler active after being closed until all the caught
signals have been delivered.

Fixes: https://github.com/libuv/libuv/issues/2398
Fixes: https://github.com/libuv/libuv/issues/2415
PR-URL: https://github.com/libuv/libuv/pull/2423
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2019-08-19 22:39:06 +02:00
Evgeny Ermakov
d92c5d1314
unix: fix a comment typo in signal.c
PR-URL: https://github.com/libuv/libuv/pull/2318
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com>
Reviewed-By: Vladimír Čunát <v@cunat.cz>
2019-06-24 21:41:46 -04:00
Ben Noordhuis
619937c783 unix,win: merge handle flags
Some long overdue refactoring that unifies more of the UNIX and Windows
backends.

PR-URL: https://github.com/libuv/libuv/pull/1904
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2018-06-29 22:24:52 +02:00
Ben Noordhuis
a4623c7392 unix: close signal pipe fds on unload
Add a destructor function that closes the file descriptors when libuv.so
is unloaded.

Fixes: https://github.com/libuv/help/issues/52
PR-URL: https://github.com/libuv/libuv/pull/1857
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2018-06-02 18:13:48 +02:00
Mason X
89cbbc895b
include,src: introduce UV__ERR() macro
Using -errno, -E**, and -pthread_function() can be
error prone, and breaks compatibility with some operating
systems that already negate errno's (e.g. Haiku).

This commit adds a UV__ERR() macro that ensures libuv
errors are negative.

Fixes: https://github.com/libuv/help/issues/39
PR-URL: https://github.com/libuv/libuv/pull/1687
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
2018-02-08 22:38:02 -05:00
Brad King
52b8b9a8b9
unix: use SA_RESTART when setting our sighandler
BSD `signal(2)` semantics make some system calls (e.g. for `write`)
restartable when interrupted by a signal handler.  Use `SA_RESTART` to
enable these semantics everywhere that supports them.

This was done by libev back when we used it.  In addition to being
common practice, this is required by C++ stream libraries that interpret
`EINTR` as any other error, set `badbit`, and stop writing.  I've
observed this with `libstdc++` during a `std::cout.flush()` call
interrupted by `SIGCHLD`.

PR-URL: https://github.com/libuv/libuv/pull/1696
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
2018-01-10 14:42:10 +01: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
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
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
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
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
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
Fedor Indutny
646de34f5e unix: fix various memory leaks and undef behavior
Kindly suggested by `cppcheck`.
2013-12-07 02:29:43 +04: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
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
05822a5507 unix: wrap long lines at 80 columns 2013-09-11 17:29:43 +02:00
Ben Noordhuis
c6adab2e27 unix: fix uv__signal_unlock() prototype 2013-08-12 07:55:34 +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
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
Sean Silva
c39648674c unix: appease warning about non-standard inline
Clang warns about using `inline`, which is not technically allowed in
C89 mode (libuv compiles with `-std=c89`). It's probably best to leave
it to the compiler to do the inlining anyway.
2013-05-25 13:08:05 +02:00
Bert Belder
c5d570ddba unix: fix assert on signal pipe overflow
An incorrect assert() statement was causing libuv to crash when writing
to an internal signal pipe would result in EAGAIN/EWOULDBLOCK.

This commit doesn't solve the underlying issue that the signal pipe can
overflow.

This should fix joyent/node#5538
2013-05-23 14:44:45 +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
7f3c783583 unix: don't clobber errno in signal handler 2013-01-31 15:28:16 +01:00
Ben Noordhuis
0a06c2f3b2 unix: fix up function prototypes in signal.c 2013-01-06 21:25:58 +01:00
Ben Noordhuis
65bb6f068e unix: rename UV__IO_* constants 2012-11-16 17:33:29 +01:00
Ben Noordhuis
1282d64868 unix: remove dependency on libev 2012-11-16 17:33:25 +01:00
Ben Noordhuis
d6b7fe0e3b unix: squelch -Wunused-but-set-variable warnings 2012-11-09 03:22:12 +01:00
Bert Belder
1e32cb01b5 unix: support signal handlers outside the main loop 2012-10-17 01:25:02 +02:00
Ben Noordhuis
ee50db6e36 unix, windows: preliminary signal handler support
* a no-op on Windows for now
* only supports the main loop on UNIX (again, for now)
2012-08-10 02:00:07 +02:00