예제 #1
0
파일: lsuio.c 프로젝트: Nnamehack/uml_linux
int main (int argc, char **argv)
{
	struct uio_info_t *info_list, *p;

	program_name = argv[0];

	decode_switches (argc, argv);

	if (opt_help)
		usage(0);

	if (opt_version)
		version(0);

	info_list = uio_find_devices(uio_filter);
	if (!info_list)
		printf("No UIO devices found.\n");

	p = info_list;

	while (p) {
		uio_get_all_info(p);
		if (opt_verbose) uio_get_device_attributes(p);
		if (opt_mmap) uio_mmap_test(p);
		show_uio_info(p);
		p = p->next;
	}

	uio_free_info(info_list);
	exit (0);
}
예제 #2
0
파일: qdoc.c 프로젝트: kevinarpe/kx
int
main (int argc, char **argv)
{
  int i;

  program_name = argv[0];

  i = decode_switches (argc, argv);

  /* do the work */

  exit (0);
}
예제 #3
0
int main (int argc, char **argv)
{
	struct uio_info_t *info_list, *p;

	program_name = argv[0];

	decode_switches (argc, argv);
	if (uio_offset < 0) {
		fprintf(stderr, "Negative offsets are not supported.\n");
		usage (-EINVAL);
	}

	if (opt_help)
		usage(0);

	if (opt_version)
		version(0);

	info_list = uio_find_devices(uio_filter);
	if (!info_list)
		printf("No UIO devices found.\n");

	p = info_list;

	while (p) {
		char dev_name[16];
		int fd;
		uio_get_all_info(p);
		uio_get_device_attributes(p);
		snprintf(dev_name,sizeof(dev_name),"/dev/uio%d",p->uio_num);
		fd = open(dev_name,O_RDWR);
		if (fd<0) {
			close(fd);
			p = p->next;
			continue;
		}
		uio_single_mmap(p,uio_map,fd);
		if (opt_read) uio_read(p);
		if (opt_write) uio_write(p);
		close(fd);
		p = p->next;
	}

	uio_free_info(info_list);
	exit (0);
}
예제 #4
0
파일: main.c 프로젝트: ivohof/Barriers
/*============================*/
int main (int argc, char *argv[]) {
    int tmp;
    char *line;
    loc_min *LM;
    int *tm;
    int i;
    char signal[100]="", what[100]="", stuff[100]="";

    /* Parse command line */
    program_name = argv[0];

    opt.kT = -300;
    opt.MOVESET = "";
    opt.minh = 0.0000001;
    opt.label = 0; /* normally, use numbers for minima */
    GRAPH   = NULL;

    /* Try to parse head to determine graph-type */
    decode_switches (argc, argv);

    if (args_info.inputs_num > 0) {
        opt.INFILE = fopen(args_info.inputs[0], "r");
        if (opt.INFILE==NULL) nrerror("can't open file");
    } else {
        opt.INFILE = stdin;
    }

    line = get_line(opt.INFILE);
    if (line == NULL) {
        fprintf(stderr,"Error in input file\n");
        exit(123);
    }
    opt.seq = (char *) space(strlen(line) + 1);
    sscanf(line,"%s %d %99s %99s %99s", opt.seq, &tmp, signal, what, stuff);
    if(strcmp(stuff, "\0")!=0 && strncmp(what, "Q", 1)==0) { /* lattice proteins*/
        memset(opt.seq, 0, strlen(line)+1);
        strcpy(opt.seq, stuff);
    }

    if ((!opt.poset)&&(strcmp(signal,"::")!=0)) {
        int r, dim;
        /* in this case we have a poset file !!!! */
        r=sscanf(signal,"P:%d",&dim);
        if(r<1) {
            fprintf(stderr,
                    "Warning: obscure headline in input file\n");
            dim = 0;
        }
        if(dim>0) opt.poset  = dim;
    }

    if (opt.poset) { /* in this case we have a poset file !!!! */
        fprintf(stderr,
                "!!! Input data are a poset with %d objective functions\n",
                opt.poset);
        /* we have a SECIS design file */
        if (  ((GRAPH != NULL) && (strstr(GRAPH, "SECIS") != NULL))
                ||(strncmp(what, "SECIS", 5) == 0) )
        {
#if HAVE_SECIS_EXTENSION
            int len, max_m, min_as;
            char *sec_structure, *protein_sequence;

            if (sscanf(what,"SECIS,%d,%d", &max_m, &min_as) < 2) {
                fprintf(stderr,
                        "Error in input format for SECIS design !"
                        "expected format: SECIS,INT,INT\n"
                        "got: `%s'",
                        what);
                exit(EXIT_FAILURE);
            }

            free(line);
            line = get_line(opt.INFILE);
            len  = strlen(line);
            sec_structure    = (char*)calloc(len+1, sizeof(char));
            protein_sequence = (char*)calloc(len+1, sizeof(char));
            sscanf(line,"%s %s", sec_structure, protein_sequence);

            if (opt.want_verbose)
                fprintf(stderr,
                        "\nGraph is SECIS design with the following parameters:\n"
                        "Structure:   %s\n"
                        "Constraints: %s\n"
                        "Protein sequence: %s\n"
                        "Max. number of mutations : %d\n"
                        "Min. alignment score (aa): %d\n\n",
                        sec_structure,
                        opt.seq,
                        protein_sequence,
                        max_m,
                        min_as);

            initialize_SECIS(opt.seq, sec_structure, protein_sequence,
                             max_m, min_as);

            free(sec_structure);
            free(protein_sequence);
#else
            fprintf(stderr,
                    "You need to reconfigure barriers with the --with-secis"
                    " option\nto use barriers SECIS design extension\n");
            exit(EXIT_FAILURE);
#endif
        }
    }

    free(line);

    if (GRAPH==NULL)
        if(strlen(what)) GRAPH = what;

    if (GRAPH==NULL) GRAPH="RNA";
    opt.GRAPH=GRAPH;

    LM = barriers(opt);
    if (opt.INFILE != stdin) fclose(opt.INFILE);
    tm = make_truemin(LM);

    if(opt.poset) mark_global(LM);

    print_results(LM,tm,opt.seq);
    fflush(stdout);

    if (!opt.want_quiet) ps_tree(LM,tm,0);

    if (opt.rates || opt.microrates) {
        compute_rates(tm,opt.seq);
        if (!opt.want_quiet) ps_tree(LM,tm,1);
        print_rates(tm[0], "rates.out");
    }
    if (opt.poset) mark_global(LM);

    for (i = 0; i < args_info.path_given; ++i) {
        int L1, L2;
        sscanf(args_info.path_arg[i], "%d=%d", &L1, &L2);
        if ((L1>0) && (L2>0)) {
            FILE *PATH = NULL;
            char tmp[30];
            path_entry *path;

            path = backtrack_path(L1, L2, LM, tm);
            (void) sprintf(tmp, "path.%03d.%03d.txt", L1, L2);

            PATH = fopen (tmp, "w");
            if (PATH == NULL) nrerror("couldn't open path file");
            print_path(PATH, path, tm);
            /* fprintf(stderr, "%llu %llu\n", 0, MAXIMUM);   */
            fclose (PATH);
            fprintf (stderr, "wrote file %s\n", tmp);
            free (path);
        }
    }

    /* memory cleanup */
    free(opt.seq);
    free(LM);
    free(tm);
#if WITH_DMALLOC
    kill_hash(); /* freeing the hash takes unacceptably long */
#endif
    cmdline_parser_free(&args_info);
    exit(0);
}
예제 #5
0
파일: pear.c 프로젝트: B-UMMI/INNUca
int 
main (int argc, char * argv[])
{
  int                   i, trim_len_fw, trim_len_rev;
  //struct reads_info  ** ri_left;
  //struct reads_info  ** ri_right;
//  int                   cnt_reads_left;
//  int                   cnt_reads_right;
  int                   read_size;
  char                * out[4];
  FILE                * fd[4];
  int                   ass;
  double                uncalled_forward, uncalled_reverse;
  struct user_args      sw;
  struct emp_freq * ef;
  struct block_t fwd_block;
  struct block_t rev_block;
  char                  two_piece;
  int elms;

  if (!decode_switches (argc, argv, &sw))
   {
     /* TODO: Validate reads names */
     usage ();
     return (EXIT_FAILURE);
   }

  ef = (struct emp_freq *)malloc (sizeof(struct emp_freq));
  ef->freqa = ef->freqc = ef->freqg = ef->freqt = ef->total = ef->pa = ef->pc = ef->pg = ef->pt = ef->q = 0.25;

  init_scores(sw->phred_base, ef);
  /* read the two fastq files containing the left-end and right-end reads */
  //ri_left  = read_fastq(sw.fastq_left,  &cnt_reads_left);
  //ri_right = read_fastq(sw.fastq_right, &cnt_reads_right);

  //if (!validate_input (cnt_reads_left, cnt_reads_right))
  // {
  //   return (EXIT_FAILURE);
  // }

  // read_size = strlen (ri_left[0]->data);

  /* TODO: THIS IS WRONG!!!! TO GET EMPIRICAL FREQUENCIES WE NEED TO READ THE WHOLE FILE :-( */
  //ef = get_emp_freq (cnt_reads_right, read_size, fwd_block.reads, rev_block.reads);

  /* reverse the right ends */

  /* allocate memory for the assembled results */
  /*
  ai = (struct asm_info *) malloc (cnt_reads_left * sizeof(struct asm_info));
  for (i = 0; i < cnt_reads_left; ++i)
   {
     ai[i].data          = (char *) malloc ((2 * read_size + 1) * sizeof(char));
     ai[i].quality_score = (char *) malloc ((2 * read_size + 1) * sizeof(char));
   }
  */
  

  init_fastq_reader (sw.fastq_left, sw.fastq_right, sw.memory, &fwd_block, &rev_block);

  /* construct output file names */
  out[0] = makefilename (sw.outfile, ".assembled.fastq");
  out[1] = makefilename (sw.outfile, ".unassembled.forward.fastq");
  out[2] = makefilename (sw.outfile, ".unassembled.reverse.fastq");
  out[3] = makefilename (sw.outfile, ".discarded.fastq");

  fd[0] = fopen (out[0], "w");
  fd[1] = fopen (out[1], "w");
  fd[2] = fopen (out[2], "w");
  fd[3] = fopen (out[3], "w");


  while (1)
   {
     elms = get_next_reads (&fwd_block, &rev_block);
     if (!elms) break;
     read_size = strlen (fwd_block.reads[0]->data);
//     printf ("%d elms (Seq)\n", elms);
     
     //#pragma omp parallel shared(fwd_block.reads, rev_block.reads, ai) private(i, ass, uncalled, kassian_result) 
     #pragma omp parallel private(i, ass) 
     {
       /* flags[i] = 1 (assembled)  0 (discarded) 2 (unassembled) */
       #pragma omp for schedule (guided)
       for (i = 0; i < elms; ++ i)
        {
          mstrrev (rev_block.reads[i]->data);
          mstrcpl (rev_block.reads[i]->data);
          mstrrev (rev_block.reads[i]->qscore);
          if (sw.emp_freqs == 0)
           {
             ass = assembly (fwd_block.reads[i], rev_block.reads[i], &sw);
             *(fwd_block.reads[i]->qscore - 1) = ass;
           }
          else
          {
             ass = assembly_ef (fwd_block.reads[i], rev_block.reads[i], ef, &sw);
             *(fwd_block.reads[i]->qscore - 1) = ass;
           }
        }
     }

     for ( i = 0; i < elms; ++ i)
      {
        two_piece = *(fwd_block.reads[i]->data - 1);
        *(fwd_block.reads[i]->data - 1) = 0;

        if (*(fwd_block.reads[i]->qscore - 1) == 1)   /* assembled */
         {
           *(fwd_block.reads[i]->qscore - 1) = 0;
           fprintf (fd[0], "%s\n", fwd_block.reads[i]->header);
           if (!two_piece)
            {
              fprintf (fd[0], "%s\n", fwd_block.reads[i]->data);
            }
           else
            {
              fprintf (fd[0], "%s",   fwd_block.reads[i]->data);
              fprintf (fd[0], "%s\n", rev_block.reads[i]->data);
            }
           fprintf (fd[0], "+\n");

           if (!two_piece)
            {
              fprintf (fd[0], "%s\n", fwd_block.reads[i]->qscore);
            }
           else
            {
              fprintf (fd[0], "%s",   fwd_block.reads[i]->qscore);
              fprintf (fd[0], "%s\n", rev_block.reads[i]->qscore);
            }
         }
        else                                            /* not assembled */
         {
           *(fwd_block.reads[i]->qscore - 1) = 0;
           trim_len_fw  = trim (fwd_block.reads[i], &sw, read_size, &uncalled_forward);
           trim_len_rev = trim_cpl (rev_block.reads[i], &sw, read_size, &uncalled_reverse);
           if (trim_len_fw < sw.min_trim_len || trim_len_rev < sw.min_trim_len || uncalled_forward >= sw.max_uncalled || uncalled_reverse >= sw.max_uncalled)
            { /* discarded reads*/
              /* Maybe consider printing the untrimmed sequences */
              fprintf (fd[3], "%s\n", fwd_block.reads[i]->header);
              fprintf (fd[3], "%s\n+\n%s\n", fwd_block.reads[i]->data,  fwd_block.reads[i]->qscore);
              fprintf (fd[3], "%s\n", rev_block.reads[i]->header);
              fprintf (fd[3], "%s\n+\n%s\n", rev_block.reads[i]->data, rev_block.reads[i]->qscore); /* printing the reverse compliment of the original sequence */
            }
           else   /* unassembled reads*/
            {
              fprintf (fd[1], "%s\n", fwd_block.reads[i]->header);
              fprintf (fd[2], "%s\n", rev_block.reads[i]->header);
              fprintf (fd[1], "%s\n+\n%s\n", fwd_block.reads[i]->data,  fwd_block.reads[i]->qscore);
              fprintf (fd[2], "%s\n+\n%s\n", rev_block.reads[i]->data, rev_block.reads[i]->qscore); /* printing the reverse compliment of the original sequence */
            }
         }
      }


   }
  
  free (ef);
  free (out[0]);
  free (out[1]);
  free (out[2]);
  free (out[3]);

  destroy_reader ();

  /* TODO: Fix those file closings */
  fclose (fd[0]);
  fclose (fd[1]);
  fclose (fd[2]);
  fclose (fd[3]);
  
  return (0);
}
예제 #6
0
int
main (int argc, char **argv)
{
  int i;
  struct xs_handle *xs;
  xs_transaction_t th;
  char *path;
  int fd;
  fd_set set;
  int er;
  char **vec;
  unsigned int num_strings;
  char * buf;
  unsigned int len;
  char *program;
  char **arguments;
  int arguments_count;
  pid_t pid;
  int j;
  char *last_value = NULL;
  int status;

  program_name = argv[0];

  i = decode_switches (argc, argv);
  
  if (argc - i < 1)
    usage(1);
  
  path = argv[i++];
  if (argc - i > 0)
  {
    program = argv[i++];
    arguments_count = argc - i;
    
    arguments = malloc(sizeof(char*) * (argc - i + 2));
    arguments[0] = program;
    for (j=0; j<arguments_count; j++)
      arguments[j + 1] = argv[i + j];
    arguments[j + 1] = NULL;
  } else
  {
    program = NULL;
    arguments = NULL;
    arguments_count = 0;
  }
  
  if (want_verbose) {
    printf("Path: %s\n", path);
    if (program)
    {
      printf("Program: %s", program);
      for (i=1; i<arguments_count + 1; i++)
        printf(" %s", arguments[i]);
      printf("\n");
    }
  }
  
  /* Get a connection to the daemon */
  xs = xs_daemon_open();
  if ( xs == NULL ) xs = xs_domain_open();
  if ( xs == NULL ) {
    error("Unable to connect to XenStore");
    exit(1);
  }

  /* Create a watch on /local/domain/0/mynode. */
  er = xs_watch(xs, path, "token");
  if ( er == 0 ) {
    error("Unable to create watch");
    exit(1);
  }

  /* We are notified of read availability on the watch via the
   * file descriptor.
   */
  fd = xs_fileno(xs);
  while (1)
  {
    FD_ZERO(&set);
    FD_SET(fd, &set);
    /* Poll for data. */
    if ( select(fd + 1, &set, NULL, NULL, NULL) > 0
         && FD_ISSET(fd, &set))
    {
      /* num_strings will be set to the number of elements in vec
       * (typically, 2 - the watched path and the token) */
      vec = xs_read_watch(xs, &num_strings);
      if ( !vec ) {
        error("Unable to read watch");
        continue;
      }
      if (want_verbose)
        printf("Path changed: %s\n", vec[XS_WATCH_PATH]);
      /* Prepare a transaction and do a read. */
      th = xs_transaction_start(xs);
      buf = xs_read(xs, th, vec[XS_WATCH_PATH], &len);
      xs_transaction_end(xs, th, false);
      if (buf)
      {
        if (last_value && strcmp(buf, last_value) == 0) {
          if (want_verbose)
            printf("Value did not change\n");
          continue;
        }
      
        if (want_verbose)
          printf("New value: %s\n", buf);
          
        if (program) {
          pid = fork();
          if (pid == 0) {
            setenv("XENSTORE_WATCH_PATH", vec[XS_WATCH_PATH], 1);
            setenv("XENSTORE_WATCH_VALUE", buf, 1);
            for (i=0; arguments[i]; i++) {
              if (strcmp(arguments[i], "%v") == 0)
                arguments[i] = buf;
              else if (strcmp(arguments[i], "%p") == 0)
                arguments[i] = vec[XS_WATCH_PATH];
            }
            execvp(program, arguments);
            error("Unable to start program");
            exit(1);
          } else {
            waitpid(pid, &status, 0);
          }
        } else {
          if (!want_verbose)
            printf("%s\n", buf);
        }
        
        if (last_value)
          free(last_value);
        last_value = buf;
      }
    }
  }
  /* Cleanup */
  close(fd);
  xs_daemon_close(xs);
  free(path);

  exit(0);
}
예제 #7
0
파일: cage.c 프로젝트: anthonyu/cage
int main(int argc, char *argv[])
{

	int num;
	char *dir, **cmd;

#ifdef HAVE_LIBCAP
	cap_t caps;
	cap_value_t capv[7];
	int flags;
#else
	cap_user_header_t head;
	cap_user_data_t data;
	__u32 mask;
#endif


	uid = 0;
	gid = 0;
#if 0
	euid = geteuid();
	egid = getegid();
#endif

	num = decode_switches(argc, argv);

	dir = argv[num++];
	cmd = argv + num;

	if (dir == NULL)
		usage(EXIT_FAILURE);

	if (chdir(dir))
		die(dir);

	if (chroot(dir))
		die("chroot");

#ifdef HAVE_LIBCAP
	if (captxt != NULL) {
		if ((caps = cap_from_text(captxt)) == NULL)
		       die("cap_from_text");
	} else {
		if ((caps = cap_get_proc()) == NULL)
			die("cap_get_proc");
 
		capv[0] = CAP_SETPCAP;	  /* give caps to non-chrooted tasks */
		capv[1] = CAP_SYS_MODULE; /* hijack syscalls like chroot() */
		capv[2] = CAP_SYS_RAWIO;  /* raw disk access (needed?) */
		capv[3] = CAP_SYS_CHROOT; /* can't have this, obviously... */
		capv[4] = CAP_SYS_PTRACE; /* control other, non-caged tasks */
		capv[5] = CAP_SYS_ADMIN;  /* mount proc and mess with kmem */
#ifdef CAP_MKNOD
		capv[6] = CAP_MKNOD;      /* create block devices */

		flags = 7;
#else
		flags = 6;
#endif /* CAP_MKNOD */

		if (cap_set_flag(caps, CAP_EFFECTIVE, flags, capv, CAP_CLEAR))
		 	die("cap_set_flag");
	
		if (cap_set_flag(caps, CAP_PERMITTED, flags, capv, CAP_CLEAR))
			die("cap_set_flag");
	
		if (cap_set_flag(caps, CAP_INHERITABLE, flags, capv, CAP_CLEAR))
			die("cap_set_flag");

	}

	if (cap_set_proc(caps))
		die("cap_set_proc");
	
	cap_free(&caps);
#else 
	if ((head = malloc(8)) == NULL)
		die("malloc()");

	if ((data = malloc(3 * 4)) == NULL)
		die("malloc()");

	head->pid = 0;
	head->version = _LINUX_CAPABILITY_VERSION;

	if (capget(head, data))
		die("capget");

 	mask  = (1 << CAP_SETPCAP);	/* give caps to non-chrooted tasks */
 	mask |= (1 << CAP_SYS_MODULE);	/* hijack syscalls such as chroot() */
 	mask |= (1 << CAP_SYS_RAWIO);	/* raw disk access (needed?) */
 	mask |= (1 << CAP_SYS_CHROOT);  /* can't have this, obviously... */
 	mask |= (1 << CAP_SYS_PTRACE);	/* control other, non-caged tasks */
 	mask |= (1 << CAP_SYS_ADMIN);   /* mount proc and mess with kmem */
#ifdef CAP_MKNOD
 	mask |= (1 << CAP_MKNOD);	/* create block devices */
#endif /* CAP_MKNOD */

	data->permitted &= ~mask;
	data->effective &= ~mask;
	data->inheritable &= ~mask;

	if (capset(head, data))
		die("capset()");

#endif /* HAVE_LIBCAP */

	if ((gid) && (setgid(gid)))
		die("setgid");

	if ((uid) && (setuid(uid)))
		die("setuid");

	execvp(cmd[0], cmd);
	
	die(cmd[0]);
}
예제 #8
0
파일: interlogd.c 프로젝트: CESNET/glite-lb
int
main (int argc, char **argv)
{
    int i;
    char *p;
    edg_wll_GssStatus gss_stat;
    int ret;
    FILE *pidf;

#ifndef IL_NOTIFICATIONS
    p = strdup(argv[0]);
    program_name = basename(p);
    if (strcmp(program_name, "glite-lb-proxy-interlogd") == 0) {
        file_prefix = DEFAULT_PROXY_PREFIX;
        socket_path = DEFAULT_PROXY_SOCKET;
        pidfile = DEFAULT_PROXY_PIDFILE;
    }
    free(p);
#endif
    program_name = argv[0];

    setlinebuf(stdout);
    setlinebuf(stderr);

    if ((p = getenv("EDG_WL_INTERLOG_TIMEOUT"))) TIMEOUT = atoi(p);

    i = decode_switches (argc, argv);

    if(glite_common_log_init()) {
        fprintf(stderr, "glite_common_log_init() failed, exiting.\n");
        exit(EXIT_FAILURE);
    }

    /* parse config file, if any */
    if(conf_file != NULL) {
        config = load_conf_file(conf_file);
    }

    /* check for reasonable queue lengths */
    if((queue_size_low == 0 && queue_size_high > 0) ||
            (queue_size_low > queue_size_high)) {
        glite_common_log(LOG_CATEGORY_CONTROL, LOG_PRIORITY_FATAL, "max queue length -Q must be greater than low queue length -q, both or none must be specified!");
        exit(EXIT_FAILURE);
    }

    /* force -b if we do not have log server */
    if(log_server == NULL) {
        log_server = strdup(DEFAULT_LOG_SERVER);
        bs_only = 1;
    }

    /* initialize error reporting */
    if(init_errors()) {
        glite_common_log(LOG_CATEGORY_CONTROL, LOG_PRIORITY_FATAL, "Failed to initialize error message subsystem. Exiting.");
        exit(EXIT_FAILURE);
    }

    if (signal(SIGPIPE, SIG_IGN) == SIG_ERR
            || signal(SIGABRT, handle_signal) == SIG_ERR
            || signal(SIGTERM, handle_signal) == SIG_ERR
            || signal(SIGINT, handle_signal) == SIG_ERR) {
        glite_common_log(LOG_CATEGORY_CONTROL, LOG_PRIORITY_FATAL, "Failed to setup signal handlers: %s, exiting.",
                         strerror(errno));
        exit(EXIT_FAILURE);
    }

    /* just try it before deamonizing to be able to complain aloud */
    if (!(pidf = fopen(pidfile,"w"))) {
        perror(pidfile);
        exit(EXIT_FAILURE);
    }
    fclose(pidf);

    if(!debug &&
            (daemon(0,0) < 0)) {
        glite_common_log(LOG_CATEGORY_CONTROL, LOG_PRIORITY_FATAL, "Failed to daemonize itself: %s, exiting.",
                         strerror(errno));
        exit(EXIT_FAILURE);
    }

    pidf = fopen(pidfile,"w");
    assert(pidf); /* XXX */
    fprintf(pidf,"%d\n",getpid());
    fclose(pidf);

    umask(S_IRWXG | S_IRWXO);

#ifdef LB_PERF
    /* this must be called after installing signal handlers */
    glite_wll_perftest_init(NULL, /* host */
                            NULL, /* user */
                            NULL, /* test name */
                            event_source,
                            njobs);
#endif

    if(input_queue_attach() < 0) {
        glite_common_log(LOG_CATEGORY_CONTROL, LOG_PRIORITY_FATAL, "Failed to initialize input queue: %s",
                         error_get_msg());
        exit(EXIT_FAILURE);
    }
    glite_common_log(LOG_CATEGORY_CONTROL, LOG_PRIORITY_INFO, "Initialized input queue.");

    /* initialize output queues */
    if(queue_list_init(log_server) < 0) {
        glite_common_log(LOG_CATEGORY_CONTROL, LOG_PRIORITY_FATAL, "Failed to initialize output event queues: %s",
                         error_get_msg());
        exit(EXIT_FAILURE);
    }
    glite_common_log(LOG_CATEGORY_CONTROL, LOG_PRIORITY_INFO, "Initialized event queues.");
    if(lazy_close)
        glite_common_log(LOG_CATEGORY_CONTROL, LOG_PRIORITY_INFO, "  using lazy mode when closing connections, timeout %d",
                         default_close_timeout);

    /* get credentials */
    if (CAcert_dir)
        setenv("X509_CERT_DIR", CAcert_dir, 1);
    if(edg_wll_gss_initialize()) {
        glite_common_log(LOG_CATEGORY_CONTROL, LOG_PRIORITY_FATAL, "Failed to initialize GSS.");
        exit(EXIT_FAILURE);
    }
    ret = edg_wll_gss_watch_creds(cert_file,&cert_mtime);
    if (ret < 0)
        glite_common_log(LOG_CATEGORY_SECURITY,LOG_PRIORITY_WARN,"edg_wll_gss_watch_creds failed, unable to access credentials\n");
    cred_handle = malloc(sizeof(*cred_handle));
    if(cred_handle == NULL) {
        glite_common_log(LOG_CATEGORY_CONTROL, LOG_PRIORITY_FATAL, "Failed to allocate structure for credentials.");
        exit(EXIT_FAILURE);
    }
    cred_handle->creds = NULL;
    cred_handle->counter = 0;
    ret = edg_wll_gss_acquire_cred(cert_file, key_file, GSS_C_INITIATE, &cred_handle->creds, &gss_stat);
    if (ret) {
        char *gss_err = NULL;

        if (ret == EDG_WLL_GSS_ERROR_GSS)
            edg_wll_gss_get_error(&gss_stat, "edg_wll_gss_acquire_cred_gsi()", &gss_err);
        glite_common_log(LOG_CATEGORY_SECURITY, LOG_PRIORITY_FATAL, "Failed to load GSI credential: %s",
                         (gss_err) ? gss_err : "edg_wll_gss_acquire_cred_gsi() failed");
        if (gss_err)
            free(gss_err);
        if(gss_stat.minor_status != 0) {
            exit(EXIT_FAILURE);
        } else {
            glite_common_log(LOG_CATEGORY_SECURITY, LOG_PRIORITY_WARN, "Continuing unauthenticated (yet).");
        }
    }
    if(cred_handle && cred_handle->creds) {
        glite_common_log(LOG_CATEGORY_SECURITY, LOG_PRIORITY_INFO, "Using certificate %s", cred_handle->creds->name);
    }

    /* parse config, initialize plugins */
    glite_common_log(LOG_CATEGORY_CONTROL, LOG_PRIORITY_INFO, "Initializing plugins:\n");
    if(config) {
        char *s = strstr(config, "[interlogd]");
        char *p;
        char name[MAXPATHLEN+1];

        if(s) {
            /* next line */
            s = strchr(s, '\n');
            if(s) s++;
            while(s) {
                if(*s == 0 || *s == '[')
                    break;
                /* parse line */
                p = strchr(s, '\n');
                if(p) {
                    *p = 0;
                }
                /* XXX possible overflow by long line in config file */
                ret = sscanf(s, " plugin =%s", name);
                if(p) *p = '\n';
                if(ret > 0) {
                    glite_common_log(LOG_CATEGORY_CONTROL, LOG_PRIORITY_INFO, "  loading plugin %s\n", name);
                    if(plugin_mgr_init(name, config) < 0) {
                        glite_common_log(LOG_CATEGORY_CONTROL, LOG_PRIORITY_ERROR, "Failed to load plugin %s: %s\n", name, error_get_msg());
                    }
                }
                s = p + 1;
            }
        }
    }

#ifndef PERF_EMPTY
    /* find all unsent events waiting in files */
#ifdef LB_PERF
    if(norecover) {
        if(event_store_init(file_prefix) < 0) {
            glite_common_log(LOG_CATEGORY_CONTROL, LOG_PRIORITY_FATAL, "Failed to initialize event stores: %s",
                             error_get_msg());
            exit(EXIT_FAILURE);
        }
    } else
#endif
    {
        pthread_t rid;

        if(pthread_create(&rid, NULL, recover_thread, NULL) < 0) {
            glite_common_log(LOG_CATEGORY_CONTROL, LOG_PRIORITY_FATAL, "Failed to start recovery thread: %s", strerror(errno));
            exit(EXIT_FAILURE);
        }
        pthread_detach(rid);
        glite_common_log(LOG_CATEGORY_CONTROL, LOG_PRIORITY_INFO, "Started recovery thread.");
    }
#endif

    glite_common_log(LOG_CATEGORY_CONTROL, LOG_PRIORITY_INFO, "Using %d threads for parallel delivery.", parallel);
    glite_common_log(LOG_CATEGORY_CONTROL, LOG_PRIORITY_INFO, "Entering main loop.");

    /* do the work */
    if(loop() < 0) {
        glite_common_log(LOG_CATEGORY_CONTROL, LOG_PRIORITY_FATAL, "Fatal error: %s", error_get_msg());
        if (killflg) {
            input_queue_detach();
            unlink(pidfile);
            exit(EXIT_FAILURE);
        }
    }
    glite_common_log(LOG_CATEGORY_CONTROL, LOG_PRIORITY_INFO, "Done!");
    input_queue_detach();
    unlink(pidfile);

    exit (0);
}
예제 #9
0
파일: bg.c 프로젝트: wolneykien/engrave
	  }
	  if (buf != NULL)
		  free(buf);
  }

  /* Начало работы фильтра. Обработка аргументов коммандной строки */

  /* Получение имени комманды. */
  program_name = argv[0];

  /* Инициализация функции аварийной очистки. */
  init_cleanup(program_name);
  push_cleanup(cleanup);

  /* Разбор аргуентов командной строки. */
  opt_r = decode_switches (argc, argv, EXIT_FAILURE, long_options, option_vars, &usage_header, &usage_params);

  /* Проверка наличия параметров изображения. */
  if (!width || !height || !hres || !vres) {
	  fprintf(stderr, "%s: WIDTH, HEIGHT, HRES & VRES should be specified.\n", program_name);
	  /* Выход с признаком ошибки, если были переданы не все параметры. */
	  exit(EXIT_FAILURE);
  }
  
  /* Инициализация счётчика цветовых каналов и размера отсчёта в соответствие с
   * цветовой схемой изображения.
   */
  if (is_cmyk) {
	  ss = 4;	/* 4 байта для CMYK */
	  c0 = 0;	/* 4 цвета, с 0 */
	  cN = 3;	/* по 3 */
예제 #10
0
파일: gapsmis.c 프로젝트: solonas13/gapsmis
int main ( int argc, char ** argv)
 {
   struct TSwitch  sw;
   char   * out_file;

   unsigned int MAXnumgaps;	//input argument		
   double gap_open_pen;		//input argument
   double gap_extend_pen;	//input argument
   unsigned int scoring_matrix; //input argument
   unsigned int MAXgap;	
   unsigned int num_mat;        //input argument + 1

   double MAXscore;		//to be computed
   unsigned int MINnumgaps;	//to be computed		
   
   unsigned int istart;		//where to start backtracing
   unsigned int jstart;		//where to start backtracing
   unsigned int iend;		//where to end backtracing
   unsigned int jend;		//where to end backtracing
   unsigned int * gaps_pos;	//position of the gap(s)
   unsigned int * gaps_len;	//len of the gap(s)
   unsigned int * where;	//where is the gap(s): text [1] or pattern [2]
   
   struct TSeq * t;		//text t
   unsigned int n; 		//length of text
   struct TSeq * p;		//pattern p
   unsigned int m; 		//length of pattern
   unsigned int L;		//local alignment	
   
   double ***       G; 		//dynamic programming matrix
   int *** 	 H; 		//backtracing matrix
   	
   unsigned int swap;           //swap the text and the pattern in case m < n        
   unsigned int i, j;

   /* checks the arguments */
   i = decode_switches ( argc, argv, &sw );

   if ( i < 5 || ! sw . seq_a || ! sw . seq_b ) 
    {
      usage ();
      return ( 1 );
    }
   else 
    {
      gap_open_pen   = - sw . gap_open_pen;	//the penalties should have a negative value
      gap_extend_pen = - sw . gap_extend_pen;
      out_file       =   sw . out_file;
      L		     =   sw . L;

      if ( ! strcmp ( "EDNAFULL", sw . matrix ) )       scoring_matrix = 0;
      else if ( ! strcmp ( "EBLOSUM62", sw . matrix ) ) scoring_matrix = 1;
      else
       {
         fprintf ( stderr, "Error: scoring matrix argument should be `EDNAFULL' for nucleotide sequences or `EBLOSUM62' for protein sequences!!!\n" );
         return ( 1 );
       }
      if ( L > 1 )
       {
         fprintf (stderr, "Error: wrong argument with L: should be either 0 (semi-global) or 1 (local)\n" );
         return ( 1 );
       }
    }
   
   /* reads the text */
   t = read_fasta_file ( sw . seq_a );
   if ( ! t )
    {
      fprintf (stderr, "Error: cannot read file %s!!!\n", sw . seq_a );
      return ( 1 );
    }
   if ( ! t -> header ) t -> header = strdup ( "Seq A" );
   
   /* reads the pattern */
   p = read_fasta_file ( sw . seq_b );
   if ( ! p )
    {
      fprintf( stderr, "Error: cannot read file %s!!!\n", sw . seq_b );
      return ( 1 );
    }
   if ( ! p -> header ) p -> header = strdup ( "Seq B" );
   
   /* calculate text's and pattern's length */
   n = strlen ( t -> data );
   m = strlen ( p -> data );
   
   /* checks the lengths of text and pattern and swaps if needed */
   if ( m > n )
    {
      swap_txt_pat ( &t, &n, &p, &m );
      swap = 1;
    }
   else
      swap = 0;
   
   /* checks the max num of gaps: MAXnumgaps < n */
   MAXnumgaps =  ( sw . max_num_gaps <= -1 ) ?  2 : sw . max_num_gaps;
   if( MAXnumgaps >= n )
    {
      fprintf ( stderr, "Error: the max gap length should be less than the length of the text!!!\n" );
      return ( 1 );
    }

   if ( L == 1 ) num_mat = MAXnumgaps + 1;
   else num_mat = MAXnumgaps;

   MAXgap =  ( sw . max_gap <= -1 ) ?  n - 1 : sw . max_gap;
   if( MAXgap >= n )
    {
      fprintf ( stderr, "Error: the max gap length should be less than the length of the text!!!\n" );
      return ( 1 );
    }
   
   /* 3d dynamic memory allocation for matrices G and H*/
   if( ( G = ( double *** ) malloc ( ( num_mat ) * sizeof( double ** ) ) ) == NULL )
    {
      fprintf( stderr, "G could not be allocated\n" );
      return 0;
    } 
	
   for ( i = 0; i < num_mat; i ++ )
    {
      if( ( G[i] = ( double ** ) malloc ( ( n + 1 ) * sizeof( double * ) ) ) == NULL )
       {
         fprintf( stderr, "G could not be allocated\n" );
         return 0;
       }
 
      if( ( G[i][0] = ( double * ) calloc ( ( n + 1 ) * ( m + 1 ), sizeof( double ) ) ) == NULL )
       {
	  fprintf( stderr, "G could not be allocated\n" );
	  return 0;
       } 

      for ( j = 1; j < n + 1; j++ )
        G[i][j] = ( void * ) G[i][0] + j * ( m + 1 ) * sizeof( double );
    }

   if( ( H = ( int *** ) malloc ( ( num_mat ) * sizeof( int ** ) ) ) == NULL )
    {
      fprintf( stderr, "H could not be allocated\n" );
      return 0;
    } 
	
   for ( i = 0; i < num_mat; i ++ )
    {
      if( ( H[i] = ( int ** ) malloc ( ( n + 1 ) * sizeof( int * ) ) ) == NULL )
       {
         fprintf( stderr, "H could not be allocated\n" );
         return 0;
       }
 
      if( ( H[i][0] = ( int * ) calloc ( ( n + 1 ) * ( m + 1 ), sizeof( int ) ) ) == NULL )
       {
	  fprintf( stderr, "H could not be allocated\n" );
	  return 0;
       } 

      for ( j = 1; j < n + 1; j++ )
        H[i][j] = ( void* ) H[i][0] + j * ( m + 1 ) * sizeof( int );
    }

   /* dynamic programming algorithm */
   if ( L == 0 )	
    {
     if ( MAXgap == n - 1 )
      {
        if ( ! ( dp_algorithm( G, MAXnumgaps, H, t -> data, n, p -> data, m, scoring_matrix, gap_open_pen, gap_extend_pen ) ) )
         {
           fprintf ( stderr, "Error: dp_algorithm() failed!!!\n" );
           return ( 1 );	
         }
      }
     else
      {
        if ( ! ( dp_algorithm_pruned( G, MAXnumgaps, H, t -> data, n, p -> data, m, scoring_matrix, gap_open_pen, gap_extend_pen, MAXgap ) ) )
         {
           fprintf ( stderr, "Error: dp_algorithm_pruned() failed!!!\n" );
           return ( 1 );	
         }
      }
    }
   else
    {
     if ( MAXgap == n - 1 )
      {
        if ( ! ( dp_algorithm_lcl( G, MAXnumgaps, H, t -> data, n, p -> data, m, scoring_matrix, gap_open_pen, gap_extend_pen ) ) )
         {
           fprintf ( stderr, "Error: dp_algorithm() failed!!!\n" );
           return ( 1 );	
         }
      }
     else
      {
        fprintf ( stderr, "Error: option `- m' is only for global alignment!!!\n" );
        return ( 1 );	
      }
    }


   MINnumgaps = 0;	//to be computed		
   /* finds the optimal alignment based on the matrices scores */
   if ( L == 0 ) opt_solution ( G, MAXnumgaps, n, m, &MAXscore, &istart, &MINnumgaps );
   if ( L == 1 ) opt_solution_lcl ( G, MAXnumgaps, n, m, &MAXscore, &istart, &jstart, &MINnumgaps );

   if( ( gaps_pos = ( unsigned int * ) calloc ( MINnumgaps, sizeof( unsigned int ) ) ) == NULL )
    {
      fprintf( stderr, "gaps_pos could not be allocated\n" );
      return 0;
    }

   if( ( gaps_len = ( unsigned int * ) calloc ( MINnumgaps, sizeof( unsigned int ) ) ) == NULL )
    {
      fprintf( stderr, "gaps_pos could not be allocated\n" );
      return 0;
    }

   if( ( where = ( unsigned int * ) calloc ( MINnumgaps, sizeof( unsigned int ) ) ) == NULL )
    {
      fprintf( stderr, "where could not be allocated\n" );
      return 0;
    }
 
   /* computes the position of the gap */
   if ( L == 0 ) backtracing ( H[MINnumgaps - 1], m, n, istart, gaps_pos, MINnumgaps, gaps_len, where );
   if ( L == 1 ) backtracing_lcl ( G[MINnumgaps], m, n, H[MINnumgaps], istart, jstart, gaps_pos, MINnumgaps, gaps_len, where, &iend, &jend );

   #if 0
   int s;
   for ( s = 0;  s < num_mat; s++ )
        {

                for(i = 0; i < n+1; i++)                //Matrix G output
                {
                        for(j = 0; j < m+1; j++)
                        {
                                fprintf( stderr,"%d\t", (int) G[s][i][j] );
                        }
                        fprintf(stderr,"\n");
                }

                fprintf(stderr,"\n");

                #if 1
                for(i = 0; i < n+1; i++)                //Matrix H output
                {
                        for(j = 0; j < m+1; j++)
                        {
                                fprintf( stderr,"%d\t", H[s][i][j]);
                        }
                        fprintf(stderr,"\n");
                }

                fprintf(stderr,"\n");
                #endif
        }
   if ( L == 1 ) fprintf( stderr,"\n[%d,%d]-->[%d,%d]\n", istart, jstart, iend, jend );
   #endif

   /* outputs the results */
   if ( L == 0 )
     if ( ! ( results ( out_file, t, n, p, m, MAXscore, gaps_pos, MINnumgaps, gaps_len, where, swap, scoring_matrix, gap_open_pen, gap_extend_pen, L ) ) )
      {
        fprintf(stderr, "Error: results() failed!!!\n");
        return ( 1 );	
      }

   if ( L == 1 )
     if ( ! ( results_lcl ( out_file, t, n, p, m, MAXscore, gaps_pos, MINnumgaps, gaps_len, where, istart, iend, jstart, jend, swap, scoring_matrix, gap_open_pen, gap_extend_pen, L ) ) )
      {
        fprintf(stderr, "Error: results() failed!!!\n");
        return ( 1 );	
      }

   for ( i = 0;  i < num_mat; i++ )
    {
      free ( G[i][0] );
      free ( G[i] );
      free ( H[i][0] );
      free ( H[i] );
    }
   free ( G );
   free ( H );
   free ( gaps_pos );
   free ( gaps_len );
   free ( where );
   free ( t -> header );
   free ( p -> header );
   free ( t );
   free ( p );
   free ( sw . out_file );
   free ( sw . matrix );
   return ( 0 );
 }