Browse Source

Set a maximum of 2^19 watches

Guard against absurd limits; on MacOS 11.1 may be 2**63-1.
pull/68/head
Eric Radman 3 weeks ago
parent
commit
8f224fb453
3 changed files with 18 additions and 7 deletions
  1. +1
    -1
      Makefile.bsd
  2. +4
    -0
      NEWS
  3. +13
    -6
      entr.c

+ 1
- 1
Makefile.bsd View File

@ -1,6 +1,6 @@
PREFIX ?= /usr/local
MANPREFIX ?= ${PREFIX}/man
RELEASE = 4.7
RELEASE = 4.8
CPPFLAGS += -DRELEASE=\"${RELEASE}\"
all: versioncheck entr


+ 4
- 0
NEWS View File

@ -1,3 +1,7 @@
= Next Release: 4.8
- Set a maximum of 2^19 watches to guard against absurd file open limits
= Release History
== 4.7: January 29, 2021


+ 13
- 6
entr.c View File

@ -114,6 +114,7 @@ main(int argc, char *argv[]) {
int n_files;
int i;
struct kevent evSet;
long open_max;
if ((*test_runner_main))
return(test_runner_main(argc, argv));
@ -168,9 +169,15 @@ main(int argc, char *argv[]) {
}
#endif
/* raise soft limit */
rl.rlim_cur = min((rlim_t)sysconf(_SC_OPEN_MAX), rl.rlim_max);
open_max = min(sysconf(_SC_OPEN_MAX), (long)rl.rlim_max);
if (open_max == -1)
err(1, "_SC_OPEN_MAX");
open_max = min(524288, open_max); /* guard against unrealistic replies */
rl.rlim_cur = (rlim_t)open_max;
if (setrlimit(RLIMIT_NOFILE, &rl) != 0)
err(1, "setrlimit cannot set rlim_cur to %d", (int)rl.rlim_cur);
err(1, "setrlimit cannot set rlim_cur to %ld", open_max);
rlim_set:
@ -181,7 +188,7 @@ rlim_set:
setenv("SHELL", "/bin/sh", 0);
/* sequential scan may depend on a 0 at the end */
files = calloc(rl.rlim_cur+1, sizeof(WatchFile *));
files = calloc(open_max+1, sizeof(WatchFile *));
if ((kq = kqueue()) == -1)
err(1, "cannot create kqueue");
@ -191,13 +198,13 @@ rlim_set:
usage();
/* read input and populate watch list, skipping non-regular files */
n_files = process_input(stdin, files, rl.rlim_cur);
n_files = process_input(stdin, files, open_max);
if (n_files == 0)
errx(1, "No regular files to watch");
if (n_files == -1)
errx(1, "Too many files listed; the hard limit for your login"
" class is %d. Please consult"
" http://eradman.com/entrproject/limits.html", (int)rl.rlim_cur);
" class is %ld. Please consult"
" http://eradman.com/entrproject/limits.html", open_max);
for (i=0; i<n_files; i++)
watch_file(kq, files[i]);


Loading…
Cancel
Save