From 484967796755051c4045cdcc26b0d3d129cc72ad Mon Sep 17 00:00:00 2001 From: Michael Albinus Date: Fri, 4 Mar 2016 14:01:36 +0000 Subject: Fix Bug#22814 * lisp/autorevert.el (global-auto-revert-mode): Do not set `auto-revert-use-notify' to nil. * etc/NEWS: Mention this. * etc/PROBLEMS: Remove problem Bug#22814. * src/kqueue.c: Include . (Fkqueue_add_watch): Limit the number of used file descriptors. (Bug#22814) * test/lisp/filenotify-tests.el (file-notify--test-remote-enabled) (file-notify-test00-availability, file-notify-test01-add-watch) (file-notify-test02-events, file-notify-test06-many-events): Use #' read syntax for functions. (file-notify-test05-dir-validity) (file-notify-test06-many-events): Simplify directory creation. (file-notify-test09-sufficient-ressources): New test. --- src/kqueue.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'src/kqueue.c') diff --git a/src/kqueue.c b/src/kqueue.c index a69d06da3ae..7e3bfdd5746 100644 --- a/src/kqueue.c +++ b/src/kqueue.c @@ -29,6 +29,10 @@ along with GNU Emacs. If not, see . */ #include "keyboard.h" #include "process.h" +#ifdef HAVE_SYS_RESOURCE_H +#include +#endif /* HAVE_SYS_RESOURCE_H */ + /* File handle for kqueue. */ static int kqueuefd = -1; @@ -368,9 +372,12 @@ only when the upper directory of the renamed file is watched. */) (Lisp_Object file, Lisp_Object flags, Lisp_Object callback) { Lisp_Object watch_object, dir_list; - int fd, oflags; + int maxfd, fd, oflags; u_short fflags = 0; struct kevent kev; +#ifdef HAVE_GETRLIMIT + struct rlimit rlim; +#endif /* HAVE_GETRLIMIT */ /* Check parameters. */ CHECK_STRING (file); @@ -383,6 +390,21 @@ only when the upper directory of the renamed file is watched. */) if (! FUNCTIONP (callback)) wrong_type_argument (Qinvalid_function, callback); + /* Check available file descriptors. */ +#ifdef HAVE_GETRLIMIT + if (! getrlimit (RLIMIT_NOFILE, &rlim)) + maxfd = rlim.rlim_cur; + else +#endif /* HAVE_GETRLIMIT */ + maxfd = 256; + + /* We assume 50 file descriptors are sufficient for the rest of Emacs. */ + if ((maxfd - 50) < XINT (Flength (watch_list))) + xsignal2 + (Qfile_notify_error, + build_string ("File watching not possible, no file descriptor left"), + Flength (watch_list)); + if (kqueuefd < 0) { /* Create kqueue descriptor. */ -- cgit v1.2.3