- } else {
- lseek(f->fd, 0, 0);
- ssize_t n = read(f->fd, buf + f->pos, f->width);
- int lasti = n + f->pos - 1;
- char lastc = buf[lasti];
- if (lastc == '\n')
- buf[lasti] = ' ';
+ 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 (File *f = cfg->files; f; f = f->next) {
+ if (FD_ISSET(f->fd, &fds)) {
+ debug("reading: %s\n", f->name);
+ read_one(f, buf);