+ {
+ base->head = 0;
+ base->gotsig = 0;
+ ++base;
+ }
+}
+
+static void
+sighandler (int signum)
+{
+ signals [signum - 1].gotsig = 1;
+
+ if (!gotsig)
+ {
+ gotsig = 1;
+ write (sigpipe [1], &gotsig, 1);
+ }
+}
+
+static void
+sigcb (struct ev_io *iow, int revents)
+{
+ struct ev_signal *w;
+ int sig;
+
+ gotsig = 0;
+ read (sigpipe [0], &revents, 1);
+
+ for (sig = signalmax; sig--; )
+ if (signals [sig].gotsig)
+ {
+ signals [sig].gotsig = 0;
+
+ for (w = signals [sig].head; w; w = w->next)
+ event ((W)w, EV_SIGNAL);
+ }
+}
+
+static void
+siginit (void)
+{
+ 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);
+
+ evio_set (&sigev, sigpipe [0], EV_READ);
+ evio_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 WCONTINUED
+# define WCONTINUED 0
+#endif
+
+static void
+childcb (struct ev_signal *sw, int revents)
+{
+ struct ev_child *w;
+ int pid, status;
+
+ while ((pid = waitpid (-1, &status, WNOHANG | WUNTRACED | WCONTINUED)) != -1)
+ for (w = childs [pid & (PID_HASHSIZE - 1)]; w; w = w->next)
+ if (w->pid == pid || w->pid == -1)
+ {
+ w->status = status;
+ event ((W)w, EV_CHILD);
+ }