Example #1
0
//--------------------------------------------------------------------------------------------------------
// Function called by main thread. Depending on the arguments, processes all desired rules. Copy and
// paste of provide function, execute_targets.
//--------------------------------------------------------------------------------------------------------
void main_thread(int argc, char* argv[], rule_node_t* list)
{
	rule_node_t* ptr = list;
	int i;
	if(argc == 0) 
	{
		rule_node_t* curr_rule = list;
			
			for(;curr_rule != NULL; curr_rule = curr_rule->next)
			{
				//printf("PROCESS: %s\n", curr_rule->rule->target);
				process_target(curr_rule->rule, list);
			}
		/*
		// no target specified on command line!
		for(ptr = list; ptr != NULL; ptr = ptr->next);
		{
			
			if(ptr == NULL) 
			{
				fprintf(stderr, "Error, no targets in dimefile.\n");
			}
			else
			{
				printf("PROCESS:%s\n", ptr->rule->target);
				process_target(ptr->rule, list);
			}
			printf("HI\n");
		}
		*/
	} 
	else 
	{
		for(i = 0; i < argc; i++) 
		{
			for(ptr = list; ptr != NULL; ptr = ptr->next) 
			{
				if(strcmp(argv[i], ptr->rule->target) == 0) 
				{
					process_target(ptr->rule, list);
					break;
				}
			}
			if(ptr == NULL) 
			{
				fprintf(stderr, "Error, target '%s' not found.\n",argv[i]);
				exit(1);
			}
		}
	}
}
Example #2
0
/*
 * Return: 0 for success.
 */
int ipacman_sync_packages(alpm_list_t *targets)
{
	int ret = 0;
	alpm_list_t *i;
	alpm_list_t *sync_dbs = alpm_get_syncdbs(handle);

	if(sync_dbs == NULL) {
		printf("no usable package repositories configured.\n");
		return 1;
	}

	/* ensure all known dbs are valid */
	for(i = sync_dbs; i; i = alpm_list_next(i)) {
		alpm_db_t *db = i->data;
		if(alpm_db_get_valid(db)) {
			printf("database '%s' is not valid (%s)\n",
					alpm_db_get_name(db), alpm_strerror(alpm_errno(handle)));
			ret = 1;
		}
	}
	if (ret)
		return ret;

	/* Step 1: create a new transaction... */
	ret = alpm_trans_init(handle, ALPM_TRANS_FLAG_FORCE);
	if(ret == -1) {
		trans_init_error(handle);
		return 1;
	}

	/* process targets */
	for(i = targets; i; i = alpm_list_next(i)) {
		const char *targ = i->data;
		if(process_target(targ, ret) == 1) {
			ret = 1;
		}
	}

	if(ret) {
		if(alpm_trans_release(handle) == -1) {
			printf("failed to release transaction (%s)\n", alpm_strerror(alpm_errno(handle)));
		}
		return ret;
	}

	return sync_prepare_execute();
}
Example #3
0
//--------------------------------------------------------------------------------------------------------
// Recursively add targets and their dependencies to the correct queue. Pretty much a copy and past
// of exe_target_rec with some additions.
//--------------------------------------------------------------------------------------------------------
void process_target(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) 
			{
				process_target(rptr->rule, list);
			}
		}
	}

	//rule has no dependencies add it to in_q
	if(rule->deps == NULL)
	{
		if(add_rule(IN_QUEUE, rule))
		{
			//printf("Rule added to in_q (%s) \n", rule->target);

			//notify workers of new job
			sem_post(&jobs_sem);
		}
	}
	else //rule has dependencies so add to dep queue and post the dep_sem
	{
		if(add_rule(DEP_QUEUE, rule))
		{
			//Update dep_q semaphore
			sem_post(&dep_q->sem);
			printf("Rule added to dep_q (%s) (%s) \n", rule->target, rule->deps->str);
		}
	}
}
/**
 *  Application entry point.
 */
