コード例 #1
0
ファイル: tests_zinm.c プロジェクト: ezorita/zerone
void
test_err_handler
(void)
{

   int obs[] = {6,2,2,3,2,0,1,2,5,2,0,0,0};
   zinb_par_t *par = NULL;

   set_zinb_err_handler(dummy_handler);

   redirect_stderr();
   set_alloc_failure_countdown_to(0);
   par = mle_zinb(obs, 13);
   reset_alloc();
   unredirect_stderr();
   test_assert(par == NULL);
   test_assert(strcmp(caught_in_stderr(), "dummy") == 0);

   redirect_stderr();
   set_alloc_failure_countdown_to(0);
   par = mle_zinb(obs, 13);
   reset_alloc();
   unredirect_stderr();
   test_assert(par == NULL);
   test_assert(strcmp(caught_in_stderr(), "dummy") == 0);

   // Reset error handler.
   set_zinb_err_handler(NULL);

   redirect_stderr();
   set_alloc_failure_countdown_to(0);
   par = mle_zinb(obs, 13);
   reset_alloc();
   unredirect_stderr();
   test_assert(par == NULL);
   test_assert(strncmp(caught_in_stderr(), "memory error", 12) == 0);

   redirect_stderr();
   set_alloc_failure_countdown_to(0);
   par = mle_nb(obs, 13);
   reset_alloc();
   unredirect_stderr();
   test_assert(par == NULL);
   test_assert(strncmp(caught_in_stderr(), "memory error", 12) == 0);

   free(par);

}
コード例 #2
0
ファイル: tests_zinm.c プロジェクト: ezorita/zerone
void
test_compress_histo
(void)
{

   histo_t *histo = new_histo();
   test_assert_critical(histo != NULL);
   for (size_t i = 0 ; i < 4096 ; i += 2) {
      test_assert(histo_push(&histo, i) == 0);
   }

   tab_t *tab;
   tab = compress_histo(histo);
   test_assert_critical(tab != NULL);
   test_assert(tab->size == 2048);
   for (size_t i = 0 ; i < tab->size ; i++) {
      test_assert(tab->val[i] == 2*i);
      test_assert(tab->num[i] == 1);
   }

   free(tab);

   redirect_stderr();
   set_alloc_failure_rate_to(1.0);
   tab = compress_histo(histo);
   reset_alloc();
   unredirect_stderr();
   test_assert(tab == NULL);
   test_assert(strcmp(caught_in_stderr(), "") != 0);

   free(histo);
   return;

}
コード例 #3
0
ファイル: test_io.c プロジェクト: ezorita/mapper
void
test_io_stream_open
(void)
{
   iostream_t * stream;

   // Test invalid arguments.
   redirect_stderr();
   stream = io_stream_open("fake-file.txt");
   test_assert(stream == NULL);
   unredirect_stderr();

   // Load files.
   stream = io_stream_open("examples/io_input.raw");
   test_assert(stream != NULL);
   io_stream_free(stream);
 
   stream = io_stream_open("examples/io_input.fasta");
   test_assert(stream != NULL);
   io_stream_free(stream);

   stream = io_stream_open("examples/io_input.fastq");
   test_assert(stream != NULL);
   io_stream_free(stream);
}
コード例 #4
0
ファイル: test_mem_index.c プロジェクト: ezorita/mapper
void
test_mem_index_read
(void)
{
   redirect_stderr();
   
   index_t * index = index_build("examples/repeats.fa", "test_base30");
   test_assert_critical(index != NULL);
   test_assert(index_ann_new(25, 1, 1, index) == 0);

   // Set alloc failure rate to 0.1.
   set_alloc_failure_rate_to(0.1);
   for (int i = 0; i < 1000; i++) {
      index_t * index_i = index_read("test_base30");
      index_free(index_i);
   }
   reset_alloc();

   // Set alloc countdown 0->10.
   for (int i = 0; i <= 200; i++) {
      set_alloc_failure_countdown_to(i);
      index_t * index_i = index_read("test_base30");
      index_free(index_i);
   }
   reset_alloc();

   index_free(index);
   unredirect_stderr();
}
コード例 #5
0
ファイル: tests_zinm.c プロジェクト: ezorita/zerone
void
test_fail_mle_nb
(void)
{

   int obs[] = {6,2,2,3,2,0,1,2,5,2};
   zinb_par_t *par = NULL;

   redirect_stderr();
   set_alloc_failure_countdown_to(0);
   par = mle_nb(obs, 10);
   reset_alloc();
   unredirect_stderr();
   test_assert(par == NULL);
   test_assert(strncmp(caught_in_stderr(), "memory error", 12) == 0);

   redirect_stderr();
   set_alloc_failure_countdown_to(1);
   par = mle_nb(obs, 10);
   reset_alloc();
   unredirect_stderr();
   test_assert(par == NULL);
   test_assert(strncmp(caught_in_stderr(), "memory error", 12) == 0);

   redirect_stderr();
   set_alloc_failure_countdown_to(2);
   par = mle_nb(obs, 10);
   reset_alloc();
   unredirect_stderr();
   test_assert(par == NULL);
   test_assert(strncmp(caught_in_stderr(), "memory error", 12) == 0);

   redirect_stderr();
   set_alloc_failure_countdown_to(3);
   par = mle_nb(obs, 10);
   reset_alloc();
   unredirect_stderr();
   test_assert_critical(par != NULL);
   test_assert(strncmp(caught_in_stderr(), "$", 1) == 0);

   free(par);

   return;

}
コード例 #6
0
ファイル: test_mem_index_sar.c プロジェクト: ezorita/mapper
void
test_mem_sar_get_range
(void)
{
   sym_t * sym = sym_new_dna();
   test_assert_critical(sym != NULL);

   txt_t * txt = txt_new(sym);
   test_assert_critical(txt != NULL);
   test_assert(txt_append("TAGCNTCGACA", txt) == 0);
   test_assert(txt_commit_seq("seq0",txt) == 0);
   test_assert(txt_commit_rc(txt) == 0);

   sar_t * sar = sar_build(txt);
   test_assert_critical(sar != NULL);

   int64_t * sa_buf = malloc(30*sizeof(int64_t));
   test_assert_critical(sa_buf != NULL);

   redirect_stderr();
   // Set alloc failure rate to 0.1.
   set_alloc_failure_rate_to(0.1);
   for (int i = 0; i < 100; i++) {
      sar_get_range(0,10,sa_buf,sar);
      sar_get_range(10,5,sa_buf,sar);
      sar_get_range(19,30,sa_buf,sar);
   }
   reset_alloc();

   // Set alloc countdown 0->10.
   for (int i = 0; i <= 10; i++) {
      set_alloc_failure_countdown_to(i);
      sar_get_range(0,10,sa_buf,sar);
      sar_get_range(10,5,sa_buf,sar);
      sar_get_range(19,30,sa_buf,sar);
   }
   reset_alloc();

   free(sa_buf);
   sar_free(sar);
   txt_free(txt);
   sym_free(sym);
   unredirect_stderr();
}
コード例 #7
0
ファイル: test_mem_index_sar.c プロジェクト: ezorita/mapper
void
test_mem_sar_file
(void)
{
   sym_t * sym = sym_new_dna();
   test_assert_critical(sym != NULL);

   txt_t * txt = txt_new(sym);
   test_assert_critical(txt != NULL);
   test_assert(txt_append("TAGCNTCGACA", txt) == 0);
   test_assert(txt_commit_seq("seq0",txt) == 0);
   test_assert(txt_commit_rc(txt) == 0);

   sar_t * sar = sar_build(txt);
   test_assert_critical(sar != NULL);

   sar_t * sar_i;

   redirect_stderr();
   // Set alloc failure rate to 0.1.
   set_alloc_failure_rate_to(0.1);
   for (int i = 0; i < 100; i++) {
      sar_file_write("test30.sar", sar);
      sar_i = sar_file_read("test30.sar");
      sar_free(sar_i);
   }
   reset_alloc();

   // Set alloc countdown 0->10.
   for (int i = 0; i <= 10; i++) {
      set_alloc_failure_countdown_to(i);
      sar_file_write("test30.sar", sar);
      sar_i = sar_file_read("test30.sar");
      sar_free(sar_i);
   }
   reset_alloc();

   sar_free(sar);
   txt_free(txt);
   sym_free(sym);
   unredirect_stderr();
}
コード例 #8
0
ファイル: unittest.c プロジェクト: ezorita/mapper
void
fail_non_critical
(
   const char * assertion,
   const char * file,
         int    lineno,
   const char * function
)
// Handle failure of non critical assert statements.
// Set the test status to failed and update the display
// and print error message.
{

   // If first failed assertion of the test
   // case, update display for the user.
   if (!TEST_CASE_FAILED) {
      update_display_failed();
   }

   TEST_CASE_FAILED = 1;

   // If stderr is redirected, we will need to
   // take it back to display the error message.
   int toggle_stderr = STDERR_OFF;
   if (toggle_stderr) unredirect_stderr();

   // Don't show more than 'MAX_N_ERROR_MSG', unless
   // user passed the --showall or -a option.
   if (N_ERROR_MSG++ < MAX_N_ERROR_MSG || SHOWALL) {
      fprintf(stderr, "%s:%d: `%s'\n", file, lineno, assertion);
   }
   else if (N_ERROR_MSG == MAX_N_ERROR_MSG + 1) {
      fprintf(stderr, "more than %d failed assertions...\n",
            MAX_N_ERROR_MSG);
   }

   // Flush stderr and put it back as it was (ie redirect
   // it if it was redirected, or leave it as is otherwise).
   fflush(stderr);
   if (toggle_stderr) redirect_stderr();

}
コード例 #9
0
ファイル: tests_zinm.c プロジェクト: ezorita/zerone
void
test_histo_push
(void)
{

   histo_t *histo;
   histo = new_histo();
   test_assert_critical(histo != NULL);
   for (size_t i = 0 ; i < (1 << 16) ; i++) {
      test_assert(histo_push(&histo, i) == 0);
   }
   test_assert(histo->size == (1 << 16));
   for (size_t i = 0 ; i < (1 << 16) ; i++) {
      test_assert(histo->num[i] == 1);
   }
   free(histo);

   histo = new_histo();
   test_assert_critical(histo != NULL);
   for (size_t i = (1 << 16) ; i > 0 ; i--) {
      test_assert(histo_push(&histo, i-1) == 0);
   }
   test_assert(histo->size == 2*((1 << 16)-1));
   for (size_t i = 0 ; i < (1 << 16) ; i++) {
      test_assert(histo->num[i] == 1);
   }
   free(histo);

   histo = new_histo();
   test_assert_critical(histo != NULL);
   redirect_stderr();
   set_alloc_failure_rate_to(1.0);
   test_assert(histo_push(&histo, HISTO_INIT_SIZE) == 1);
   reset_alloc();
   unredirect_stderr();
   test_assert(strcmp(caught_in_stderr(), "") != 0);
   free(histo);

   return;

}
コード例 #10
0
ファイル: test_mem_index.c プロジェクト: ezorita/mapper
void
test_mem_index_build
(void)
{
   redirect_stderr();
   // Set alloc failure rate to 0.1.
   set_alloc_failure_rate_to(0.1);
   for (int i = 0; i < 1000; i++) {
      index_t * index = index_build("examples/repeats.fa", "test_base20");
      index_free(index);
   }
   reset_alloc();

   // Set alloc countdown 0->10.
   for (int i = 0; i <= 200; i++) {
      set_alloc_failure_countdown_to(i);
      index_t * index = index_build("examples/repeats.fa", "test_base20");
      index_free(index);
   }
   reset_alloc();
   unredirect_stderr();
}
コード例 #11
0
ファイル: test_mem_index.c プロジェクト: ezorita/mapper
void
test_mem_index_ann_new
(void)
{
   redirect_stderr();
   
   index_t * index = index_build("examples/repeats.fa", "test_base20");
   test_assert_critical(index != NULL);

   // Set alloc failure rate to 0.1.
   set_alloc_failure_rate_to(0.1);
   for (int i = 0; i < 1000; i++) {
      if (index_ann_new(25, 1, 1, index) == 0) {
         unlink("test_base20.ann.25.1");
         ann_free(index->ann[0]);
         free(index->ann);
         index->ann = NULL;
         index->ann_cnt = 0;
      }
   }
   reset_alloc();

   // Set alloc countdown 0->10.
   for (int i = 0; i <= 1000; i++) {
      set_alloc_failure_countdown_to(i);
      if (index_ann_new(25, 1, 1, index) == 0) {
         unlink("test_base20.ann.25.1");
         ann_free(index->ann[0]);
         free(index->ann);
         index->ann = NULL;
         index->ann_cnt = 0;
      }
   }
   reset_alloc();

   index_free(index);
   unredirect_stderr();
}
コード例 #12
0
ファイル: tests_zinm.c プロジェクト: ezorita/zerone
void
test_new_histo
(void)
{

   histo_t *histo;
   histo = new_histo();
   test_assert_critical(histo != NULL);
   for (size_t i = 0 ; i < HISTO_INIT_SIZE ; i++) {
      test_assert(histo->num[i] == 0);
   }
   free(histo);

   redirect_stderr();
   set_alloc_failure_rate_to(1.0);
   histo = new_histo();
   reset_alloc();
   unredirect_stderr();
   test_assert(histo == NULL);
   test_assert(strcmp(caught_in_stderr(), "") != 0);

   return;

}
コード例 #13
0
ファイル: unittest.c プロジェクト: emmaggie/starcode
void
assert_fail_non_critical
(
   const char         * assertion,
   const char         * file,
   const unsigned int   lineno,
   const char         * function
)
{
   TEST_CASE_FAILED = 1;
   if (++N_ERROR_MESSAGES > MAX_N_ERROR_MESSAGES + 1) return;
   int switch_stderr = STDERR_OFF;
   if (switch_stderr) unredirect_stderr();
   if (N_ERROR_MESSAGES == MAX_N_ERROR_MESSAGES + 1) {
      fprintf(stderr, "more than %d failed assertions...\n",
            MAX_N_ERROR_MESSAGES);
   }
   else {
      fprintf(stderr, "assertion failed in %s(), %s:%d: `%s'\n",
            function, file, lineno, assertion);
   }
   fflush(stderr);
   if (switch_stderr) redirect_stderr();
}
コード例 #14
0
ファイル: amflush.c プロジェクト: ahqmhjk/amanda
int
main(
    int		argc,
    char **	argv)
{
    int foreground;
    int batch;
    int redirect;
    char **datearg = NULL;
    int nb_datearg = 0;
    char *conf_diskfile;
    char *conf_tapelist;
    char *conf_logfile;
    int conf_usetimestamps;
    disklist_t diskq;
    disk_t *dp;
    pid_t pid;
    pid_t driver_pid, reporter_pid;
    amwait_t exitcode;
    int opt;
    GSList *holding_list=NULL, *holding_file;
    int driver_pipe[2];
    char date_string[100];
    char date_string_standard[100];
    time_t today;
    char *errstr;
    struct tm *tm;
    char *tapedev;
    char *tpchanger;
    char *qdisk, *qhname;
    GSList *datestamp_list = NULL;
    config_overrides_t *cfg_ovr;
    char **config_options;
    find_result_t *holding_files;
    disklist_t holding_disklist = { NULL, NULL };

    /*
     * Configure program for internationalization:
     *   1) Only set the message locale for now.
     *   2) Set textdomain for all amanda related programs to "amanda"
     *      We don't want to be forced to support dozens of message catalogs.
     */  
    setlocale(LC_MESSAGES, "C");
    textdomain("amanda"); 

    safe_fd(-1, 0);
    safe_cd();

    set_pname("amflush");

    /* Don't die when child closes pipe */
    signal(SIGPIPE, SIG_IGN);

    dbopen(DBG_SUBDIR_SERVER);

    add_amanda_log_handler(amanda_log_stderr);
    foreground = 0;
    batch = 0;
    redirect = 1;

    /* process arguments */

    cfg_ovr = new_config_overrides(argc/2);
    while((opt = getopt(argc, argv, "bfso:D:")) != EOF) {
	switch(opt) {
	case 'b': batch = 1;
		  break;
	case 'f': foreground = 1;
		  break;
	case 's': redirect = 0;
		  break;
	case 'o': add_config_override_opt(cfg_ovr, optarg);
		  break;
	case 'D': if (datearg == NULL)
		      datearg = g_malloc(21*sizeof(char *));
		  if(nb_datearg == 20) {
		      g_fprintf(stderr,_("maximum of 20 -D arguments.\n"));
		      exit(1);
		  }
		  datearg[nb_datearg++] = g_strdup(optarg);
		  datearg[nb_datearg] = NULL;
		  break;
	}
    }
    argc -= optind, argv += optind;

    if(!foreground && !redirect) {
	g_fprintf(stderr,_("Can't redirect to stdout/stderr if not in forground.\n"));
	exit(1);
    }

    if(argc < 1) {
	error(_("Usage: amflush [-b] [-f] [-s] [-D date]* [-o configoption]* <confdir> [host [disk]* ]*"));
	/*NOTREACHED*/
    }

    set_config_overrides(cfg_ovr);
    config_init(CONFIG_INIT_EXPLICIT_NAME,
		argv[0]);

    conf_diskfile = config_dir_relative(getconf_str(CNF_DISKFILE));
    read_diskfile(conf_diskfile, &diskq);
    amfree(conf_diskfile);

    if (config_errors(NULL) >= CFGERR_WARNINGS) {
	config_print_errors();
	if (config_errors(NULL) >= CFGERR_ERRORS) {
	    g_critical(_("errors processing config file"));
	}
    }

    check_running_as(RUNNING_AS_DUMPUSER);

    dbrename(get_config_name(), DBG_SUBDIR_SERVER);

    /* load DLEs from the holding disk, in case there's anything to flush there */
    search_holding_disk(&holding_files, &holding_disklist);
    /* note that the dumps are added to the global disklist, so we need not
     * consult holding_files or holding_disklist after this.  The holding-only
     * dumps will be filtered properly by match_disklist, setting the dp->todo
     * flag appropriately. */

    errstr = match_disklist(&diskq, argc-1, argv+1);
    if (errstr) {
	g_printf(_("%s"),errstr);
	amfree(errstr);
    }

    conf_tapelist = config_dir_relative(getconf_str(CNF_TAPELIST));
    if(read_tapelist(conf_tapelist)) {
	error(_("could not load tapelist \"%s\""), conf_tapelist);
	/*NOTREACHED*/
    }
    amfree(conf_tapelist);

    conf_usetimestamps = getconf_boolean(CNF_USETIMESTAMPS);

    amflush_datestamp = get_datestamp_from_time(0);
    if(conf_usetimestamps == 0) {
	amflush_timestamp = g_strdup(amflush_datestamp);
    }
    else {
	amflush_timestamp = get_timestamp_from_time(0);
    }

    conf_logdir = config_dir_relative(getconf_str(CNF_LOGDIR));
    conf_logfile = g_strjoin(NULL, conf_logdir, "/log", NULL);
    if (access(conf_logfile, F_OK) == 0) {
	run_amcleanup(get_config_name());
    }
    if (access(conf_logfile, F_OK) == 0) {
	char *process_name = get_master_process(conf_logfile);
	error(_("%s exists: %s is already running, or you must run amcleanup"), conf_logfile, process_name);
	/*NOTREACHED*/
    }

    driver_program = g_strjoin(NULL, amlibexecdir, "/", "driver", NULL);
    reporter_program = g_strjoin(NULL, sbindir, "/", "amreport", NULL);
    logroll_program = g_strjoin(NULL, amlibexecdir, "/", "amlogroll", NULL);

    tapedev = getconf_str(CNF_TAPEDEV);
    tpchanger = getconf_str(CNF_TPCHANGER);
    if (tapedev == NULL && tpchanger == NULL) {
	error(_("No tapedev or tpchanger specified"));
    }

    /* if dates were specified (-D), then use match_datestamp
     * against the list of all datestamps to turn that list
     * into a set of existing datestamps (basically, evaluate the
     * expressions into actual datestamps) */
    if(datearg) {
	GSList *all_datestamps;
	GSList *datestamp;
	int i, ok;

	all_datestamps = holding_get_all_datestamps();
	for(datestamp = all_datestamps; datestamp != NULL; datestamp = datestamp->next) {
	    ok = 0;
	    for(i=0; i<nb_datearg && ok==0; i++) {
		ok = match_datestamp(datearg[i], (char *)datestamp->data);
	    }
	    if (ok)
		datestamp_list = g_slist_insert_sorted(datestamp_list,
		    g_strdup((char *)datestamp->data),
		    g_compare_strings);
	}
	slist_free_full(all_datestamps, g_free);
    }
    else {
	/* otherwise, in batch mode, use all datestamps */
	if(batch) {
	    datestamp_list = holding_get_all_datestamps();
	}
	/* or allow the user to pick datestamps */
	else {
	    datestamp_list = pick_datestamp();
	}
    }

    if(!datestamp_list) {
	g_printf(_("Could not find any Amanda directories to flush.\n"));
	exit(1);
    }

    holding_list = holding_get_files_for_flush(datestamp_list);
    if (holding_list == NULL) {
	g_printf(_("Could not find any valid dump image, check directory.\n"));
	exit(1);
    }

    if (access(conf_logfile, F_OK) == 0) {
	char *process_name = get_master_process(conf_logfile);
	error(_("%s exists: someone started %s"), conf_logfile, process_name);
	/*NOTREACHED*/
    }
    log_add(L_INFO, "%s pid %ld", get_pname(), (long)getpid());

    if(!batch) confirm(datestamp_list);

    for(dp = diskq.head; dp != NULL; dp = dp->next) {
	if(dp->todo) {
	    char *qname;
	    qname = quote_string(dp->name);
	    log_add(L_DISK, "%s %s", dp->host->hostname, qname);
	    amfree(qname);
	}
    }

    if(!foreground) { /* write it before redirecting stdout */
	puts(_("Running in background, you can log off now."));
	puts(_("You'll get mail when amflush is finished."));
    }

    if(redirect) redirect_stderr();

    if(!foreground) detach();

    add_amanda_log_handler(amanda_log_stderr);
    add_amanda_log_handler(amanda_log_trace_log);
    today = time(NULL);
    tm = localtime(&today);
    if (tm) {
	strftime(date_string, 100, "%a %b %e %H:%M:%S %Z %Y", tm);
	strftime(date_string_standard, 100, "%Y-%m-%d %H:%M:%S %Z", tm);
    } else {
	error(_("BAD DATE")); /* should never happen */
    }
    g_fprintf(stderr, _("amflush: start at %s\n"), date_string);
    g_fprintf(stderr, _("amflush: datestamp %s\n"), amflush_timestamp);
    g_fprintf(stderr, _("amflush: starttime %s\n"), amflush_timestamp);
    g_fprintf(stderr, _("amflush: starttime-locale-independent %s\n"),
	      date_string_standard);
    log_add(L_START, _("date %s"), amflush_timestamp);

    /* START DRIVER */
    if(pipe(driver_pipe) == -1) {
	error(_("error [opening pipe to driver: %s]"), strerror(errno));
	/*NOTREACHED*/
    }
    if((driver_pid = fork()) == 0) {
	/*
	 * This is the child process.
	 */
	dup2(driver_pipe[0], 0);
	close(driver_pipe[1]);
	config_options = get_config_options(3);
	config_options[0] = "driver";
	config_options[1] = get_config_name();
	config_options[2] = "nodump";
	safe_fd(-1, 0);
	execve(driver_program, config_options, safe_env());
	error(_("cannot exec %s: %s"), driver_program, strerror(errno));
	/*NOTREACHED*/
    } else if(driver_pid == -1) {
	error(_("cannot fork for %s: %s"), driver_program, strerror(errno));
	/*NOTREACHED*/
    }
    driver_stream = fdopen(driver_pipe[1], "w");
    if (!driver_stream) {
	error(_("Can't fdopen: %s"), strerror(errno));
	/*NOTREACHED*/
    }

    g_fprintf(driver_stream, "DATE %s\n", amflush_timestamp);
    for(holding_file=holding_list; holding_file != NULL;
				   holding_file = holding_file->next) {
	dumpfile_t file;
	holding_file_get_dumpfile((char *)holding_file->data, &file);

	if (holding_file_size((char *)holding_file->data, 1) <= 0) {
	    g_debug("%s is empty - ignoring", (char *)holding_file->data);
	    log_add(L_INFO, "%s: removing file with no data.",
		    (char *)holding_file->data);
	    holding_file_unlink((char *)holding_file->data);
	    dumpfile_free_data(&file);
	    continue;
	}

	/* search_holding_disk should have already ensured that every
	 * holding dumpfile has an entry in the dynamic disklist */
	dp = lookup_disk(file.name, file.disk);
	assert(dp != NULL);

	/* but match_disklist may have indicated we should not flush it */
	if (dp->todo == 0) continue;

	qdisk = quote_string(file.disk);
	qhname = quote_string((char *)holding_file->data);
	g_fprintf(stderr,
		"FLUSH %s %s %s %d %s\n",
		file.name,
		qdisk,
		file.datestamp,
		file.dumplevel,
		qhname);

	g_debug("flushing '%s'", (char *)holding_file->data);
	g_fprintf(driver_stream,
		"FLUSH %s %s %s %d %s\n",
		file.name,
		qdisk,
		file.datestamp,
		file.dumplevel,
		qhname);
	amfree(qdisk);
	amfree(qhname);
	dumpfile_free_data(&file);
    }
    g_fprintf(stderr, "ENDFLUSH\n"); fflush(stderr);
    g_fprintf(driver_stream, "ENDFLUSH\n"); fflush(driver_stream);
    fclose(driver_stream);

    /* WAIT DRIVER */
    while(1) {
	if((pid = wait(&exitcode)) == -1) {
	    if(errno == EINTR) {
		continue;
	    } else {
		error(_("wait for %s: %s"), driver_program, strerror(errno));
		/*NOTREACHED*/
	    }
	} else if (pid == driver_pid) {
	    break;
	}
    }

    slist_free_full(datestamp_list, g_free);
    datestamp_list = NULL;
    slist_free_full(holding_list, g_free);
    holding_list = NULL;

    if(redirect) { /* rename errfile */
	char *errfile, *errfilex, *nerrfilex, number[100];
	int tapecycle;
	int maxdays, days;
		
	struct stat stat_buf;

	errfile = g_strjoin(NULL, conf_logdir, "/amflush", NULL);
	errfilex = NULL;
	nerrfilex = NULL;
	tapecycle = getconf_int(CNF_TAPECYCLE);
	maxdays = tapecycle + 2;
	days = 1;
	/* First, find out the last existing errfile,           */
	/* to avoid ``infinite'' loops if tapecycle is infinite */

	g_snprintf(number,100,"%d",days);
	errfilex = newvstralloc(errfilex, errfile, ".", number, NULL);
	while ( days < maxdays && stat(errfilex,&stat_buf)==0) {
	    days++;
	    g_snprintf(number,100,"%d",days);
	    errfilex = newvstralloc(errfilex, errfile, ".", number, NULL);
	}
	g_snprintf(number,100,"%d",days);
	errfilex = newvstralloc(errfilex, errfile, ".", number, NULL);
	nerrfilex = NULL;
	while (days > 1) {
	    amfree(nerrfilex);
	    nerrfilex = errfilex;
	    days--;
	    g_snprintf(number,100,"%d",days);
	    errfilex = g_strjoin(NULL, errfile, ".", number, NULL);
	    if (rename(errfilex, nerrfilex) != 0) {
		error(_("cannot rename \"%s\" to \"%s\": %s"),
		      errfilex, nerrfilex, strerror(errno));
	        /*NOTREACHED*/
	    }
	}
	errfilex = newvstralloc(errfilex, errfile, ".1", NULL);
	if (rename(errfile,errfilex) != 0) {
	    error(_("cannot rename \"%s\" to \"%s\": %s"),
		  errfilex, nerrfilex, strerror(errno));
	    /*NOTREACHED*/
	}
	amfree(errfile);
	amfree(errfilex);
	amfree(nerrfilex);
    }

    /*
     * Have amreport generate report and send mail.  Note that we do
     * not bother checking the exit status.  If it does not work, it
     * can be rerun.
     */

    if((reporter_pid = fork()) == 0) {
	/*
	 * This is the child process.
	 */
	config_options = get_config_options(3);
	config_options[0] = "amreport";
	config_options[1] = get_config_name();
        config_options[2] = "--from-amdump";
	safe_fd(-1, 0);
	execve(reporter_program, config_options, safe_env());
	error(_("cannot exec %s: %s"), reporter_program, strerror(errno));
	/*NOTREACHED*/
    } else if(reporter_pid == -1) {
	error(_("cannot fork for %s: %s"), reporter_program, strerror(errno));
	/*NOTREACHED*/
    }
    while(1) {
	if((pid = wait(&exitcode)) == -1) {
	    if(errno == EINTR) {
		continue;
	    } else {
		error(_("wait for %s: %s"), reporter_program, strerror(errno));
		/*NOTREACHED*/
	    }
	} else if (pid == reporter_pid) {
	    break;
	}
    }

    log_add(L_INFO, "pid-done %ld", (long)getpid());

    /*
     * Call amlogroll to rename the log file to its datestamped version.
     * Since we exec at this point, our exit code will be that of amlogroll.
     */
    config_options = get_config_options(2);
    config_options[0] = "amlogroll";
    config_options[1] = get_config_name();
    safe_fd(-1, 0);
    execve(logroll_program, config_options, safe_env());
    error(_("cannot exec %s: %s"), logroll_program, strerror(errno));
    /*NOTREACHED*/
    return 0;				/* keep the compiler happy */
}
コード例 #15
0
ファイル: test_io.c プロジェクト: ezorita/mapper
void
test_io_stream_read_seq
(void)
{
   iostream_t * stream;
   gstack_t   * stack;
   seqread_t  * read;

   // Invalid arguments.
   redirect_stderr();
   test_assert(io_stream_read_seq(NULL) == NULL);
   unredirect_stderr();

   // Load files.
   // Read RAW file.
   stream = io_stream_open("examples/io_input.raw");
   test_assert_critical(stream != NULL);
   
   stack = io_stream_read_seq(stream);
   test_assert_critical(stack != NULL);
   test_assert(gstack_num_elm(stack) == 6);
   
   read = seqread_pop(stack);
   test_assert(read != NULL);
   test_assert(strcmp(seqread_seq(read), "NNNNNNLLYYYYJDFLS") == 0);
   test_assert(strcmp(seqread_tag(read), "6") == 0);
   seqread_free(read);
   read = seqread_pop(stack);
   test_assert(read != NULL);
   test_assert(strcmp(seqread_seq(read), "NNNNNNNNACGTACGCC") == 0);
   test_assert(strcmp(seqread_tag(read), "5") == 0);
   seqread_free(read);
   read = seqread_pop(stack);
   test_assert(read != NULL);
   test_assert(strcmp(seqread_seq(read), "ACGTACATGTATGACAC") == 0);
   test_assert(strcmp(seqread_tag(read), "4") == 0);
   seqread_free(read);

   gstack_free(stack);
   io_stream_free(stream);

   // Read FASTA file.
   stream = io_stream_open_buf("examples/io_input.fasta", 80);
   test_assert_critical(stream != NULL);

   stack = io_stream_read_seq(stream);
   test_assert_critical(stack != NULL);
   test_assert(gstack_num_elm(stack) == 4);

   read = seqread_pop(stack);
   test_assert(read != NULL);
   test_assert(strcmp(seqread_seq(read), "ACGTACATGTATGACAC") == 0);
   test_assert(strcmp(seqread_tag(read), "seq4") == 0);
   seqread_free(read);

   read = seqread_pop(stack);
   test_assert(read != NULL);
   test_assert(strcmp(seqread_seq(read), "AGTCGANTATACNTACG") == 0);
   test_assert(strcmp(seqread_tag(read), "seq3") == 0);
   seqread_free(read);

   read = seqread_pop(stack);
   test_assert(read != NULL);
   test_assert(strcmp(seqread_seq(read), "GTATCGACTACGAGCTA") == 0);
   test_assert(strcmp(seqread_tag(read), "seq2") == 0);
   seqread_free(read);

   read = seqread_pop(stack);
   test_assert(read != NULL);
   test_assert(strcmp(seqread_seq(read), "ATGCGTACGTCGTATCA") == 0);
   test_assert(strcmp(seqread_tag(read), "seq1") == 0);
   seqread_free(read);
   gstack_free(stack);
   
   stack = io_stream_read_seq(stream);
   test_assert_critical(stack != NULL);
   test_assert(gstack_num_elm(stack) == 2);

   read = seqread_pop(stack);
   test_assert(read != NULL);
   test_assert(strcmp(seqread_seq(read), "NNNNNNLLYYYYJDFLS") == 0);
   test_assert(strcmp(seqread_tag(read), "seq6") == 0);
   seqread_free(read);
   read = seqread_pop(stack);
   test_assert(read != NULL);
   test_assert(strcmp(seqread_seq(read), "NNNNNNNNACGTACGCC") == 0);
   test_assert(strcmp(seqread_tag(read), "seq5") == 0);
   seqread_free(read);


   gstack_free(stack);
   io_stream_free(stream);

   // Read FASTQ file.
   stream = io_stream_open_buf("examples/io_input.fastq", 50);
   test_assert_critical(stream != NULL);
   
   stack = io_stream_read_seq(stream);
   test_assert_critical(stack != NULL);
   test_assert(gstack_num_elm(stack) == 2);

   read = seqread_pop(stack);
   test_assert(read != NULL);
   test_assert(strcmp(seqread_seq(read), "GTATCGACTACGAGCTA") == 0);
   test_assert(strcmp(seqread_tag(read), "seq2") == 0);
   test_assert(strcmp(seqread_qscore(read), "BACBABCA0ACBB00AC") == 0);   
   seqread_free(read);

   read = seqread_pop(stack);
   test_assert(read != NULL);
   test_assert(strcmp(seqread_seq(read), "ATGCGTACGTCGTATCA") == 0);
   test_assert(strcmp(seqread_tag(read), "seq1") == 0);
   test_assert(strcmp(seqread_qscore(read), "12391284194819241") == 0);   
   seqread_free(read);
   gstack_free(stack);

   stack = io_stream_read_seq(stream);
   test_assert_critical(stack != NULL);
   test_assert(gstack_num_elm(stack) == 2);
   gstack_free(stack);

   stack = io_stream_read_seq(stream);
   test_assert_critical(stack != NULL);
   test_assert(gstack_num_elm(stack) == 2);
   gstack_free(stack);

   stack = io_stream_read_seq(stream);
   test_assert_critical(stack != NULL);
   test_assert(gstack_num_elm(stack) == 0);
   gstack_free(stack);

   stack = io_stream_read_seq(stream);
   test_assert(stack == NULL);
   
   io_stream_free(stream);   
}