… | |
… | |
811 | fd_intern (evpipe [1]); |
811 | fd_intern (evpipe [1]); |
812 | |
812 | |
813 | ev_io_set (&pipeev, evpipe [0], EV_READ); |
813 | ev_io_set (&pipeev, evpipe [0], EV_READ); |
814 | ev_io_start (EV_A_ &pipeev); |
814 | ev_io_start (EV_A_ &pipeev); |
815 | ev_unref (EV_A); /* watcher should not keep loop alive */ |
815 | ev_unref (EV_A); /* watcher should not keep loop alive */ |
816 | |
|
|
817 | /* in case we received the signal before we had the chance of installing a handler */ |
|
|
818 | ev_feed_event (EV_A_ &pipeev, 0); |
|
|
819 | } |
816 | } |
820 | } |
817 | } |
821 | |
818 | |
822 | void inline_size |
819 | void inline_size |
823 | evpipe_write (EV_P_ int sig, int async) |
820 | evpipe_write (EV_P_ EV_ATOMIC_T *flag) |
824 | { |
821 | { |
825 | if (!(gotasync || gotsig)) |
822 | if (!*flag) |
826 | { |
823 | { |
827 | int old_errno = errno; /* save errno becaue write might clobber it */ |
824 | int old_errno = errno; /* save errno because write might clobber it */ |
828 | |
825 | |
829 | if (sig) gotsig = 1; |
826 | *flag = 1; |
830 | if (async) gotasync = 1; |
|
|
831 | |
|
|
832 | write (evpipe [1], &old_errno, 1); |
827 | write (evpipe [1], &old_errno, 1); |
833 | |
828 | |
834 | errno = old_errno; |
829 | errno = old_errno; |
835 | } |
830 | } |
836 | } |
831 | } |
… | |
… | |
881 | #if _WIN32 |
876 | #if _WIN32 |
882 | signal (signum, sighandler); |
877 | signal (signum, sighandler); |
883 | #endif |
878 | #endif |
884 | |
879 | |
885 | signals [signum - 1].gotsig = 1; |
880 | signals [signum - 1].gotsig = 1; |
886 | evpipe_write (EV_A_ 1, 0); |
881 | evpipe_write (EV_A_ &gotsig); |
887 | } |
882 | } |
888 | |
883 | |
889 | void noinline |
884 | void noinline |
890 | ev_feed_signal_event (EV_P_ int signum) |
885 | ev_feed_signal_event (EV_P_ int signum) |
891 | { |
886 | { |
… | |
… | |
917 | #ifndef WIFCONTINUED |
912 | #ifndef WIFCONTINUED |
918 | # define WIFCONTINUED(status) 0 |
913 | # define WIFCONTINUED(status) 0 |
919 | #endif |
914 | #endif |
920 | |
915 | |
921 | void inline_speed |
916 | void inline_speed |
922 | child_reap (EV_P_ ev_signal *sw, int chain, int pid, int status) |
917 | child_reap (EV_P_ int chain, int pid, int status) |
923 | { |
918 | { |
924 | ev_child *w; |
919 | ev_child *w; |
925 | int traced = WIFSTOPPED (status) || WIFCONTINUED (status); |
920 | int traced = WIFSTOPPED (status) || WIFCONTINUED (status); |
926 | |
921 | |
927 | for (w = (ev_child *)childs [chain & (EV_PID_HASHSIZE - 1)]; w; w = (ev_child *)((WL)w)->next) |
922 | for (w = (ev_child *)childs [chain & (EV_PID_HASHSIZE - 1)]; w; w = (ev_child *)((WL)w)->next) |
928 | { |
923 | { |
929 | if ((w->pid == pid || !w->pid) |
924 | if ((w->pid == pid || !w->pid) |
930 | && (!traced || (w->flags & 1))) |
925 | && (!traced || (w->flags & 1))) |
931 | { |
926 | { |
932 | ev_set_priority (w, ev_priority (sw)); /* need to do it *now* */ |
927 | ev_set_priority (w, EV_MAXPRI); /* need to do it *now*, this *must* be the same prio as the signal watcher itself */ |
933 | w->rpid = pid; |
928 | w->rpid = pid; |
934 | w->rstatus = status; |
929 | w->rstatus = status; |
935 | ev_feed_event (EV_A_ (W)w, EV_CHILD); |
930 | ev_feed_event (EV_A_ (W)w, EV_CHILD); |
936 | } |
931 | } |
937 | } |
932 | } |
… | |
… | |
951 | if (!WCONTINUED |
946 | if (!WCONTINUED |
952 | || errno != EINVAL |
947 | || errno != EINVAL |
953 | || 0 >= (pid = waitpid (-1, &status, WNOHANG | WUNTRACED))) |
948 | || 0 >= (pid = waitpid (-1, &status, WNOHANG | WUNTRACED))) |
954 | return; |
949 | return; |
955 | |
950 | |
956 | /* make sure we are called again until all childs have been reaped */ |
951 | /* make sure we are called again until all children have been reaped */ |
957 | /* we need to do it this way so that the callback gets called before we continue */ |
952 | /* we need to do it this way so that the callback gets called before we continue */ |
958 | ev_feed_event (EV_A_ (W)sw, EV_SIGNAL); |
953 | ev_feed_event (EV_A_ (W)sw, EV_SIGNAL); |
959 | |
954 | |
960 | child_reap (EV_A_ sw, pid, pid, status); |
955 | child_reap (EV_A_ pid, pid, status); |
961 | if (EV_PID_HASHSIZE > 1) |
956 | if (EV_PID_HASHSIZE > 1) |
962 | child_reap (EV_A_ sw, 0, pid, status); /* this might trigger a watcher twice, but feed_event catches that */ |
957 | child_reap (EV_A_ 0, pid, status); /* this might trigger a watcher twice, but feed_event catches that */ |
963 | } |
958 | } |
964 | |
959 | |
965 | #endif |
960 | #endif |
966 | |
961 | |
967 | /*****************************************************************************/ |
962 | /*****************************************************************************/ |
… | |
… | |
1221 | #endif |
1216 | #endif |
1222 | |
1217 | |
1223 | if (ev_is_active (&pipeev)) |
1218 | if (ev_is_active (&pipeev)) |
1224 | { |
1219 | { |
1225 | /* this "locks" the handlers against writing to the pipe */ |
1220 | /* this "locks" the handlers against writing to the pipe */ |
|
|
1221 | /* while we modify the fd vars */ |
|
|
1222 | gotsig = 1; |
|
|
1223 | #if EV_ASYNC_ENABLE |
1226 | gotsig = gotasync = 1; |
1224 | gotasync = 1; |
|
|
1225 | #endif |
1227 | |
1226 | |
1228 | ev_ref (EV_A); |
1227 | ev_ref (EV_A); |
1229 | ev_io_stop (EV_A_ &pipeev); |
1228 | ev_io_stop (EV_A_ &pipeev); |
1230 | close (evpipe [0]); |
1229 | close (evpipe [0]); |
1231 | close (evpipe [1]); |
1230 | close (evpipe [1]); |
… | |
… | |
2467 | |
2466 | |
2468 | void |
2467 | void |
2469 | ev_async_send (EV_P_ ev_async *w) |
2468 | ev_async_send (EV_P_ ev_async *w) |
2470 | { |
2469 | { |
2471 | w->sent = 1; |
2470 | w->sent = 1; |
2472 | evpipe_write (EV_A_ 0, 1); |
2471 | evpipe_write (EV_A_ &gotasync); |
2473 | } |
2472 | } |
2474 | #endif |
2473 | #endif |
2475 | |
2474 | |
2476 | /*****************************************************************************/ |
2475 | /*****************************************************************************/ |
2477 | |
2476 | |