summaryrefslogtreecommitdiff
path: root/src/kqueue.c
diff options
context:
space:
mode:
authorMichael Albinus <michael.albinus@gmx.de>2016-03-04 14:01:36 +0000
committerMichael Albinus <michael.albinus@gmx.de>2016-03-04 14:01:36 +0000
commit484967796755051c4045cdcc26b0d3d129cc72ad (patch)
treec2fc0747c640beb5f6056494728e775bf9c20883 /src/kqueue.c
parentca4e30058eba0531f38fff75f14734acffab84ea (diff)
downloademacs-484967796755051c4045cdcc26b0d3d129cc72ad.tar.gz
emacs-484967796755051c4045cdcc26b0d3d129cc72ad.tar.bz2
emacs-484967796755051c4045cdcc26b0d3d129cc72ad.zip
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 <sys/resource.h>. (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.
Diffstat (limited to 'src/kqueue.c')
-rw-r--r--src/kqueue.c24
1 files changed, 23 insertions, 1 deletions
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 <http://www.gnu.org/licenses/>. */
#include "keyboard.h"
#include "process.h"
+#ifdef HAVE_SYS_RESOURCE_H
+#include <sys/resource.h>
+#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. */