+ while (!should_quit) {
+ pollfd fds[2];
+ fds[0].fd = inotify_fd;
+ fds[0].events = POLLIN;
+ fds[0].revents = 0;
+ fds[1].fd = should_quit_fd;
+ fds[1].events = POLLIN;
+ fds[1].revents = 0;
+
+ int ret = poll(fds, 2, -1);
+ if (ret == -1) {
+ if (errno == EINTR) {
+ continue;
+ } else {
+ perror("poll(inotify_fd)");
+ return;
+ }
+ }
+ if (ret == 0) {
+ continue;
+ }
+
+ if (fds[1].revents) break; // should_quit_fd asserted.
+
+ ret = read(inotify_fd, buf.get(), size);
+ if (ret == -1) {
+ if (errno == EINTR) {
+ continue;
+ } else {
+ perror("read(inotify_fd)");
+ close(watch_fd);
+ close(inotify_fd);
+ return;
+ }
+ }