113 | 113 |
int n_files;
|
114 | 114 |
int i;
|
115 | 115 |
struct kevent evSet;
|
|
116 |
long open_max;
|
116 | 117 |
|
117 | 118 |
if ((*test_runner_main))
|
118 | 119 |
return(test_runner_main(argc, argv));
|
|
163 | 164 |
max_watches = (rlim_t)fs_sysctl(INOTIFY_MAX_USER_WATCHES);
|
164 | 165 |
if(max_watches > 0) {
|
165 | 166 |
rl.rlim_cur = max_watches;
|
|
167 |
open_max = max_watches;
|
166 | 168 |
goto rlim_set;
|
167 | 169 |
}
|
168 | 170 |
#endif
|
169 | 171 |
/* raise soft limit */
|
170 | |
rl.rlim_cur = min((rlim_t)sysconf(_SC_OPEN_MAX), rl.rlim_max);
|
|
172 |
open_max = min(sysconf(_SC_OPEN_MAX), (long)rl.rlim_max);
|
|
173 |
if (open_max == -1)
|
|
174 |
err(1, "_SC_OPEN_MAX");
|
|
175 |
|
|
176 |
open_max = min(524288, open_max); /* guard against unrealistic replies */
|
|
177 |
|
|
178 |
rl.rlim_cur = (rlim_t)open_max;
|
171 | 179 |
if (setrlimit(RLIMIT_NOFILE, &rl) != 0)
|
172 | |
err(1, "setrlimit cannot set rlim_cur to %d", (int)rl.rlim_cur);
|
|
180 |
err(1, "setrlimit cannot set rlim_cur to %ld", open_max);
|
173 | 181 |
|
174 | 182 |
rlim_set:
|
175 | 183 |
|
|
180 | 188 |
setenv("SHELL", "/bin/sh", 0);
|
181 | 189 |
|
182 | 190 |
/* sequential scan may depend on a 0 at the end */
|
183 | |
files = calloc(rl.rlim_cur+1, sizeof(WatchFile *));
|
|
191 |
files = calloc(open_max+1, sizeof(WatchFile *));
|
184 | 192 |
|
185 | 193 |
if ((kq = kqueue()) == -1)
|
186 | 194 |
err(1, "cannot create kqueue");
|
|
190 | 198 |
usage();
|
191 | 199 |
|
192 | 200 |
/* read input and populate watch list, skipping non-regular files */
|
193 | |
n_files = process_input(stdin, files, rl.rlim_cur);
|
|
201 |
n_files = process_input(stdin, files, open_max);
|
194 | 202 |
if (n_files == 0)
|
195 | 203 |
errx(1, "No regular files to watch");
|
196 | 204 |
if (n_files == -1)
|
197 | 205 |
errx(1, "Too many files listed; the hard limit for your login"
|
198 | |
" class is %d. Please consult"
|
199 | |
" http://eradman.com/entrproject/limits.html", (int)rl.rlim_cur);
|
|
206 |
" class is %ld. Please consult"
|
|
207 |
" http://eradman.com/entrproject/limits.html", open_max);
|
200 | 208 |
for (i=0; i<n_files; i++)
|
201 | 209 |
watch_file(kq, files[i]);
|
202 | 210 |
|
|
364 | 372 |
aggressive_opt = 1;
|
365 | 373 |
break;
|
366 | 374 |
case 'c':
|
367 | |
clear_opt = 1;
|
|
375 |
clear_opt = clear_opt ? 2 : 1;
|
368 | 376 |
break;
|
369 | 377 |
case 'd':
|
370 | 378 |
dirwatch_opt = 1;
|
|
453 | 461 |
err(1, "can't fork");
|
454 | 462 |
|
455 | 463 |
if (pid == 0) {
|
|
464 |
/* 2J - erase the entire display
|
|
465 |
* 3J - clear scrollback buffer
|
|
466 |
* H - set cursor position to the default
|
|
467 |
*/
|
456 | 468 |
if (clear_opt == 1)
|
457 | |
system("/usr/bin/clear");
|
|
469 |
printf("\033[2J\033[H");
|
|
470 |
if (clear_opt == 2)
|
|
471 |
printf("\033[2J\033[3J\033[H");
|
|
472 |
fflush(stdout);
|
|
473 |
|
458 | 474 |
/* Set process group so subprocess can be signaled */
|
459 | 475 |
if (restart_opt == 1) {
|
460 | 476 |
setpgid(0, getpid());
|