X-Git-Url: http://git.archive.openwrt.org/?p=project%2Flibubox.git;a=blobdiff_plain;f=uloop.c;h=8517366a55f19154b25a67dd21ce1e08f09e1589;hp=f5032418ed6697bf5035cbe3cdedf1c3ff85880b;hb=bb0c830b2a259b7c5ffa7c309ce9d3004f3c41a1;hpb=368fd2645878edadc72c60948d1f19c6769751d6 diff --git a/uloop.c b/uloop.c index f503241..8517366 100644 --- a/uloop.c +++ b/uloop.c @@ -58,6 +58,7 @@ static struct list_head processes = LIST_HEAD_INIT(processes); static int poll_fd = -1; bool uloop_cancelled = false; +bool uloop_handle_sigchld = true; static int uloop_status = 0; static bool do_sigchld = false; @@ -116,6 +117,8 @@ static int waker_init(void) return 0; } +static void uloop_setup_signals(bool add); + int uloop_init(void) { if (uloop_init_pollfd() < 0) @@ -126,6 +129,8 @@ int uloop_init(void) return -1; } + uloop_setup_signals(true); + return 0; } @@ -462,7 +467,9 @@ static void uloop_setup_signals(bool add) uloop_install_handler(SIGINT, uloop_handle_sigint, &old_sigint, add); uloop_install_handler(SIGTERM, uloop_handle_sigint, &old_sigterm, add); - uloop_install_handler(SIGCHLD, uloop_sigchld, &old_sigchld, add); + + if (uloop_handle_sigchld) + uloop_install_handler(SIGCHLD, uloop_sigchld, &old_sigchld, add); uloop_ignore_signal(SIGPIPE, add); } @@ -525,12 +532,7 @@ int uloop_run_timeout(int timeout) int next_time = 0; struct timeval tv; - /* - * Handlers are only updated for the first call to uloop_run() (and restored - * when this call is done). - */ - if (!uloop_run_depth++) - uloop_setup_signals(true); + uloop_run_depth++; uloop_status = 0; uloop_cancelled = false; @@ -548,19 +550,20 @@ int uloop_run_timeout(int timeout) uloop_gettime(&tv); next_time = uloop_get_next_timeout(&tv); - if (timeout > 0 && next_time < timeout) - timeout = next_time; - uloop_run_events(timeout); + if (timeout >= 0 && timeout < next_time) + next_time = timeout; + uloop_run_events(next_time); } - if (!--uloop_run_depth) - uloop_setup_signals(false); + --uloop_run_depth; return uloop_status; } void uloop_done(void) { + uloop_setup_signals(false); + if (poll_fd >= 0) { close(poll_fd); poll_fd = -1;