static int reload_from_client_confs(struct cstat **clist, struct conf *conf) { struct cstat *c; static struct conf *cconf=NULL; if(!cconf && !(cconf=conf_alloc())) goto error; for(c=*clist; c; c=c->next) { // Look at the client conf files to see if they have changed, // and reload bits and pieces if they have. struct stat statp; if(!c->conffile) continue; if(stat(c->conffile, &statp) || !S_ISREG(statp.st_mode)) { cstat_remove(clist, &c); continue; } if(statp.st_mtime==c->conf_mtime) { // conf file has not changed - no need to do anything. continue; } c->conf_mtime=statp.st_mtime; conf_free_content(cconf); if(!(cconf->cname=strdup_w(c->name, __func__))) goto error; if(conf_set_client_global(conf, cconf) || conf_load(c->conffile, cconf, 0)) { cstat_remove(clist, &c); continue; } if(set_cstat_from_conf(c, cconf)) goto error; } return 0; error: conf_free(cconf); cconf=NULL; return -1; }
static #endif int cstat_reload_from_client_confs(struct cstat **clist, struct conf **globalcs, struct conf **cconfs) { struct cstat *c; struct stat statp; static time_t global_mtime=0; time_t global_mtime_new=0; const char *globalconffile; int reloaded=0; globalconffile=get_string(globalcs[OPT_CONFFILE]); if(stat(globalconffile, &statp) || !S_ISREG(statp.st_mode)) { logp("Could not stat main conf file %s: %s\n", globalconffile, strerror(errno)); return -1; } global_mtime_new=statp.st_mtime; // FIX THIS: If '. included' conf files have changed, this code will // not detect them. I guess that conf.c should make a list of them. while(1) { for(c=*clist; c; c=c->next) { // Look at the client conf files to see if they have // changed, and reload bits and pieces if they have. if(!c->conffile) continue; if(stat(c->conffile, &statp) || !S_ISREG(statp.st_mode)) { cstat_remove(clist, &c); break; // Go to the beginning of the list. } if(statp.st_mtime==c->conf_mtime && global_mtime_new==global_mtime) { // The conf files have not changed - no need to // do anything. continue; } c->conf_mtime=statp.st_mtime; confs_free_content(cconfs); if(set_string(cconfs[OPT_CNAME], c->name)) return -1; if(conf_load_clientconfdir(globalcs, cconfs)) { // If the file has junk in it, we will keep // trying to reload it after removal. // So, just deny permission to view it. c->permitted=0; continue; } if(set_cstat_from_conf(c, globalcs, cconfs)) return -1; reloaded++; } // Only stop if the end of the list was not reached. if(!c) break; } if(global_mtime!=global_mtime_new) global_mtime=global_mtime_new; return reloaded; }