+ /* TODO: Consider backing off retries for failed fifos. */
+ error("Failed to open \"%s\"\n", f->name);
+ fifo_read_error(f, buf);
+ continue;
+ }
+ if (f->fd > maxfd)
+ maxfd = f->fd;
+ FD_SET(f->fd, &fds);
+ }
+ debug("selecting...\n");
+ ready = select(maxfd + 1, &fds, NULL, NULL, NULL);
+ debug("ready: %d\n", ready);
+ assert(ready != 0);
+ if (ready < 0)
+ fatal("%s", strerror(errno));
+ for (Fifo *f = cfg->fifos; f; f = f->next) {
+ if (FD_ISSET(f->fd, &fds)) {
+ debug("reading: %s\n", f->name);
+ fifo_read_one(f, buf, cfg);
+ }
+ }
+}
+
+void
+snooze(struct timespec *t, Config *cfg)
+{
+ struct timespec remainder;
+ int result;
+
+ result = nanosleep(t, &remainder);
+
+ if (result < 0) {
+ if (errno == EINTR) {
+ warn(
+ "nanosleep interrupted. Remainder: "
+ "{ tv_sec = %ld, tv_nsec = %ld }",
+ remainder.tv_sec, remainder.tv_nsec);
+ /* No big deal if we occasionally sleep less,
+ * so not attempting to correct after an interruption.
+ */