Subject: Re: bug#21337: 25.0.50; inotify error message

From: Eli Zaretskii <[email-masked]>
Date: Mon, 24 Aug 2015 22:36:02 +0300

> From: Robert Pluim <[email-masked]>
> Cc: [email-masked]
> Date: Mon, 24 Aug 2015 20:32:59 +0200
> 
> 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.

Can you see which code causes these 22 calls for the same 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.

That's strange, isn't it?  If to_read is zero, how come pselect
indicated that FD has stuff to be read?

> (what does xmalloc do when its argument is 0?)

Nothing, usually.

> 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.

Exactly.

Could it be that we are somehow trying to read the same event 22
times, and then only the 1st time succeeds?

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

The important question is, IMO, how come pselect says this FD is ready
to be read, when there's nothing to be read.

Btw, it would be nice to have errno description added to the error
message.

Thanks.