X-Git-Url: http://dolda2000.com/gitweb/?a=blobdiff_plain;f=src%2Fdirplex%2Fconf.c;h=e83d847e665663037602649a450573cd804eba5f;hb=18fb436dba91930a8d60c1d343c50b55b55a4c37;hp=96a7704b6fc11516ec5c0387229fd0f3019fda02;hpb=600a1ce79471493f8cad5fcf118dc9797331d5aa;p=ashd.git diff --git a/src/dirplex/conf.c b/src/dirplex/conf.c index 96a7704..e83d847 100644 --- a/src/dirplex/conf.c +++ b/src/dirplex/conf.c @@ -76,6 +76,8 @@ static void freeconfig(struct config *cf) freepattern(pat); } freeca(cf->index); + if(cf->capture != NULL) + free(cf->capture); free(cf); } @@ -228,6 +230,14 @@ struct config *readconfig(char *file) cf->index = NULL; if(s->argc > 1) cf->index = cadup(s->argv + 1); + } else if(!strcmp(s->argv[0], "capture")) { + if(s->argc < 2) { + flog(LOG_WARNING, "%s:%i: missing argument to capture declaration", s->file, s->lno); + continue; + } + if(cf->capture != NULL) + free(cf->capture); + cf->capture = sstrdup(s->argv[1]); } else if(!strcmp(s->argv[0], "eof")) { break; } else { @@ -240,9 +250,24 @@ struct config *readconfig(char *file) return(cf); } +static void mergechildren(struct config *dst, struct config *src) +{ + struct child *ch1, *ch2; + + for(ch1 = dst->children; ch1 != NULL; ch1 = ch1->next) { + for(ch2 = src->children; ch2 != NULL; ch2 = ch2->next) { + if(!strcmp(ch1->name, ch2->name)) { + ch1->fd = ch2->fd; + ch2->fd = -1; + break; + } + } + } +} + struct config *getconfig(char *path) { - struct config *cf; + struct config *cf, *ocf; struct stat sb; char *fn; time_t mtime; @@ -251,15 +276,14 @@ struct config *getconfig(char *path) for(cf = cflist; cf != NULL; cf = cf->next) { if(!strcmp(cf->path, path)) { if(now - cf->lastck > 5) { - if(stat(fn, &sb) || (sb.st_mtime != cf->mtime)) { - freeconfig(cf); + if(stat(fn, &sb) || (sb.st_mtime != cf->mtime)) break; - } } cf->lastck = now; return(cf); } } + ocf = cf; if(access(fn, R_OK) || stat(fn, &sb)) { cf = emptyconfig(); mtime = 0; @@ -268,6 +292,10 @@ struct config *getconfig(char *path) return(NULL); mtime = sb.st_mtime; } + if(ocf != NULL) { + mergechildren(cf, ocf); + freeconfig(ocf); + } cf->path = sstrdup(path); cf->mtime = mtime; cf->lastck = now; @@ -311,7 +339,7 @@ struct config **getconfigs(char *file) return(ret = buf.b); } -struct child *findchild(char *file, char *name) +struct child *findchild(char *file, char *name, struct config **cf) { int i; struct config **cfs; @@ -319,10 +347,13 @@ struct child *findchild(char *file, char *name) cfs = getconfigs(file); for(i = 0; cfs[i] != NULL; i++) { - if((ch = getchild(cfs[i], name)) != NULL) - break; + if((ch = getchild(cfs[i], name)) != NULL) { + if(cf != NULL) + *cf = cfs[i]; + return(ch); + } } - return(ch); + return(NULL); } struct pattern *findmatch(char *file, int trydefault, int dir)