72 | 72 |
WatchFile *leading_edge;
|
73 | 73 |
int child_pid;
|
74 | 74 |
|
|
75 |
int aggressive_opt;
|
75 | 76 |
int clear_opt;
|
76 | 77 |
int dirwatch_opt;
|
|
78 |
int noninteractive_opt;
|
|
79 |
int postpone_opt;
|
77 | 80 |
int restart_opt;
|
78 | |
int postpone_opt;
|
79 | 81 |
int shell_opt;
|
80 | |
int noninteractive_opt;
|
81 | 82 |
struct termios canonical_tty;
|
82 | 83 |
|
83 | 84 |
/* forwards */
|
|
126 | 127 |
xlist_dir = list_dir;
|
127 | 128 |
xtcsetattr = tcsetattr;
|
128 | 129 |
|
|
130 |
if (pledge("stdio rpath tty proc exec", NULL) == -1)
|
|
131 |
err(1, "pledge");
|
|
132 |
|
129 | 133 |
/* call usage() if no command is supplied */
|
130 | 134 |
if (argc < 2) usage();
|
131 | 135 |
argv_index = set_options(argv);
|
|
137 | 141 |
if (sigemptyset(&act.sa_mask) & (sigaction(SIGINT, &act, NULL) != 0))
|
138 | 142 |
err(1, "Failed to set SIGINT handler");
|
139 | 143 |
if (sigemptyset(&act.sa_mask) & (sigaction(SIGTERM, &act, NULL) != 0))
|
140 | |
err(1, "Failed to set TERM handler");
|
|
144 |
err(1, "Failed to set SIGTERM handler");
|
141 | 145 |
|
142 | 146 |
/* raise soft limit */
|
143 | 147 |
getrlimit(RLIMIT_NOFILE, &rl);
|
|
168 | 172 |
if (n_files == -1)
|
169 | 173 |
errx(1, "Too many files listed; the hard limit for your login"
|
170 | 174 |
" class is %d. Please consult"
|
171 | |
" http://entrproject.org/limits.html", (int)rl.rlim_cur);
|
|
175 |
" http://eradman.com/entrproject/limits.html", (int)rl.rlim_cur);
|
172 | 176 |
for (i=0; i<n_files; i++)
|
173 | 177 |
watch_file(kq, files[i]);
|
174 | 178 |
|
|
199 | 203 |
void
|
200 | 204 |
usage() {
|
201 | 205 |
fprintf(stderr, "release: %s\n", RELEASE);
|
202 | |
fprintf(stderr, "usage: entr [-cdnprs] utility [argument [/_] ...] < filenames\n");
|
|
206 |
fprintf(stderr, "usage: entr [-acdnprs] utility [argument [/_] ...] < filenames\n");
|
203 | 207 |
exit(1);
|
204 | 208 |
}
|
205 | 209 |
|
|
225 | 229 |
}
|
226 | 230 |
|
227 | 231 |
/*
|
228 | |
* Read lines from a file stream (normally STDIN)
|
229 | |
* Returns the number of regular files to be watched or -1 if max_files is
|
230 | |
* exceeded
|
|
232 |
* Read lines from a file stream (normally STDIN). Returns the number of
|
|
233 |
* regular files to be watched or -1 if max_files is exceeded.
|
231 | 234 |
*/
|
232 | 235 |
int
|
233 | 236 |
process_input(FILE *file, WatchFile *files[], int max_files) {
|
|
308 | 311 |
|
309 | 312 |
/* read arguments until we reach a command */
|
310 | 313 |
for (argc=1; argv[argc] != 0 && argv[argc][0] == '-'; argc++);
|
311 | |
while ((ch = getopt(argc, argv, "cdnprs")) != -1) {
|
|
314 |
while ((ch = getopt(argc, argv, "acdnprs")) != -1) {
|
312 | 315 |
switch (ch) {
|
|
316 |
case 'a':
|
|
317 |
aggressive_opt = 1;
|
|
318 |
break;
|
313 | 319 |
case 'c':
|
314 | 320 |
clear_opt = 1;
|
315 | 321 |
break;
|
|
440 | 446 |
else break;
|
441 | 447 |
}
|
442 | 448 |
if (file->fd == -1) {
|
|
449 |
warn("cannot open '%s'", file->fn);
|
443 | 450 |
terminate_utility();
|
444 | |
err(1, "cannot open '%s'", file->fn);
|
|
451 |
exit(1);
|
445 | 452 |
}
|
446 | 453 |
|
447 | 454 |
EV_SET(&evSet, file->fd, EVFILT_VNODE, EV_ADD | EV_CLEAR, NOTE_ALL, 0,
|
|
450 | 457 |
if (errno == ENOSPC)
|
451 | 458 |
errx(1, "Unable to allocate memory for kernel queue."
|
452 | 459 |
" Please consult"
|
453 | |
" http://entrproject.org/limits.html");
|
|
460 |
" http://eradman.com/entrproject/limits.html");
|
454 | 461 |
else
|
455 | 462 |
err(1, "failed to register VNODE event");
|
456 | 463 |
}
|
|
494 | 501 |
WatchFile *file;
|
495 | 502 |
int i;
|
496 | 503 |
struct timespec evTimeout = { 0, 1000000 };
|
497 | |
int reopen_only = 0;
|
|
504 |
int reopen_only = !aggressive_opt;
|
498 | 505 |
int collate_only = 0;
|
499 | 506 |
int do_exec = 0;
|
500 | 507 |
int dir_modified = 0;
|
|
516 | 523 |
|
517 | 524 |
main:
|
518 | 525 |
if (!noninteractive_opt)
|
519 | |
xtcsetattr(STDIN_FILENO, TCSADRAIN, &character_tty);
|
|
526 |
xtcsetattr(0, TCSADRAIN, &character_tty);
|
520 | 527 |
if ((reopen_only == 1) || (collate_only == 1)) {
|
521 | 528 |
nev = xkevent(kq, NULL, 0, evList, 32, &evTimeout);
|
522 | 529 |
}
|
|
631 | 638 |
if (do_exec == 1) {
|
632 | 639 |
do_exec = 0;
|
633 | 640 |
run_utility(argv);
|
634 | |
reopen_only = 1;
|
|
641 |
if (!aggressive_opt)
|
|
642 |
reopen_only = 1;
|
635 | 643 |
leading_edge_set = 0;
|
636 | 644 |
}
|
637 | 645 |
if (dir_modified > 0) {
|