From 92eeafbe6b3c68a51b11dbe773d909982acfb1b9 Mon Sep 17 00:00:00 2001 From: Sergey Poznyakoff Date: Sun, 31 Aug 2014 17:27:45 +0300 Subject: Accept multpile watchers for the same path * src/direvent.h (dirwatcher): New member. * src/config.c (eventconf_flush): Use handler_tail to update the handler list. Remove erroneous check. --- src/config.c | 23 +++++++++++------------ src/direvent.h | 10 +++++++--- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/src/config.c b/src/config.c index 82262a8..ef95211 100644 --- a/src/config.c +++ b/src/config.c @@ -198,20 +198,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 handler *hp, *prev = NULL; + struct handler *hp; + int isnew; - dwp = dirwatcher_install(pe->path, NULL); + dwp = dirwatcher_install(pe->path, &isnew); if (!dwp) abort(); + if (!isnew && dwp->depth != pe->depth) + grecs_error(loc, 0, + _("%s: recursion depth does not match previous definition"), + pe->path); dwp->depth = pe->depth; - for (hp = dwp->handler_list; hp; prev = hp, hp = hp->next) { - if (strcmp(dwp->dirname, pe->path) == 0) { - grecs_error(loc, 0, - _("ignoring duplicate definition")); - return; - } - } - + hp = emalloc(sizeof(*hp)); hp->next = NULL; hp->ev_mask = eventconf.eventmask; @@ -224,10 +222,11 @@ eventconf_flush(grecs_locus_t *loc) hp->gidv = eventconf.gidv; hp->env = eventconf.env; - if (prev) - prev->next = hp; + if (dwp->handler_tail) + dwp->handler_tail->next = hp; else dwp->handler_list = hp; + dwp->handler_tail = hp; } grecs_list_free(eventconf.pathlist); eventconf_init(); diff --git a/src/direvent.h b/src/direvent.h index 069d3d8..07dfd0b 100644 --- a/src/direvent.h +++ b/src/direvent.h @@ -89,9 +89,13 @@ struct dirwatcher { struct dirwatcher *parent; /* Points to the parent watcher. NULL for top-level watchers */ char *dirname; /* Pathname being watched */ - struct handler *handler_list; /* Handlers */ - int depth; - char *split_p; + struct handler *handler_list; /* List of handlers */ + struct handler *handler_tail; /* Tail of the handler list */ + int depth; /* Recursion depth */ + char *split_p; /* Points to the deleted directory + separator in dirname (see + split_pathname, + unsplit_pathname */ #if USE_IFACE == IFACE_KQUEUE mode_t file_mode; time_t file_ctime; -- cgit v1.2.1