ext/libuv/src/unix/signal.c in uvrb-0.1.4 vs ext/libuv/src/unix/signal.c in uvrb-0.2.0
- old
+ new
@@ -35,11 +35,11 @@
} uv__signal_msg_t;
RB_HEAD(uv__signal_tree_s, uv_signal_s);
-static int uv__signal_unlock();
+static int uv__signal_unlock(void);
static void uv__signal_event(uv_loop_t* loop, uv__io_t* w, unsigned int events);
static int uv__signal_compare(uv_signal_t* w1, uv_signal_t* w2);
static void uv__signal_stop(uv_signal_t* handle);
@@ -114,11 +114,11 @@
if (pthread_sigmask(SIG_SETMASK, saved_sigmask, NULL))
abort();
}
-inline static uv_signal_t* uv__signal_first_handle(int signum) {
+static uv_signal_t* uv__signal_first_handle(int signum) {
/* This function must be called with the signal lock held. */
uv_signal_t lookup;
uv_signal_t* handle;
lookup.signum = signum;
@@ -169,11 +169,11 @@
uv__signal_unlock();
errno = saved_errno;
}
-static uv_err_t uv__signal_register_handler(int signum) {
+static int uv__signal_register_handler(int signum) {
/* When this function is called, the signal lock must be held. */
struct sigaction sa;
/* XXX use a separate signal stack? */
memset(&sa, 0, sizeof(sa));
@@ -181,13 +181,13 @@
abort();
sa.sa_handler = uv__signal_handler;
/* XXX save old action so we can restore it later on? */
if (sigaction(signum, &sa, NULL))
- return uv__new_sys_error(errno);
+ return -errno;
- return uv_ok_;
+ return 0;
}
static void uv__signal_unregister_handler(int signum) {
/* When this function is called, the signal lock must be held. */
@@ -204,16 +204,19 @@
abort();
}
static int uv__signal_loop_once_init(uv_loop_t* loop) {
+ int err;
+
/* Return if already initialized. */
if (loop->signal_pipefd[0] != -1)
return 0;
- if (uv__make_pipe(loop->signal_pipefd, UV__F_NONBLOCK))
- return -1;
+ err = uv__make_pipe(loop->signal_pipefd, UV__F_NONBLOCK);
+ if (err)
+ return err;
uv__io_init(&loop->signal_io_watcher,
uv__signal_event,
loop->signal_pipefd[0]);
uv__io_start(loop, &loop->signal_io_watcher, UV__POLLIN);
@@ -221,18 +224,18 @@
return 0;
}
void uv__signal_loop_cleanup(uv_loop_t* loop) {
- ngx_queue_t* q;
+ QUEUE* q;
/* Stop all the signal watchers that are still attached to this loop. This
* ensures that the (shared) signal tree doesn't contain any invalid entries
* entries, and that signal handlers are removed when appropriate.
*/
- ngx_queue_foreach(q, &loop->handle_queue) {
- uv_handle_t* handle = ngx_queue_data(q, uv_handle_t, handle_queue);
+ QUEUE_FOREACH(q, &loop->handle_queue) {
+ uv_handle_t* handle = QUEUE_DATA(q, uv_handle_t, handle_queue);
if (handle->type == UV_SIGNAL)
uv__signal_stop((uv_signal_t*) handle);
}
@@ -247,13 +250,16 @@
}
}
int uv_signal_init(uv_loop_t* loop, uv_signal_t* handle) {
- if (uv__signal_loop_once_init(loop))
- return uv__set_sys_error(loop, errno);
+ int err;
+ err = uv__signal_loop_once_init(loop);
+ if (err)
+ return err;
+
uv__handle_init(loop, (uv_handle_t*) handle, UV_SIGNAL);
handle->signum = 0;
handle->caught_signals = 0;
handle->dispatched_signals = 0;
@@ -275,21 +281,20 @@
}
int uv_signal_start(uv_signal_t* handle, uv_signal_cb signal_cb, int signum) {
sigset_t saved_sigmask;
+ int err;
assert(!(handle->flags & (UV_CLOSING | UV_CLOSED)));
/* If the user supplies signum == 0, then return an error already. If the
* signum is otherwise invalid then uv__signal_register will find out
* eventually.
*/
- if (signum == 0) {
- uv__set_artificial_error(handle->loop, UV_EINVAL);
- return -1;
- }
+ if (signum == 0)
+ return -EINVAL;
/* Short circuit: if the signal watcher is already watching {signum} don't
* go through the process of deregistering and registering the handler.
* Additionally, this avoids pending signals getting lost in the small time
* time frame that handle->signum == 0.
@@ -308,15 +313,14 @@
/* If at this point there are no active signal watchers for this signum (in
* any of the loops), it's time to try and register a handler for it here.
*/
if (uv__signal_first_handle(signum) == NULL) {
- uv_err_t err = uv__signal_register_handler(signum);
- if (err.code != UV_OK) {
+ err = uv__signal_register_handler(signum);
+ if (err) {
/* Registering the signal handler failed. Must be an invalid signal. */
- handle->loop->last_err = err;
uv__signal_unlock_and_unblock(&saved_sigmask);
- return -1;
+ return err;
}
}
handle->signum = signum;
RB_INSERT(uv__signal_tree_s, &uv__signal_tree, handle);