From 6f39bd7e00acee689ce9a8a3916888a815242557 Mon Sep 17 00:00:00 2001 From: Sergey Poznyakoff Date: Mon, 22 Aug 2016 17:49:30 +0300 Subject: Rename: struct dirwatcher -> struct watchpoint --- src/config.c | 12 +-- src/direvent.c | 2 +- src/direvent.h | 55 +++++------ src/ev_inotify.c | 72 +++++++-------- src/ev_kqueue.c | 38 ++++---- src/handler.c | 20 ++-- src/progman.c | 8 +- src/watcher.c | 274 +++++++++++++++++++++++++++---------------------------- 8 files changed, 241 insertions(+), 240 deletions(-) diff --git a/src/config.c b/src/config.c index a11e629..1f8d26e 100644 --- a/src/config.c +++ b/src/config.c @@ -176,18 +176,18 @@ eventconf_flush(grecs_locus_t *loc) for (ep = eventconf.pathlist->head; ep; ep = ep->next) { struct pathent *pe = ep->data; - struct dirwatcher *dwp; + struct watchpoint *wpt; int isnew; - dwp = dirwatcher_install(pe->path, &isnew); - if (!dwp) + wpt = watchpoint_install(pe->path, &isnew); + if (!wpt) abort(); - if (!isnew && dwp->depth != pe->depth) + if (!isnew && wpt->depth != pe->depth) grecs_error(loc, 0, _("%s: recursion depth does not match previous definition"), pe->path); - dwp->depth = pe->depth; - handler_list_append(dwp->handler_list, hp); + wpt->depth = pe->depth; + handler_list_append(wpt->handler_list, hp); } grecs_list_free(eventconf.pathlist); eventconf_init(); diff --git a/src/direvent.c b/src/direvent.c index 6c6a278..e1775f9 100644 --- a/src/direvent.c +++ b/src/direvent.c @@ -364,7 +364,7 @@ setuser(const char *user) } void -ev_log(int flags, struct dirwatcher *dp) +ev_log(int flags, struct watchpoint *dp) { int i; char *p; diff --git a/src/direvent.h b/src/direvent.h index bc5bb46..faa1657 100644 --- a/src/direvent.h +++ b/src/direvent.h @@ -95,7 +95,7 @@ struct handler { char **env; /* Environment */ } prog; struct { - struct dirwatcher *watcher; + struct watchpoint *watchpoint; } sentinel; } v; #define prog_flags v.prog.flags @@ -105,17 +105,18 @@ struct handler { #define prog_gidc v.prog.gidc #define prog_timeout v.prog.timeout #define prog_env v.prog.env -#define sentinel_watcher v.sentinel.watcher +#define sentinel_watchpoint v.sentinel.watchpoint }; typedef struct handler_list *handler_list_t; typedef struct handler_iterator *handler_iterator_t; -/* A directory watcher is described by the following structure */ -struct dirwatcher { +/* Watchpoint links the directory being monitored and a list of + handlers for various events: */ +struct watchpoint { size_t refcnt; int wd; /* Watch descriptor */ - struct dirwatcher *parent; /* Points to the parent watcher. + struct watchpoint *parent; /* Points to the parent watcher. NULL for top-level watchers */ char *dirname; /* Pathname being watched */ handler_list_t handler_list; /* List of handlers */ @@ -174,10 +175,10 @@ void debugprt(const char *fmt, ...); void signal_setup(void (*sf) (int)); int detach(void (*)(void)); -int sysev_filemask(struct dirwatcher *dp); +int sysev_filemask(struct watchpoint *dp); void sysev_init(void); -int sysev_add_watch(struct dirwatcher *dwp, event_mask mask); -void sysev_rm_watch(struct dirwatcher *dwp); +int sysev_add_watch(struct watchpoint *dwp, event_mask mask); +void sysev_rm_watch(struct watchpoint *dwp); int sysev_select(void); int sysev_name_to_code(const char *name); const char *sysev_code_to_name(int code); @@ -240,35 +241,35 @@ void config_parse(const char *file); int get_facility(const char *arg); int get_priority(const char *arg); -int dirwatcher_init(struct dirwatcher *dwp); -void dirwatcher_ref(struct dirwatcher *dw); -void dirwatcher_unref(struct dirwatcher *dw); -void dirwatcher_gc(void); +int watchpoint_init(struct watchpoint *dwp); +void watchpoint_ref(struct watchpoint *dw); +void watchpoint_unref(struct watchpoint *dw); +void watchpoint_gc(void); -int dirwatcher_pattern_match(struct dirwatcher *dwp, const char *file_name); +int watchpoint_pattern_match(struct watchpoint *dwp, const char *file_name); void setup_watchers(void); void shutdown_watchers(void); -struct dirwatcher *dirwatcher_lookup(const char *dirname); +struct watchpoint *watchpoint_lookup(const char *dirname); int check_new_watcher(const char *dir, const char *name); -struct dirwatcher *dirwatcher_install(const char *path, int *pnew); -struct dirwatcher *dirwatcher_install_ptr(struct dirwatcher *dw); -void dirwatcher_suspend(struct dirwatcher *dwp); -void dirwatcher_destroy(struct dirwatcher *dwp); -struct dirwatcher *dirwatcher_install_sentinel(struct dirwatcher *dwp); +struct watchpoint *watchpoint_install(const char *path, int *pnew); +struct watchpoint *watchpoint_install_ptr(struct watchpoint *dw); +void watchpoint_suspend(struct watchpoint *dwp); +void watchpoint_destroy(struct watchpoint *dwp); +struct watchpoint *watchpoint_install_sentinel(struct watchpoint *dwp); -int watch_pathname(struct dirwatcher *parent, const char *dirname, int isdir, int notify); +int watch_pathname(struct watchpoint *parent, const char *dirname, int isdir, int notify); -char *split_pathname(struct dirwatcher *dp, char **dirname); -void unsplit_pathname(struct dirwatcher *dp); +char *split_pathname(struct watchpoint *dp, char **dirname); +void unsplit_pathname(struct watchpoint *dp); -void ev_log(int flags, struct dirwatcher *dp); -void deliver_ev_create(struct dirwatcher *dp, const char *name); -int subwatcher_create(struct dirwatcher *parent, const char *dirname, +void ev_log(int flags, struct watchpoint *dp); +void deliver_ev_create(struct watchpoint *dp, const char *name); +int subwatcher_create(struct watchpoint *parent, const char *dirname, int isdir, int notify); -struct handler *handler_itr_first(struct dirwatcher *dp, +struct handler *handler_itr_first(struct watchpoint *dp, handler_iterator_t *itr); struct handler *handler_itr_next(handler_iterator_t *itr); struct handler *handler_itr_current(handler_iterator_t itr); @@ -291,7 +292,7 @@ size_t handler_list_size(handler_list_t hlist); struct process *process_lookup(pid_t pid); void process_cleanup(int expect_term); void process_timeouts(void); -int run_handler(struct dirwatcher *dp, struct handler *hp, event_mask *event, +int run_handler(struct watchpoint *dp, struct handler *hp, event_mask *event, const char *dir, const char *file); char **environ_setup(char **hint, char **kve); diff --git a/src/ev_inotify.c b/src/ev_inotify.c index 6d4c03a..7b2ee1d 100644 --- a/src/ev_inotify.c +++ b/src/ev_inotify.c @@ -45,30 +45,30 @@ event_mask genev_xlat[] = { static int ifd; -static struct dirwatcher **dwtab; -static size_t dwsize; +static struct watchpoint **wptab; +static size_t wpsize; static int -dwreg(int wd, struct dirwatcher *wp) +wpreg(int wd, struct watchpoint *wpt) { if (wd < 0) abort(); - if (wd >= dwsize) { - size_t n = dwsize; - struct dirwatcher **p; + if (wd >= wpsize) { + size_t n = wpsize; + struct watchpoint **p; if (n == 0) n = sysconf(_SC_OPEN_MAX); while (wd >= n) { n *= 2; - if (n < dwsize) { + if (n < wpsize) { diag(LOG_CRIT, _("can't allocate memory for fd %d"), wd); return -1; } } - p = realloc(dwtab, n * sizeof(dwtab[0])); + p = realloc(wptab, n * sizeof(wptab[0])); if (!p) { diag(LOG_CRIT, _("can't allocate memory for fd %d"), @@ -76,36 +76,36 @@ dwreg(int wd, struct dirwatcher *wp) return -1; } - memset(p + dwsize, 0, (n - dwsize) * sizeof(dwtab[0])); - dwtab = p; - dwsize = n; + memset(p + wpsize, 0, (n - wpsize) * sizeof(wptab[0])); + wptab = p; + wpsize = n; } - dirwatcher_ref(wp); - dwtab[wd] = wp; + watchpoint_ref(wpt); + wptab[wd] = wpt; return 0; } static void -dwunreg(int wd) +wpunreg(int wd) { - if (wd < 0 || wd > dwsize) + if (wd < 0 || wd > wpsize) abort(); - if (dwtab[wd]) { - dirwatcher_unref(dwtab[wd]); - dwtab[wd] = NULL; + if (wptab[wd]) { + watchpoint_unref(wptab[wd]); + wptab[wd] = NULL; } } -static struct dirwatcher * -dwget(int wd) +static struct watchpoint * +wpget(int wd) { - if (wd >= 0 && wd < dwsize) - return dwtab[wd]; + if (wd >= 0 && wd < wpsize) + return wptab[wd]; return NULL; } int -sysev_filemask(struct dirwatcher *dp) +sysev_filemask(struct watchpoint *dp) { return 0; } @@ -121,10 +121,10 @@ sysev_init() } int -sysev_add_watch(struct dirwatcher *dwp, event_mask mask) +sysev_add_watch(struct watchpoint *wpt, event_mask mask) { - int wd = inotify_add_watch(ifd, dwp->dirname, mask.sys_mask); - if (wd >= 0 && dwreg(wd, dwp)) { + int wd = inotify_add_watch(ifd, wpt->dirname, mask.sys_mask); + if (wd >= 0 && wpreg(wd, wpt)) { inotify_rm_watch(ifd, wd); return -1; } @@ -132,39 +132,39 @@ sysev_add_watch(struct dirwatcher *dwp, event_mask mask) } void -sysev_rm_watch(struct dirwatcher *dwp) +sysev_rm_watch(struct watchpoint *wpt) { - dwunreg(dwp->wd); - inotify_rm_watch(ifd, dwp->wd); + wpunreg(wpt->wd); + inotify_rm_watch(ifd, wpt->wd); } /* Remove a watcher identified by its directory and file name */ void remove_watcher(const char *dir, const char *name) { - struct dirwatcher *dwp; + struct watchpoint *wpt; char *fullname = mkfilename(dir, name); if (!fullname) { diag(LOG_EMERG, "not enough memory: " "cannot look up a watcher to delete"); return; } - dwp = dirwatcher_lookup(fullname); + wpt = watchpoint_lookup(fullname); free(fullname); - if (dwp) - dirwatcher_suspend(dwp); + if (wpt) + watchpoint_suspend(wpt); } static void process_event(struct inotify_event *ep) { - struct dirwatcher *dp; + struct watchpoint *dp; struct handler *h; handler_iterator_t itr; event_mask m; char *dirname, *filename; - dp = dwget(ep->wd); + dp = wpget(ep->wd); if (!dp) { if (!(ep->mask & IN_IGNORED)) diag(LOG_NOTICE, _("watcher not found: %d (%s)"), @@ -174,7 +174,7 @@ process_event(struct inotify_event *ep) if (ep->mask & IN_IGNORED) { diag(LOG_NOTICE, _("%s deleted"), dp->dirname); - dirwatcher_suspend(dp); + watchpoint_suspend(dp); return; } diff --git a/src/ev_kqueue.c b/src/ev_kqueue.c index a9921c6..680fb42 100644 --- a/src/ev_kqueue.c +++ b/src/ev_kqueue.c @@ -60,7 +60,7 @@ sysev_init() } int -sysev_filemask(struct dirwatcher *dp) +sysev_filemask(struct watchpoint *dp) { struct handler *h; handler_iterator_t itr; @@ -73,9 +73,9 @@ sysev_filemask(struct dirwatcher *dp) } int -sysev_add_watch(struct dirwatcher *dwp, event_mask mask) +sysev_add_watch(struct watchpoint *wpt, event_mask mask) { - int wd = open(dwp->dirname, O_RDONLY); + int wd = open(wpt->dirname, O_RDONLY); if (wd >= 0) { struct stat st; int sysmask; @@ -84,26 +84,26 @@ sysev_add_watch(struct dirwatcher *dwp, event_mask mask) close(wd); return -1; } - dwp->file_mode = st.st_mode; - dwp->file_ctime = st.st_ctime; + wpt->file_mode = st.st_mode; + wpt->file_ctime = st.st_ctime; sysmask = mask.sys_mask; if (S_ISDIR(st.st_mode) && mask.gen_mask & GENEV_CREATE) sysmask |= NOTE_WRITE; EV_SET(chtab + chcnt, wd, EVFILT_VNODE, EV_ADD | EV_ENABLE | EV_CLEAR, sysmask, - 0, dwp); + 0, wpt); wd = chcnt++; } return wd; } void -sysev_rm_watch(struct dirwatcher *dwp) +sysev_rm_watch(struct watchpoint *wpt) { - close(chtab[dwp->wd].ident); - chtab[dwp->wd].ident = -1; - if (chclosed == -1 || chclosed > dwp->wd) - chclosed = dwp->wd; + close(chtab[wpt->wd].ident); + chtab[wpt->wd].ident = -1; + if (chclosed == -1 || chclosed > wpt->wd) + chclosed = wpt->wd; } static void @@ -116,11 +116,11 @@ chclosed_elim() for (i = chclosed, j = chclosed + 1; j < chcnt; j++) if (chtab[j].ident != -1) { - struct dirwatcher *dwp; + struct watchpoint *wpt; chtab[i] = chtab[j]; - dwp = chtab[i].udata; - dwp->wd = i; + wpt = chtab[i].udata; + wpt->wd = i; i++; } chcnt = i; @@ -128,7 +128,7 @@ chclosed_elim() } static void -check_created(struct dirwatcher *dp) +check_created(struct watchpoint *dp) { DIR *dir; struct dirent *ent; @@ -150,7 +150,7 @@ check_created(struct dirwatcher *dp) (ent->d_name[1] == '.' && ent->d_name[2] == 0))) continue; - if (dirwatcher_pattern_match(dp, ent->d_name)) + if (watchpoint_pattern_match(dp, ent->d_name)) continue; pathname = mkfilename(dp->dirname, ent->d_name); @@ -171,7 +171,7 @@ check_created(struct dirwatcher *dp) know about that file. If the file is new, register a watcher for it. */ } else if (st.st_ctime > dp->file_ctime || - !dirwatcher_lookup(pathname)) { + !watchpoint_lookup(pathname)) { deliver_ev_create(dp, ent->d_name); subwatcher_create(dp, pathname, S_ISDIR(st.st_mode), 1); @@ -185,7 +185,7 @@ check_created(struct dirwatcher *dp) static void process_event(struct kevent *ep) { - struct dirwatcher *dp = ep->udata; + struct watchpoint *dp = ep->udata; struct handler *h; handler_iterator_t itr; event_mask m; @@ -217,7 +217,7 @@ process_event(struct kevent *ep) if (ep->fflags & (NOTE_DELETE|NOTE_RENAME)) { debug(1, ("%s deleted", dp->dirname)); - dirwatcher_suspend(dp); + watchpoint_suspend(dp); return; } } diff --git a/src/handler.c b/src/handler.c index 0e86a44..2d27824 100644 --- a/src/handler.c +++ b/src/handler.c @@ -108,7 +108,7 @@ handler_free(struct handler *hp) envfree(hp->prog_env); break; case HANDLER_SENTINEL: - dirwatcher_unref(hp->sentinel_watcher); + watchpoint_unref(hp->sentinel_watchpoint); } } @@ -146,11 +146,11 @@ struct handler_iterator { static struct handler_iterator *itr_avail; struct handler * -handler_itr_first(struct dirwatcher *dwp, handler_iterator_t *ret_itr) +handler_itr_first(struct watchpoint *wpt, handler_iterator_t *ret_itr) { struct handler_iterator *itr; - if (!dwp->handler_list) + if (!wpt->handler_list) return NULL; if (itr_avail) { @@ -162,13 +162,13 @@ handler_itr_first(struct dirwatcher *dwp, handler_iterator_t *ret_itr) itr = emalloc(sizeof *itr); itr->prev = NULL; - itr->next = dwp->handler_list->itr_chain; - itr->hlist = dwp->handler_list; - if (dwp->handler_list->itr_chain) - dwp->handler_list->itr_chain->prev = itr; - dwp->handler_list->itr_chain = itr; + itr->next = wpt->handler_list->itr_chain; + itr->hlist = wpt->handler_list; + if (wpt->handler_list->itr_chain) + wpt->handler_list->itr_chain->prev = itr; + wpt->handler_list->itr_chain = itr; - itr->ent = dwp->handler_list->list->head; + itr->ent = wpt->handler_list->list->head; itr->advanced = 0; *ret_itr = itr; return handler_itr_current(itr); @@ -284,5 +284,5 @@ handler_list_remove(handler_list_t hlist, struct handler *hp) grecs_list_remove_entry(hlist->list, ep); if (grecs_list_size(hlist->list) == 0) /* Remove watchers that don't have handlers */ - dirwatcher_gc(); + watchpoint_gc(); } diff --git a/src/progman.c b/src/progman.c index 823d51c..134deaf 100644 --- a/src/progman.c +++ b/src/progman.c @@ -541,16 +541,16 @@ run_handler_prog(struct handler *hp, event_mask *event, } static int -run_sentinel(struct dirwatcher *dp, struct handler *hp) +run_sentinel(struct watchpoint *dp, struct handler *hp) { - dirwatcher_init(hp->sentinel_watcher); - dirwatcher_install_ptr(hp->sentinel_watcher); + watchpoint_init(hp->sentinel_watchpoint); + watchpoint_install_ptr(hp->sentinel_watchpoint); handler_list_remove(dp->handler_list, hp); return 0; } int -run_handler(struct dirwatcher *dp, struct handler *hp, event_mask *event, +run_handler(struct watchpoint *dp, struct handler *hp, event_mask *event, const char *dirname, const char *file) { int rc; diff --git a/src/watcher.c b/src/watcher.c index b625276..e0b4950 100644 --- a/src/watcher.c +++ b/src/watcher.c @@ -19,177 +19,177 @@ #include void -dirwatcher_ref(struct dirwatcher *dw) +watchpoint_ref(struct watchpoint *wpt) { - ++dw->refcnt; + ++wpt->refcnt; } void -dirwatcher_unref(struct dirwatcher *dw) +watchpoint_unref(struct watchpoint *wpt) { - if (--dw->refcnt) + if (--wpt->refcnt) return; - free(dw->dirname); - handler_list_unref(dw->handler_list); - free(dw); + free(wpt->dirname); + handler_list_unref(wpt->handler_list); + free(wpt); } -struct dwref { +struct wpref { int used; - struct dirwatcher *dw; + struct watchpoint *wpt; }; static unsigned -dwname_hash(void *data, unsigned long hashsize) +wpref_hash(void *data, unsigned long hashsize) { - struct dwref *sym = data; - return hash_string(sym->dw->dirname, hashsize); + struct wpref *sym = data; + return hash_string(sym->wpt->dirname, hashsize); } static int -dwname_cmp(const void *a, const void *b) +wpref_cmp(const void *a, const void *b) { - struct dwref const *syma = a; - struct dwref const *symb = b; + struct wpref const *syma = a; + struct wpref const *symb = b; - return strcmp(syma->dw->dirname, symb->dw->dirname); + return strcmp(syma->wpt->dirname, symb->wpt->dirname); } static int -dwname_copy(void *a, void *b) +wpref_copy(void *a, void *b) { - struct dwref *syma = a; - struct dwref *symb = b; + struct wpref *syma = a; + struct wpref *symb = b; syma->used = 1; - syma->dw = symb->dw; + syma->wpt = symb->wpt; return 0; } static void -dwref_free(void *p) +wpref_free(void *p) { - struct dwref *dwref = p; - dirwatcher_unref(dwref->dw); - free(dwref); + struct wpref *wpref = p; + watchpoint_unref(wpref->wpt); + free(wpref); } struct hashtab *nametab; -struct dirwatcher * -dirwatcher_install(const char *path, int *pnew) +struct watchpoint * +watchpoint_install(const char *path, int *pnew) { - struct dirwatcher *dw, dwkey; - struct dwref key; - struct dwref *ent; + struct watchpoint *wpt, wpkey; + struct wpref key; + struct wpref *ent; int install = 1; if (!nametab) { - nametab = hashtab_create(sizeof(struct dwref), - dwname_hash, dwname_cmp, dwname_copy, - NULL, dwref_free); + nametab = hashtab_create(sizeof(struct wpref), + wpref_hash, wpref_cmp, wpref_copy, + NULL, wpref_free); if (!nametab) { diag(LOG_CRIT, _("not enough memory")); exit(1); } } - dwkey.dirname = (char*) path; - key.dw = &dwkey; + wpkey.dirname = (char*) path; + key.wpt = &wpkey; ent = hashtab_lookup_or_install(nametab, &key, &install); if (install) { - dw = ecalloc(1, sizeof(*dw)); - dw->dirname = estrdup(path); - dw->wd = -1; - dw->handler_list = handler_list_create(); - dw->refcnt++; - ent->dw = dw; + wpt = ecalloc(1, sizeof(*wpt)); + wpt->dirname = estrdup(path); + wpt->wd = -1; + wpt->handler_list = handler_list_create(); + wpt->refcnt++; + ent->wpt = wpt; } if (!ent) abort(); /* FIXME */ if (pnew) *pnew = install; - return ent->dw; + return ent->wpt; } -struct dirwatcher * -dirwatcher_install_ptr(struct dirwatcher *dw) +struct watchpoint * +watchpoint_install_ptr(struct watchpoint *wpt) { - struct dwref key; + struct wpref key; int install = 1; - key.dw = dw; + key.wpt = wpt; if (!hashtab_lookup_or_install(nametab, &key, &install)) { diag(LOG_CRIT, _("not enough memory")); exit(1); } - dirwatcher_ref(dw); - return dw; + watchpoint_ref(wpt); + return wpt; } static int -dwref_gc(struct hashent *ent, void *data) +wpref_gc(struct hashent *ent, void *data) { - struct dwref *dwref = (struct dwref *) ent; - struct dirwatcher *dwp = dwref->dw; + struct wpref *wpref = (struct wpref *) ent; + struct watchpoint *wpt = wpref->wpt; - if (handler_list_size(dwp->handler_list) == 0) - dirwatcher_destroy(dwp); + if (handler_list_size(wpt->handler_list) == 0) + watchpoint_destroy(wpt); return 0; } void -dirwatcher_gc(void) +watchpoint_gc(void) { - hashtab_foreach(nametab, dwref_gc, NULL); + hashtab_foreach(nametab, wpref_gc, NULL); } -struct dirwatcher * -dirwatcher_lookup(const char *dirname) +struct watchpoint * +watchpoint_lookup(const char *dirname) { - struct dirwatcher dwkey; - struct dwref key; - struct dwref *ent; + struct watchpoint wpkey; + struct wpref key; + struct wpref *ent; if (!nametab) return NULL; - dwkey.dirname = (char*) dirname; - key.dw = &dwkey; + wpkey.dirname = (char*) dirname; + key.wpt = &wpkey; ent = hashtab_lookup_or_install(nametab, &key, NULL); - return ent ? ent->dw : NULL; + return ent ? ent->wpt : NULL; } static void -dirwatcher_remove(const char *dirname) +watchpoint_remove(const char *dirname) { - struct dirwatcher dwkey; - struct dwref key; + struct watchpoint wpkey; + struct wpref key; if (!nametab) return; - dwkey.dirname = (char*) dirname; - key.dw = &dwkey; + wpkey.dirname = (char*) dirname; + key.wpt = &wpkey; hashtab_remove(nametab, &key); } void -dirwatcher_destroy(struct dirwatcher *dwp) +watchpoint_destroy(struct watchpoint *wpt) { - debug(1, (_("removing watcher %s"), dwp->dirname)); - sysev_rm_watch(dwp); - dirwatcher_remove(dwp->dirname); + debug(1, (_("removing watcher %s"), wpt->dirname)); + sysev_rm_watch(wpt); + watchpoint_remove(wpt->dirname); } // FIXME: Perhaps the check for count is not needed after all void -dirwatcher_suspend(struct dirwatcher *dwp) +watchpoint_suspend(struct watchpoint *wpt) { - struct dirwatcher *sent = dirwatcher_install_sentinel(dwp); - dirwatcher_init(sent);//FIXME: error checking - dirwatcher_destroy(dwp); + struct watchpoint *sent = watchpoint_install_sentinel(wpt); + watchpoint_init(sent);//FIXME: error checking + watchpoint_destroy(wpt); if (hashtab_count(nametab) == 0) { diag(LOG_CRIT, _("no watchers left; exiting now")); stop = 1; @@ -197,7 +197,7 @@ dirwatcher_suspend(struct dirwatcher *dwp) } static int -convert_watcher(struct dirwatcher *dwp) +convert_watcher(struct watchpoint *wpt) { char *dirname; char *filename; @@ -205,51 +205,51 @@ convert_watcher(struct dirwatcher *dwp) struct handler *hp; handler_iterator_t itr; - for_each_handler(dwp, itr, hp) { + for_each_handler(wpt, itr, hp) { if (hp->fnames) { /* FIXME: Error message */ return 1; } } - filename = split_pathname(dwp, &dirname); - for_each_handler(dwp, itr, hp) + filename = split_pathname(wpt, &dirname); + for_each_handler(wpt, itr, hp) handler_add_exact_filename(hp, filename); new_dirname = estrdup(dirname); - unsplit_pathname(dwp); + unsplit_pathname(wpt); diag(LOG_NOTICE, _("watcher %s converted to %s"), - dwp->dirname, new_dirname); + wpt->dirname, new_dirname); - free(dwp->dirname); - dwp->dirname = new_dirname; + free(wpt->dirname); + wpt->dirname = new_dirname; return 0; } -struct dirwatcher * -dirwatcher_install_sentinel(struct dirwatcher *dwp) +struct watchpoint * +watchpoint_install_sentinel(struct watchpoint *wpt) { - struct dirwatcher *sent; + struct watchpoint *sent; char *dirname; char *filename; struct handler *hp; - filename = split_pathname(dwp, &dirname); - sent = dirwatcher_install(dirname, NULL); + filename = split_pathname(wpt, &dirname); + sent = watchpoint_install(dirname, NULL); hp = handler_alloc(HANDLER_SENTINEL); getevt("CREATE", &hp->ev_mask); - hp->sentinel_watcher = dwp; - dirwatcher_ref(dwp); + hp->sentinel_watchpoint = wpt; + watchpoint_ref(wpt); handler_add_exact_filename(hp, filename); handler_list_append(sent->handler_list, hp); - unsplit_pathname(dwp); - diag(LOG_NOTICE, _("installing CREATE sentinel for %s"), dwp->dirname); - dirwatcher_init(sent); + unsplit_pathname(wpt); + diag(LOG_NOTICE, _("installing CREATE sentinel for %s"), wpt->dirname); + watchpoint_init(sent); return sent; } int -dirwatcher_init(struct dirwatcher *dwp) +watchpoint_init(struct watchpoint *wpt) { struct stat st; event_mask mask = { 0, 0 }; @@ -257,73 +257,73 @@ dirwatcher_init(struct dirwatcher *dwp) handler_iterator_t itr; int wd; - debug(1, (_("creating watcher %s"), dwp->dirname)); + debug(1, (_("creating watcher %s"), wpt->dirname)); - if (stat(dwp->dirname, &st)) { + if (stat(wpt->dirname, &st)) { if (errno == ENOENT) { - dwp = dirwatcher_install_sentinel(dwp); + wpt = watchpoint_install_sentinel(wpt); return 0; } else { diag(LOG_ERR, _("cannot set watcher on %s: %s"), - dwp->dirname, strerror(errno)); + wpt->dirname, strerror(errno)); return 1; } } else if (!S_ISDIR(st.st_mode)) { - diag(LOG_NOTICE, _("%s is a regular file"), dwp->dirname); - convert_watcher(dwp); + diag(LOG_NOTICE, _("%s is a regular file"), wpt->dirname); + convert_watcher(wpt); } - for_each_handler(dwp, itr, hp) { + for_each_handler(wpt, itr, hp) { mask.sys_mask |= hp->ev_mask.sys_mask; mask.gen_mask |= hp->ev_mask.gen_mask; } - wd = sysev_add_watch(dwp, mask); + wd = sysev_add_watch(wpt, mask); if (wd == -1) { diag(LOG_ERR, _("cannot set watcher on %s: %s"), - dwp->dirname, strerror(errno)); + wpt->dirname, strerror(errno)); return 1; } - dwp->wd = wd; + wpt->wd = wd; return 0; } -static int watch_subdirs(struct dirwatcher *parent, int notify); +static int watch_subdirs(struct watchpoint *parent, int notify); int -subwatcher_create(struct dirwatcher *parent, const char *dirname, +subwatcher_create(struct watchpoint *parent, const char *dirname, int isdir, int notify) { - struct dirwatcher *dwp; + struct watchpoint *wpt; int inst; - dwp = dirwatcher_install(dirname, &inst); + wpt = watchpoint_install(dirname, &inst); if (!inst) return -1; - dwp->handler_list = handler_list_copy(parent->handler_list); - dwp->parent = parent; + wpt->handler_list = handler_list_copy(parent->handler_list); + wpt->parent = parent; if (parent->depth == -1) - dwp->depth = parent->depth; + wpt->depth = parent->depth; else if (parent->depth) - dwp->depth = parent->depth - 1; + wpt->depth = parent->depth - 1; else - dwp->depth = 0; + wpt->depth = 0; - if (dirwatcher_init(dwp)) { - //FIXME dirwatcher_free(dwp); + if (watchpoint_init(wpt)) { + //FIXME watchpoint_free(wpt); return -1; } - return 1 + (isdir ? watch_subdirs(dwp, notify) : 0); + return 1 + (isdir ? watch_subdirs(wpt, notify) : 0); } /* Deliver GENEV_CREATE event */ void -deliver_ev_create(struct dirwatcher *dp, const char *name) +deliver_ev_create(struct watchpoint *dp, const char *name) { event_mask m = { GENEV_CREATE, 0 }; struct handler *h; @@ -352,9 +352,9 @@ check_new_watcher(const char *dir, const char *name) int rc; char *fname; struct stat st; - struct dirwatcher *parent; + struct watchpoint *parent; - parent = dirwatcher_lookup(dir); + parent = watchpoint_lookup(dir); if (!parent || !parent->depth) return 0; @@ -381,12 +381,12 @@ check_new_watcher(const char *dir, const char *name) } int -dirwatcher_pattern_match(struct dirwatcher *dwp, const char *file_name) +watchpoint_pattern_match(struct watchpoint *wpt, const char *file_name) { struct handler *hp; handler_iterator_t itr; - for_each_handler(dwp, itr, hp) { + for_each_handler(wpt, itr, hp) { if (filename_pattern_match(hp->fnames, file_name) == 0) return 0; } @@ -396,7 +396,7 @@ dirwatcher_pattern_match(struct dirwatcher *dwp, const char *file_name) /* Recursively scan subdirectories of parent and add them to the watcher list, as requested by the parent's recursion depth value. */ static int -watch_subdirs(struct dirwatcher *parent, int notify) +watch_subdirs(struct watchpoint *parent, int notify) { DIR *dir; struct dirent *ent; @@ -434,7 +434,7 @@ watch_subdirs(struct dirwatcher *parent, int notify) if (stat(dirname, &st)) { diag(LOG_ERR, _("cannot stat %s: %s"), dirname, strerror(errno)); - } else if (dirwatcher_pattern_match(parent, ent->d_name) + } else if (watchpoint_pattern_match(parent, ent->d_name) == 0) { if (notify) deliver_ev_create(parent, ent->d_name); @@ -456,20 +456,20 @@ watch_subdirs(struct dirwatcher *parent, int notify) static int setwatcher(struct hashent *ent, void *data) { - struct dwref *dwref = (struct dwref *) ent; - struct dirwatcher *dwp = dwref->dw; + struct wpref *wpref = (struct wpref *) ent; + struct watchpoint *wpt = wpref->wpt; - if (dwp->wd == -1 && dirwatcher_init(dwp) == 0) - watch_subdirs(dwp, 0); + if (wpt->wd == -1 && watchpoint_init(wpt) == 0) + watch_subdirs(wpt, 0); return 0; } static int checkwatcher(struct hashent *ent, void *data) { - struct dwref *dwref = (struct dwref *) ent; - struct dirwatcher *dwp = dwref->dw; - return dwp->wd >= 0; + struct wpref *wpref = (struct wpref *) ent; + struct watchpoint *wpt = wpref->wpt; + return wpt->wd >= 0; } void @@ -490,11 +490,11 @@ setup_watchers(void) static int stopwatcher(struct hashent *ent, void *data) { - struct dwref *dwref = (struct dwref *) ent; - struct dirwatcher *dwp = dwref->dw; - if (dwp->wd != -1) { - debug(1, (_("removing watcher %s"), dwp->dirname)); - sysev_rm_watch(dwp); + struct wpref *wpref = (struct wpref *) ent; + struct watchpoint *wpt = wpref->wpt; + if (wpt->wd != -1) { + debug(1, (_("removing watcher %s"), wpt->dirname)); + sysev_rm_watch(wpt); } return 0; } @@ -508,7 +508,7 @@ shutdown_watchers(void) char * -split_pathname(struct dirwatcher *dp, char **dirname) +split_pathname(struct watchpoint *dp, char **dirname) { char *p = strrchr(dp->dirname, '/'); if (p) { @@ -523,7 +523,7 @@ split_pathname(struct dirwatcher *dp, char **dirname) } void -unsplit_pathname(struct dirwatcher *dp) +unsplit_pathname(struct watchpoint *dp) { if (dp->split_p) { *dp->split_p = '/'; -- cgit v1.2.1