END_TEST static void do_test_cstat_reload_from_client_confs(enum protocol protocol) { struct cstat *c1; struct cstat *c2; struct cstat *clist=NULL; c1=setup_cstat("cli1", protocol); c2=setup_cstat("cli2", protocol); cstat_add_to_list(&clist, c1); cstat_add_to_list(&clist, c2); c1->permitted=1; // First time, nothing is reloaded. fail_unless(reload_from_clientdir(&clist)==0); fail_unless(c1->run_status==RUN_STATUS_IDLE); fail_unless(c2->run_status==RUN_STATUS_UNSET); fail_unless(c1->bu==NULL); fail_unless(c2->bu==NULL); // Add some storage dirs, and c1 is loaded. build_storage_dirs((struct sdirs *)c1->sdirs, sd123, ARR_LEN(sd123)); fail_unless(reload_from_clientdir(&clist)==1); fail_unless(c1->run_status==RUN_STATUS_IDLE); fail_unless(c2->run_status==RUN_STATUS_UNSET); fail_unless(c1->bu!=NULL); fail_unless(c2->bu==NULL); // Go again, nothing should be reloaded. fail_unless(reload_from_clientdir(&clist)==0); // Get a lock. lock_get_quick(((struct sdirs *)c1->sdirs)->lock); fail_unless(reload_from_clientdir(&clist)==1); sdirs_free((struct sdirs **)&c1->sdirs); sdirs_free((struct sdirs **)&c2->sdirs); cstat_list_free(&clist); clean(); alloc_check(); }
static #endif int cstat_get_client_names(struct cstat **clist, const char *clientconfdir) { int i=0; int n=0; int ret=-1; struct cstat *c; struct cstat *cnew; struct dirent **dir=NULL; if(entries_in_directory_no_sort(clientconfdir, &dir, &n, 1 /*atime*/)) { logp("scandir failed for %s in %s: %s\n", clientconfdir, __func__, strerror(errno)); goto end; } for(i=0; i<n; i++) { // looks_like...() also avoids '.' and '..'. if(looks_like_tmp_or_hidden_file(dir[i]->d_name)) continue; for(c=*clist; c; c=c->next) { if(!c->name) continue; if(!strcmp(dir[i]->d_name, c->name)) break; } if(c) continue; // We do not have this client yet. Add it. if(!(cnew=cstat_alloc()) || cstat_init_with_cntr(cnew, dir[i]->d_name, clientconfdir)) goto end; cstat_add_to_list(clist, cnew); } ret=0; end: if(dir) { for(i=0; i<n; i++) free_v((void **)&dir[i]); free_v((void **)&dir); } return ret; }
static int get_client_names(struct cstat **clist, struct conf *conf) { int m=0; int n=-1; int ret=-1; struct cstat *c; struct cstat *cnew; struct dirent **dir=NULL; if((n=scandir(conf->clientconfdir, &dir, 0, 0))<0) { logp("could not scandir clientconfdir: %s\n", conf->clientconfdir, strerror(errno)); goto end; } for(m=0; m<n; m++) { if(dir[m]->d_ino==0 // looks_like...() also avoids '.' and '..'. || looks_like_tmp_or_hidden_file(dir[m]->d_name)) continue; for(c=*clist; c; c=c->next) { if(!c->name) continue; if(!strcmp(dir[m]->d_name, c->name)) break; } if(c) continue; // We do not have this client yet. Add it. if(!(cnew=cstat_alloc()) || cstat_init(cnew, dir[m]->d_name, conf->clientconfdir) || cstat_add_to_list(clist, cnew)) goto end; } ret=0; end: for(m=0; m<n; m++) free_v((void **)&dir[m]); free_v((void **)&dir); return ret; }
static int input_end_array(void *ctx) { if(in_backups && !in_flags && !in_counters && !in_logslist) { in_backups=0; if(add_to_bu_list()) return 0; // Now may have two lists. Want to keep the old one is intact // as possible, so that we can keep a pointer to its entries // in the ncurses stuff. // Merge the new list into the old. merge_bu_lists(); bu_list=NULL; if(cnew) { if(cstat_add_to_list(cslist, cnew)) return -1; cnew=NULL; } current=NULL; } else if(in_flags) { in_flags=0; } else if(in_counters) { in_counters=0; } else if(in_logslist) { in_logslist=0; } else if(in_log_content) { in_log_content=0; llines_free(sllines); *sllines=ll_list; ll_list=NULL; } return 1; }