diff options
Diffstat (limited to 'catsit-watch.c')
-rw-r--r-- | catsit-watch.c | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/catsit-watch.c b/catsit-watch.c index ea64155..78d1cb2 100644 --- a/catsit-watch.c +++ b/catsit-watch.c @@ -65,10 +65,12 @@ int main(int argc, char *argv[]) { fcntl(kq, F_SETFD, FD_CLOEXEC); int init = 0; + int delay = 0; int append = 0; - for (int opt; 0 < (opt = getopt(argc, argv, "af:i"));) { + for (int opt; 0 < (opt = getopt(argc, argv, "ad:f:i"));) { switch (opt) { break; case 'a': append = 1; + break; case 'd': delay = strtol(optarg, NULL, 10); break; case 'f': watch(kq, optarg); break; case 'i': init = 1; break; default: return EX_USAGE; @@ -96,9 +98,27 @@ int main(int argc, char *argv[]) { int nevents = kevent(kq, NULL, 0, &event, 1, NULL); if (nevents < 0) err(EX_OSERR, "kevent"); - if (event.fflags & NOTE_DELETE) { + if (delay) { + struct kevent timer; + EV_SET( + &timer, 0, EVFILT_TIMER, EV_ADD | EV_ONESHOT, + 0, delay, event.udata + ); + nevents = kevent(kq, &timer, 1, NULL, 0, NULL); + if (nevents < 0) err(EX_OSERR, "kevent"); + while ( + event.filter != EVFILT_TIMER + && !(event.fflags & NOTE_DELETE) + ) { + nevents = kevent(kq, NULL, 0, &event, 1, NULL); + if (nevents < 0) err(EX_OSERR, "kevent"); + } + } + + if (event.filter == EVFILT_VNODE && event.fflags & NOTE_DELETE) { errx(EX_TEMPFAIL, "%s: file removed", (char *)event.udata); } + if (append) rest[argc] = (char *)event.udata; run(rest); } |