Пример #1
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;
}
Пример #2
0
END_TEST

START_TEST(test_cstat_set_backup_list_fail_bu_get_list)
{
	struct cstat *cstat;
	fail_unless((cstat=cstat_alloc())!=NULL);
	cstat->permitted=1;
	// No sdirs is set on cstat, so bu_get_list_with_working() will fail.
	// But cstat_set_backup_list() will return OK anyway.
	fail_unless(!cstat_set_backup_list(cstat));
	fail_unless(cstat->bu==NULL);
}
Пример #3
0
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;
}
Пример #4
0
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;
}
Пример #5
0
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;
}