int
vosesame (int argc, char *argv[], size_t *reslen, void **result)
{
    char **pargv, optval[SZ_FNAME];
    register int  ch=0, arg_index=1, narg=0;
    int    pos=0;


    /*  Process command line arguments and initialize.
     */
    nflags   = 0;
    out	     = stdout;
    *reslen  = 0;
    *result  = NULL;
    memset (flags, 0, MAX_FLAGS);

    pargv = vo_paramInit (argc, argv, opts, long_opts);
    while ((ch = vo_paramNext (opts,long_opts,argc,pargv,optval,&pos)) != 0) {
	if (ch > 0) {
	    switch (ch) {
	    case '%':    Tests (optval);  		return (self.nfail);
	    case 'h':    Usage();     			return (OK);
	    case 'v':    verbose++; quiet=0;		break;
	    case 'q':    quiet++;   verbose=0;		break;

	    case 'a':    all_flags++; 			break;
	    case 'i':    invert++; 			break;
	    case 'd':    flags[nflags++] = F_DEC; 	break;
	    case 'e':    flags[nflags++] = F_ERR; 	break;
	    case 'n':    flags[nflags++] = F_NAM; 	break;
	    case 's':    flags[nflags++] = F_SEX; 	break;
	    case 't':    flags[nflags++] = F_TYP; 	break;

	    case 'p':
		/* Check for a comma-separate position, break it up
		** if necessary.
		*/
		user_pos++;
		if ((sep = (char *) strchr (optval, (int)','))) {
		    *sep = '\0';
		    u_dec = strdup (++sep);
		    u_ra  = strdup (optval);
		}
		if (debug) fprintf (stderr, "ra='%s' dec='%s'\n",  u_ra,u_dec);
		if (u_ra == NULL || u_dec == NULL) {
		    fprintf (stderr, "ERROR: Invalid '-p' syntax\n");
		    return (ERR);
		}

		/* Process a 'fake record' based on the position given.
		** Note this is done using the other options given up to
		** this point.
		*/
		procUserCoord (u_ra, u_dec);
		break;

	    case 'f':
		if (voc_initVOClient("runid=voc.vosesame,use_cache=no") != OK) {
		    fprintf (stderr, "ERROR: cannot open VOClient\n");
		    return (ERR);
		}
		break;

	    case 'o':    
		output = strdup (optval);
		if ((out = fopen (output, "w+")) == (FILE *)NULL) {
		    fprintf (stderr, "Cannot open file '%s'\n", output);
		    return (ERR);
		}
		break;

	    case 'A':    delim = ' ';			break;
	    case 'C':    delim = ',',  format = 0;	break;
	    case 'F':    format++;			break;
	    case 'H':    header++;			break;
	    case 'T':    delim = '\t', format = 0;	break;

	    case 'I':    /*  FIXME  */
			 system ("/bin/rm -f ~/.voclient/cache/sesame/*");
			 exit (0);;
	    }

        } else if (ch == PARG_ERR) {
            return (ERR);

	} else {
	    /* Arguments without a leading '-' are assumed to be either
	    ** target names or @-files.  We let the processing routine
	    ** figure out how to handle it.
	    */
	    if ((status = process_target (optval)) != OK) {
		if (!quiet) {
		    fprintf (stderr, "Warning: Cannot resolve target '%s'\n",
		        optval);
		}
	    }
	    narg++;
	}
	arg_index++;

	/* Final error check for argument overflow -- should never happen.
	if (arg_index > argc)
	    break;
	*/
        if (narg > MAX_FLAGS) {
	    fprintf (stderr, "ERROR: Too many arguments specified\n");
	    return (1);
        }
    }


    /* Process the arguments from the standard input. 
    */
    if (!ntargets) {
        char *name = calloc (1, SZ_FNAME);

        while (fgets (name, SZ_FNAME, stdin)) {
	    name[strlen(name)-1] = '\0';		/* kill newline	*/
	    if ((status += process_target (name)) != OK) {
		if (!quiet) {
		    fprintf (stderr, 
			"Warning: cannot resolve target/access file '%s'\n",
			name);
		}
	    } else
		ntargets++;
	}
        free (name);
    }

    if (!ntargets)
	fprintf (stderr, "Warning: No target name specified.\n");

    if (u_ra)   free ((void *) u_ra);
    if (u_dec)  free ((void *) u_dec);
    if (output) free ((void *) output);

    if (out != stdout)
	fclose (out);

    return ( status );
}