I am using inotify in a program written in C; it closely follows the example in man 7 inotify. The steps are essentially:

/* setup */
int fd = inotify_init1(IN_NONBLOCK);
int wd = inotify_add_watch(fd, path, IN_CLOSE_WRITE);
struct pollfd fds[1];
fds[0].fd = fd;
fds[0].events = POLLIN;

/* within main loop */
int poll_num = poll(fds, 1, 0);
if (poll_num == -1) { /* error handling */ }
else if (poll_num>0) {
    if (fds[0].revents & POLLERR ||
        fds[0].revents & POLLHUP ||
        fds[0].revents & POLLNVAL) { /* error handling */ }
    if (fds[0].revents & POLLIN) { /* read events */ }

While reading events, the event mask is checked for queue overflow (IN_Q_OVERFLOW), filesystem unmounting (IN_UNMOUNT), and other problems (IN_IGNORED). None of these conditions (nor POLLERR, POLLHUP, etc.) ever occur.

This works well for a while (usually for run times of a day or two). Then, for no apparent reason, inotify stops reporting events. The rest of my program continues to run without any problems, but it no longer receives any events from inotify. I'm not sure how to debug this, since I believe I am checking all the relevant error conditions. The watched file is still in place and has the same inode as it had when inotify was set up to monitor it.

What would cause inotify to stop reporting events without generating any errors in a program?

  • Have you verified that the file hasn’t been logrotate’d? – G-Man Says 'Reinstate Monica' Nov 16 at 1:17
  • @G-ManSays'ReinstateMonica': Yes, the file is not subject to logrotate, but thanks for the suggestion. – user001 Nov 18 at 0:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.