Esempio n. 1
0
/*********
 * Given a target list and the list of rules, execute the targets.
 *********/
void execute_targets(int targetc, char* targetv[], rule_node_t* list,
                     ARG_HOLDER* argholder) {
	rule_node_t* ptr = list;
	int i;
	if(targetc == 0) {
		// no target specified on command line!
		//Go to the last rule (which was first in the file) and run it
		for(ptr = list; ptr->next != NULL; ptr = ptr->next);
		{
		    //Do nothing, we're just getting to the last rule
		}
	    if(ptr == NULL) {
		    fprintf(stderr, "Error, no targets in dimefile.\n");
	    } else {
		    exec_target_rec(ptr->rule, list, argholder);
	    }
	} else {
		for(i = 0; i < targetc; i++) {
			for(ptr = list; ptr != NULL; ptr = ptr->next) {
				if(strcmp(targetv[i], ptr->rule->target) == 0) {
					exec_target_rec(ptr->rule, list, argholder);
					break;
				}
			}
			if(ptr == NULL) {
				fprintf(stderr, "Error, target '%s' not found.\n",targetv[i]);
				exit(1);
			}
		}
	}
	argholder->finished_adding = 1;
	while (argholder->threads_not_done > 0)
	{
	    cond_wait(&finished_execution, &mutex);
	}
}
Esempio n. 2
0
/**************
 * Exec targets with recursive calls
 **************/
void exec_target_rec(rule_t* rule, rule_node_t* list, ARG_HOLDER* argholder) {
	str_node_t* sptr;
	rule_node_t* rptr;
	for(sptr = rule->deps; sptr != NULL; sptr = sptr->next) {
		// for each dependency, see if there's a rule, then exec that rule
		for(rptr = list; rptr != NULL; rptr = rptr->next) {
			if(strcmp(sptr->str, rptr->rule->target) == 0) {
				exec_target_rec(rptr->rule, list, argholder);
			}
		}
	}
    
    //Should add the target to the queue instead so helper threads can exec
	//fake_exec(rule);
	rule_node_t* queue = argholder->rule_queue;
	int max_queue_length = argholder->max_queue_length;
	
	int ql = queue_length(queue) - 1;
	int empty_queue = 0;
	if (ql == max_queue_length)
	{
	    //Wait for the queue length to go down
	    cond_wait(&queue_full, &mutex);
	}
	else if (ql == 0)
	{
	    empty_queue = 1;
	}
    //Attach the new target to the back of the queue
    sem_wait(&sem_lock);
    rule_node_t* qnode = queue;
    rule_node_t* qnext = qnode->next;
    while (qnext != NULL)
    {
        qnode = qnext;
        qnext = qnode->next;
    }
    rule_node_t* new_node = (rule_node_t*)(malloc(sizeof(rule_node_t)));
    new_node->rule = rule;
    new_node->next = NULL;
    qnode->next = new_node;
    sem_post(&sem_lock);
    //If the queue was empty, signal the helper threads that it is not
    if (empty_queue)
    {
        pthread_cond_signal(&queue_empty);
    }
}
Esempio n. 3
0
/**************
 * Exec targets with recursive calls
 **************/
void exec_target_rec(DIME_MSG* response_msg, int socket, rule_t* rule, rule_node_t* list) {
	str_node_t* sptr;
	rule_node_t* rptr;
	for(sptr = rule->deps; sptr != NULL; sptr = sptr->next) {
		// for each dependency, see if there's a rule, then exec that rule
		for(rptr = list; rptr != NULL; rptr = rptr->next) {
			if(strcmp(sptr->str, rptr->rule->target) == 0) {
				exec_target_rec(response_msg, socket, rptr->rule, list);
			}
		}
	}
	
	str_node_t* s_ptr;
	for(s_ptr = rule->commandlines; s_ptr != NULL; s_ptr = s_ptr->next) {
		if(!create_msg(response_msg, EXECUTE_ACK, s_ptr->str, strlen(s_ptr->str))) { error("Server failed to create proper response"); }
		send_msg(response_msg, socket);
	}
}
Esempio n. 4
0
/*********
 * Given a target list and the list of rules, execute the targets.
 *********/
int execute_targets(DIME_MSG* response_msg, int socket, char* targetv, rule_node_t* list) {
	rule_node_t* ptr = list;
	for(ptr = list; ptr != NULL; ptr = ptr->next) {
		if(strcmp(targetv, ptr->rule->target) == 0) {
			exec_target_rec(response_msg, socket, ptr->rule, list);
			break;
		}
	}
	if(ptr == NULL) {
		char message[504] = "Rule (";
		strcat(message, targetv);
		strcat(message, ") doesnt exist");
					
		if(!create_msg(response_msg, ERROR_MSG, message, strlen(message))) { error("Server failed to create proper response"); }

		
		send_msg(response_msg, socket);
		return 0;
	}
	
	return 1;
}