+static void
+sighandler (int signum)
+{
+ signals [signum - 1].gotsig = 1;
+
+ if (!gotsig)
+ {
+ int old_errno = errno;
+ gotsig = 1;
+ write (sigpipe [1], &signum, 1);
+ errno = old_errno;
+ }
+}
+
+static void
+sigcb (struct ev_io *iow, int revents)
+{
+ struct ev_signal *w;
+ int signum;
+
+ read (sigpipe [0], &revents, 1);
+ gotsig = 0;
+
+ for (signum = signalmax; signum--; )
+ if (signals [signum].gotsig)
+ {
+ signals [signum].gotsig = 0;
+
+ for (w = signals [signum].head; w; w = w->next)
+ event ((W)w, EV_SIGNAL);
+ }
+}
+
+static void
+siginit (void)
+{
+#ifndef WIN32
+ fcntl (sigpipe [0], F_SETFD, FD_CLOEXEC);
+ fcntl (sigpipe [1], F_SETFD, FD_CLOEXEC);
+
+ /* rather than sort out wether we really need nb, set it */
+ fcntl (sigpipe [0], F_SETFL, O_NONBLOCK);
+ fcntl (sigpipe [1], F_SETFL, O_NONBLOCK);
+#endif
+
+ ev_io_set (&sigev, sigpipe [0], EV_READ);
+ ev_io_start (&sigev);
+}
+
+/*****************************************************************************/
+
+static struct ev_idle **idles;
+static int idlemax, idlecnt;
+
+static struct ev_prepare **prepares;
+static int preparemax, preparecnt;
+
+static struct ev_check **checks;
+static int checkmax, checkcnt;
+
+/*****************************************************************************/
+
+static struct ev_child *childs [PID_HASHSIZE];
+static struct ev_signal childev;
+
+#ifndef WIN32
+
+#ifndef WCONTINUED
+# define WCONTINUED 0
+#endif
+
+static void
+child_reap (struct ev_signal *sw, int chain, int pid, int status)
+{
+ struct ev_child *w;
+
+ for (w = childs [chain & (PID_HASHSIZE - 1)]; w; w = w->next)
+ if (w->pid == pid || !w->pid)
+ {
+ w->priority = sw->priority; /* need to do it *now* */
+ w->rpid = pid;
+ w->rstatus = status;
+ printf ("rpid %p %d %d\n", w, pid, w->pid);//D
+ event ((W)w, EV_CHILD);
+ }
+}
+
+static void
+childcb (struct ev_signal *sw, int revents)
+{
+ int pid, status;
+
+ printf ("chld %x\n", revents);//D
+ if (0 < (pid = waitpid (-1, &status, WNOHANG | WUNTRACED | WCONTINUED)))
+ {
+ /* make sure we are called again until all childs have been reaped */
+ event ((W)sw, EV_SIGNAL);
+
+ child_reap (sw, pid, pid, status);
+ child_reap (sw, 0, pid, status); /* this might trigger a watcher twice, but event catches that */
+ }
+}
+
+#endif
+
+/*****************************************************************************/
+
+#if EV_USE_KQUEUE
+# include "ev_kqueue.c"
+#endif
+#if EV_USE_EPOLL