g_file_monitor should signal error when maximum number of watches has been reached
Submitted by Tassilo
Emacs now has the possibility to place watches on files and directories to get notified when they change. It can do that on GNU/Linux systems either with plain inotify or via glib's GFileMonitor (which uses inotify under the hoods, too, at least on my system). In the latter case, there is the problem that g_file_monitor doesn't signal an error when the limit of watches a user may place is reached.
Here's a receipe:
As root, execute "sysctl fs.inotify.max_user_watches=0" to set the maximum number of watches a user is allowed to set to 0.
Validate that this setting works: $ inotifywait . Setting up watches. Failed to watch .; upper limit on inotify watches reached! Please increase the amount of inotify watches allowed per user via `/proc/sys/fs/inotify/max_user_watches'.
Now the following glib api call
GError *err = NULL; monitor = g_file_monitor (gfile, gflags, NULL, &err);
still returns a GFileMonitor and err won't be set. According to the docs, it should return NULL and set err in case of any error. And IMHO, reaching the limit is an error.
There is no way to figure out that the GFileMonitor won't work. It just looks like the watched file or directory never changes although it does.
I've had a brief look at the glib code and it seems that the error is at least considered in the low-level gio/inotify/*.c code but somehow is lost somewhere.
This is the bug about the issue I've filed for Emacs: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=21241