diff options
Diffstat (limited to 'src/kqueue.c')
-rw-r--r-- | src/kqueue.c | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/src/kqueue.c b/src/kqueue.c index 49ca0c95e27..8ebd132fdc3 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; @@ -364,9 +368,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); @@ -379,6 +386,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. */ @@ -469,7 +491,7 @@ WATCH-DESCRIPTOR should be an object returned by `kqueue-add-watch'. */) } DEFUN ("kqueue-valid-p", Fkqueue_valid_p, Skqueue_valid_p, 1, 1, 0, - doc: /* "Check a watch specified by its WATCH-DESCRIPTOR. + doc: /* Check a watch specified by its WATCH-DESCRIPTOR. WATCH-DESCRIPTOR should be an object returned by `kqueue-add-watch'. |