+int uloop_process_delete(struct uloop_process *p)
+{
+ if (!p->pending)
+ return -1;
+
+ list_del(&p->list);
+ p->pending = false;
+
+ return 0;
+}
+
+static void uloop_handle_processes(void)
+{
+ struct uloop_process *p, *tmp;
+ pid_t pid;
+ int ret;
+
+ do_sigchld = false;
+
+ while (1) {
+ pid = waitpid(-1, &ret, WNOHANG);
+ if (pid < 0 && errno == EINTR)
+ continue;
+
+ if (pid <= 0)
+ return;
+
+ list_for_each_entry_safe(p, tmp, &processes, list) {
+ if (p->pid < pid)
+ continue;
+
+ if (p->pid > pid)
+ break;
+
+ uloop_process_delete(p);
+ p->cb(p, ret);
+ }
+ }
+
+}
+
+int uloop_interval_set(struct uloop_interval *timer, unsigned int msecs)
+{
+ return timer_register(timer, msecs);
+}
+
+int uloop_interval_cancel(struct uloop_interval *timer)
+{
+ return timer_remove(timer);
+}
+
+int64_t uloop_interval_remaining(struct uloop_interval *timer)
+{
+ return timer_next(timer);
+}
+
+static void uloop_signal_wake(int signo)
+{
+ uint8_t sigbyte = signo;
+
+ if (signo == SIGCHLD)
+ do_sigchld = true;
+
+ do {
+ if (write(waker_pipe, &sigbyte, 1) < 0) {
+ if (errno == EINTR)
+ continue;
+ }
+ break;
+ } while (1);
+}
+