int cstat_init_with_cntr(struct cstat *cstat, const char *name, const char *clientconfdir) { if(cstat_init(cstat, name, clientconfdir) || !(cstat->cntr=cntr_alloc()) || cntr_init(cstat->cntr, name)) return -1; return 0; }
static struct cstat *setup_cstat(const char *cname, enum protocol protocol) { struct cstat *cstat; struct sdirs *sdirs; clean(); sdirs=setup_sdirs(protocol); fail_unless((cstat=cstat_alloc())!=NULL); fail_unless(!cstat_init(cstat, cname, CLIENTCONFDIR)); cstat->sdirs=sdirs; return cstat; }
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_string(void *ctx, const unsigned char *val, size_t len) { char *str; if(!(str=(char *)malloc_w(len+2, __func__))) return 0; snprintf(str, len+1, "%s", val); if(in_counters) { if(!strcmp(lastkey, "name")) { // Ignore 'name' in a counters object. We use 'type' // instead. } else if(!strcmp(lastkey, "type")) { if(!current) goto error; cntr_ent=current->cntr->ent[(uint8_t)*str]; } else { goto error; } goto end; } else if(!strcmp(lastkey, "name")) { if(cnew) goto error; if(!(current=cstat_get_by_name(*cslist, str))) { if(!(cnew=cstat_alloc()) || cstat_init(cnew, str, NULL)) goto error; current=cnew; } goto end; } else if(!strcmp(lastkey, "run_status")) { if(!current) goto error; current->run_status=run_str_to_status(str); goto end; } else if(!strcmp(lastkey, "phase")) { if(!current) goto error; current->cntr->cntr_status=cntr_str_to_status(str); goto end; } else if(!strcmp(lastkey, "flags")) { if(!current) goto error; if(is_wrap(str, "hardlinked", BU_HARDLINKED) || is_wrap(str, "deletable", BU_DELETABLE) || is_wrap(str, "working", BU_WORKING) || is_wrap(str, "finishing", BU_FINISHING) || is_wrap(str, "current", BU_CURRENT) || is_wrap(str, "manifest", BU_MANIFEST)) goto end; } else if(!strcmp(lastkey, "counters")) // Do we need this? { goto end; } else if(!strcmp(lastkey, "list")) { if(is_wrap(str, "backup", BU_LOG_BACKUP) || is_wrap(str, "restore", BU_LOG_RESTORE) || is_wrap(str, "verify", BU_LOG_VERIFY) || is_wrap(str, "backup_stats", BU_STATS_BACKUP) || is_wrap(str, "restore_stats", BU_STATS_RESTORE) || is_wrap(str, "verify_stats", BU_STATS_VERIFY)) goto end; } else if(!strcmp(lastkey, "logs")) { goto end; } else if(!strcmp(lastkey, "logline")) { goto end; } else if(!strcmp(lastkey, "backup") || !strcmp(lastkey, "restore") || !strcmp(lastkey, "verify") || !strcmp(lastkey, "backup_stats") || !strcmp(lastkey, "restore_stats") || !strcmp(lastkey, "verify_stats")) { // Log file contents. if(lline_add(&ll_list, str)) goto error; goto end; } error: logp("Unexpected string: %s %s\n", lastkey, str); free_w(&str); return 0; end: free_w(&str); return 1; }