Subject: bug#21337: 25.0.50; inotify error message

From: Robert Pluim <[email-masked]>
Date: Mon, 24 Aug 2015 20:32:59 +0200

Eli Zaretskii <[email-masked]> writes:

>
> Strange.  Does auto-revert-mode work in "emacs -Q"?  Do the related
> tests in the test suite pass?
>

Yes and yes.

> Can you use strace to see what error is that and what directory is
> being watched?

strace indicates that the directory where emacs is being run from is
being watched, along with my home directory plus any directories
containing files that are being visited. What's strange is that
inotify_add_watch is being called 22 times for the current directory.

I've debugged inotify_callback a little. The expectation of this code

  to_read = 0;
  if (ioctl (fd, FIONREAD, &to_read) == -1)
    xsignal1
      (Qfile_notify_error,
       build_string ("Error while trying to retrieve file system events"));
  buffer = xmalloc (to_read);
  n = read (fd, buffer, to_read);
  if (n < 0)
    {

is that the read will succeed, however to_read is very often 0, so
it's not surprising the read fails. (what does xmalloc do when its
argument is 0?)

My understanding was that the callback should only be called when
there are actual inotify events to process, so this behaviour is
somewhat surprising to me.

I can add in skipping the read if to_read == 0, but I suspect that's
just papering over the cracks.

Regards

Robert