aboutsummaryrefslogtreecommitdiffstats
path: root/src/kqueue.c
diff options
context:
space:
mode:
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/>. */
29#include "keyboard.h" 29#include "keyboard.h"
30#include "process.h" 30#include "process.h"
31 31
32#ifdef HAVE_SYS_RESOURCE_H
33#include <sys/resource.h>
34#endif /* HAVE_SYS_RESOURCE_H */
35
32 36
33/* File handle for kqueue. */ 37/* File handle for kqueue. */
34static int kqueuefd = -1; 38static int kqueuefd = -1;
@@ -368,9 +372,12 @@ only when the upper directory of the renamed file is watched. */)
368 (Lisp_Object file, Lisp_Object flags, Lisp_Object callback) 372 (Lisp_Object file, Lisp_Object flags, Lisp_Object callback)
369{ 373{
370 Lisp_Object watch_object, dir_list; 374 Lisp_Object watch_object, dir_list;
371 int fd, oflags; 375 int maxfd, fd, oflags;
372 u_short fflags = 0; 376 u_short fflags = 0;
373 struct kevent kev; 377 struct kevent kev;
378#ifdef HAVE_GETRLIMIT
379 struct rlimit rlim;
380#endif /* HAVE_GETRLIMIT */
374 381
375 /* Check parameters. */ 382 /* Check parameters. */
376 CHECK_STRING (file); 383 CHECK_STRING (file);
@@ -383,6 +390,21 @@ only when the upper directory of the renamed file is watched. */)
383 if (! FUNCTIONP (callback)) 390 if (! FUNCTIONP (callback))
384 wrong_type_argument (Qinvalid_function, callback); 391 wrong_type_argument (Qinvalid_function, callback);
385 392
393 /* Check available file descriptors. */
394#ifdef HAVE_GETRLIMIT
395 if (! getrlimit (RLIMIT_NOFILE, &rlim))
396 maxfd = rlim.rlim_cur;
397 else
398#endif /* HAVE_GETRLIMIT */
399 maxfd = 256;
400
401 /* We assume 50 file descriptors are sufficient for the rest of Emacs. */
402 if ((maxfd - 50) < XINT (Flength (watch_list)))
403 xsignal2
404 (Qfile_notify_error,
405 build_string ("File watching not possible, no file descriptor left"),
406 Flength (watch_list));
407
386 if (kqueuefd < 0) 408 if (kqueuefd < 0)
387 { 409 {
388 /* Create kqueue descriptor. */ 410 /* Create kqueue descriptor. */