-
- /* TODO: stat then check TTL */
- for (File *f = cfg->files; f; f = f->next) {
- debug("opening: %s\n", f->name);
- if (f->fd < 0)
- f->fd = open(f->name, O_RDONLY | O_NONBLOCK);
- if (f->fd == -1)
- /* TODO: Consider backing off retries for failed files. */
- fatal("Failed to open \"%s\"\n", f->name);
- if (f->fd > maxfd)
- maxfd = f->fd;
- FD_SET(f->fd, &fds);
+ for (s = cfg->slots; s; s = s->next) {
+ /* TODO: Create the FIFO if it doesn't already exist. */
+ if (lstat(s->in_fifo, &st) < 0) {
+ khlib_error(
+ "Cannot stat \"%s\". Error: %s\n",
+ s->in_fifo,
+ strerror(errno)
+ );
+ slot_read_error(s, buf);
+ continue;
+ }
+ if (!(st.st_mode & S_IFIFO)) {
+ khlib_error("\"%s\" is not a FIFO\n", s->in_fifo);
+ slot_read_error(s, buf);
+ continue;
+ }
+ if (s->in_fd < 0) {
+ khlib_debug(
+ "%s: closed. opening. in_fd: %d\n",
+ s->in_fifo,
+ s->in_fd
+ );
+ s->in_fd = open(s->in_fifo, O_RDONLY | O_NONBLOCK);
+ } else {
+ khlib_debug(
+ "%s: already openned. in_fd: %d\n",
+ s->in_fifo,
+ s->in_fd
+ );
+ }
+ if (s->in_fd == -1) {
+ /* TODO Consider backing off retries for failed slots */
+ khlib_error("Failed to open \"%s\"\n", s->in_fifo);
+ slot_read_error(s, buf);
+ continue;
+ }
+ khlib_debug("%s: open. in_fd: %d\n", s->in_fifo, s->in_fd);
+ if (s->in_fd > maxfd)
+ maxfd = s->in_fd;
+ FD_SET(s->in_fd, &fds);