+slots_log(Slot *head)
+{
+ Slot *s = head;
+
+ for (; s; s = s->next) {
+ slot_log(s);
+ }
+}
+
+void
+slots_assert_fifos_exist(Slot *s)
+{
+ struct stat st;
+ int errors = 0;
+
+ for (; s; s = s->next) {
+ if (lstat(s->in_fifo, &st) < 0) {
+ khlib_error(
+ "Cannot stat \"%s\". Error: %s\n",
+ s->in_fifo,
+ strerror(errno)
+ );
+ errors++;
+ continue;
+ }
+ if (!(st.st_mode & S_IFIFO)) {
+ khlib_error("\"%s\" is not a FIFO\n", s->in_fifo);
+ errors++;
+ continue;
+ }
+ }
+ if (errors)
+ khlib_fatal(
+ "Encountered errors with given file paths. See log.\n"
+ );
+}
+
+void
+slot_close(Slot *s)
+{
+ close(s->in_fd);
+ s->in_fd = -1;
+ s->out_pos_cur = s->out_pos_lo;
+}
+
+void
+slots_close(Slot *s)
+{
+ for (; s; s = s->next)
+ if (s->in_fd > -1)
+ slot_close(s);
+}
+
+
+void
+slot_expire(Slot *s, struct timespec t, char expiry_character, char *buf)
+{
+ struct timespec td;
+
+ timespecsub(&t, &(s->in_last_read), &td);
+ if (timespeccmp(&td, &(s->out_ttl), >=)) {
+ memset(
+ buf + s->out_pos_lo,
+ expiry_character,
+ s->out_width
+ );
+ khlib_warn("Slot expired: \"%s\"\n", s->in_fifo);
+ }
+}
+
+void
+slot_set_error(Slot *s, char *buf)
+{
+ char *b;
+ int i;
+
+ s->in_fd = -1;
+ b = buf + s->out_pos_lo;
+ /* Copy as much of the error message as possible.
+ * EXCLUDING the terminating \0. */
+ for (i = 0; i < errlen && i < s->out_width; i++)
+ b[i] = errmsg[i];
+ /* Any remaining positions: */
+ memset(b + i, '_', s->out_width - i);
+}
+
+enum read_status
+slot_read(Slot *s, char *buf)
+{
+ char c; /* Character read. */
+ int r; /* Remaining unused positions in buffer range. */
+
+ for (;;) {
+ switch (read(s->in_fd, &c, 1)) {
+ case -1:
+ khlib_error(
+ "Failed to read: \"%s\". errno: %d, msg: %s\n",
+ s->in_fifo,
+ errno,
+ strerror(errno)
+ );
+ switch (errno) {
+ case EINTR:
+ case EAGAIN:
+ return RETRY;
+ default:
+ return FAILURE;
+ }
+ case 0:
+ khlib_debug("%s: End of FILE\n", s->in_fifo);
+ s->out_pos_cur = s->out_pos_lo;
+ return END_OF_FILE;
+ case 1:
+ /* TODO: Consider making msg term char a CLI option */
+ if (c == '\n' || c == '\0') {
+ r = (s->out_pos_hi - s->out_pos_cur) + 1;
+ if (r > 0)
+ memset(buf + s->out_pos_cur, ' ', r);
+ return END_OF_MESSAGE;
+ } else {
+ if (s->out_pos_cur <= s->out_pos_hi)
+ buf[s->out_pos_cur++] = c;
+ else
+ /*
+ * Force EOM beyond available range.
+ * To ensure that a rogue large message
+ * doesn't trap us here needlessly
+ * long.
+ */
+ return END_OF_MESSAGE;
+ }
+ break;
+ default:
+ assert(0);
+ }
+ }
+}
+
+void
+slots_read(Config *cfg, struct timespec *ti, char *buf)