示例#1
0
文件: dag.c 项目: dcbradley/cctools
struct dag_variable_value *dag_variable_value_append_or_create(struct dag_variable_value *v, const char *value)
{
	if(!v)
		return dag_variable_value_create(value);

	int nlen = strlen(value);
	int req  = v->len + nlen + 2;   // + 2 for ' ' and '\0'

	if( req > v->size )
	{
		//make size for string to be appended, plus some more, so we do not
		//need to reallocate for a while.
		int nsize = req > 2*(v->size) ? 2*req : 2*(v->size);
		char *new_val = realloc(v->value, nsize*sizeof(char));
		if(!new_val)
			fatal("Could not allocate memory for makeflow variable value: %s\n", value);

		v->size  = nsize;
		v->value = new_val;
	}

	//add separating space
	*(v->value + v->len) = ' ';

	//append new string
	strcpy(v->value + v->len + 1, value);
	v->len = v->len + nlen + 1;

	return v;
}
示例#2
0
文件: dag.c 项目: dcbradley/cctools
struct dag *dag_create()
{
	struct dag *d = malloc(sizeof(*d));

	if(!d) {
		debug(D_DEBUG, "makeflow: could not allocate new dag : %s\n", strerror(errno));
		return NULL;
	} else {
		memset(d, 0, sizeof(*d));
		d->nodes = 0;
		d->filename = NULL;
		d->node_table = itable_create(0);
		d->local_job_table = itable_create(0);
		d->remote_job_table = itable_create(0);
		d->file_table = hash_table_create(0, 0);
		d->completed_files = hash_table_create(0, 0);
		d->symlinks_created = list_create();
		d->variables = hash_table_create(0, 0);
		d->local_jobs_running = 0;
		d->local_jobs_max = 1;
		d->remote_jobs_running = 0;
		d->remote_jobs_max = MAX_REMOTE_JOBS_DEFAULT;
		d->nodeid_counter = 0;
		d->collect_table = set_create(0);
		d->export_list = list_create();

		d->task_categories = hash_table_create(0, 0);

		/* Add GC_*_LIST to variables table to ensure it is in
		 * global DAG scope. */
		hash_table_insert(d->variables, "GC_COLLECT_LIST", dag_variable_value_create(""));
		hash_table_insert(d->variables, "GC_PRESERVE_LIST", dag_variable_value_create(""));

		memset(d->node_states, 0, sizeof(int) * DAG_NODE_STATE_MAX);
		return d;
	}
}
示例#3
0
文件: dag.c 项目: badi/cctools
struct dag_variable_value *dag_lookup(const char *name, void *arg)
{
	struct dag_lookup_set *s = (struct dag_lookup_set *) arg;
	struct dag_variable_value *v;

	int nodeid;
	if(s->node)
	{
		nodeid = s->node->nodeid;
	}
	else if(s->dag)
	{
		nodeid = s->dag->nodeid_counter;
	}

	if(s) {
		/* Try node variables table */
		if(s->node) {
			v = dag_get_variable_value(name, s->node->variables, nodeid);
			if(v) {
				s->table = s->node->variables; //why this line?
				return v;
			}
		}

		/* Try dag variables table */
		if(s->dag) {
			v = dag_get_variable_value(name, s->dag->variables, nodeid);
			if(v) {
				s->table = s->dag->variables;
				return v;
			}
		}
	}

	/* Try environment */
	char *value = getenv(name);
	if(value) {
		return dag_variable_value_create(value);
	}

	return NULL;
}
示例#4
0
struct dag_variable_value *dag_variable_lookup(const char *name, struct dag_variable_lookup_set *s )
{
    struct dag_variable_value *v;

    if(!s)
        return NULL;

    /* Try node variables table */
    if(s->node) {
        v = dag_variable_get_value(name, s->node->variables, s->node->nodeid);
        if(v) {
            s->table = s->node->variables; //why this line?
            return v;
        }
    }

    if(!s->dag)
        return NULL;

    /* Try the category variables table */
    if(s->category) {
        v = dag_variable_get_value(name, s->category->mf_variables, s->dag->nodeid_counter);
        if(v) {
            s->table = s->dag->default_category->mf_variables;
            return v;
        }
    }

    /* Try dag variables table */
    v = dag_variable_get_value(name, s->dag->default_category->mf_variables, s->dag->nodeid_counter);
    if(v) {
        s->table = s->dag->default_category->mf_variables;
        return v;
    }

    /* Try the environment last. */
    char *value = getenv(name);
    if(value) {
        return dag_variable_value_create(value);
    }

    return NULL;
}
示例#5
0
文件: dag.c 项目: dcbradley/cctools
struct dag_variable_value *dag_lookup(const char *name, void *arg)
{
	struct dag_lookup_set *s = (struct dag_lookup_set *) arg;
	struct dag_variable_value *v;

	if(s) {
		/* Try node variables table */
		if(s->node) {
			v = (struct dag_variable_value *) hash_table_lookup(s->node->variables, name);
			if(v) {
				s->table = s->node->variables; //why this line?
				return v;
			}
		}

		/* Try variables from category */
		if(s->category) {
			v = (struct dag_variable_value *) hash_table_lookup(s->category->variables, name);
			if(v) {
				s->table = s->category->variables;
				return v;
			}
		}

		/* Try dag variables table */
		if(s->dag) {
			v = (struct dag_variable_value *) hash_table_lookup(s->dag->variables, name);
			if(v) {
				s->table = s->dag->variables;
				return v;
			}
		}
	}

	/* Try environment */
	char *value = getenv(name);
	if(value) {
		return dag_variable_value_create(value);
	}

	return NULL;
}
示例#6
0
文件: dag.c 项目: badi/cctools
void dag_variable_add_value(const char *name, struct hash_table *current_table, int nodeid, const char *value)
{
	struct dag_variable *var = hash_table_lookup(current_table, name);
	if(!var)
	{
		char *value_env = getenv(name);
		var = dag_variable_create(name, value_env);
		hash_table_insert(current_table, name, var);
	}

	struct dag_variable_value *v = dag_variable_value_create(value);
	v->nodeid = nodeid;

	if(var->count < 1 || var->values[var->count - 1]->nodeid != v->nodeid)
	{
		var->count++;
		var->values = realloc(var->values, var->count * sizeof(struct dag_variable_value *));
	}

	//possible memory leak...
	var->values[var->count - 1] = v;
}
示例#7
0
文件: dag.c 项目: badi/cctools
struct dag_variable *dag_variable_create(const char *name, const char *initial_value)
{
	struct dag_variable *var = malloc(sizeof(struct dag_variable *));

	if(!initial_value && name)
	{
		initial_value = getenv(name);
	}

	if(initial_value)
	{
		var->count  = 1;
		var->values = malloc(sizeof(struct dag_variable_value *));
		var->values[0] = dag_variable_value_create(initial_value);
	}
	else
	{
		var->count  = 0;
		var->values = NULL;
	}

	return var;
}