int main()
{
    ///////////////////////////////////////////////////////////////////////////

    { // Client to A, instance of B
        clientA obj(hpx::components::new_<B>(hpx::find_here()));

        HPX_TEST_EQ(obj.test0(), "B");
    }

    HPX_TEST(a_ctor); HPX_TEST(a_dtor);
    HPX_TEST(b_ctor); HPX_TEST(b_dtor);

    reset_globals();

    ///////////////////////////////////////////////////////////////////////////

    { // Client to B, instance of B
        clientB obj(hpx::components::new_<B>(hpx::find_here()));

        HPX_TEST_EQ(obj.test0(), "B");
        HPX_TEST_EQ(obj.test1(), "B");

    }

    HPX_TEST(a_ctor); HPX_TEST(a_dtor);
    HPX_TEST(b_ctor); HPX_TEST(b_dtor);

    reset_globals();

    return 0;
}
示例#2
0
/* leave pluto, with status.
 * Once child is launched, parent must not exit this way because
 * the lock would be released.
 *
 *  0 OK
 *  1 general discomfort
 * 10 lock file exists
 */
void exit_pluto(int status)
{
	reset_globals();    /* needed because we may be called in odd state */
	free_preshared_secrets();
	free_remembered_public_keys();
	close_ha_iface();
	delete_every_connection();
	whack_attribute_finalize(); /* free in-memory pools */
	fetch_finalize();           /* stop fetching thread */
	free_crl_fetch();           /* free chain of crl fetch requests */
	free_ocsp_fetch();          /* free chain of ocsp fetch requests */
	free_authcerts();           /* free chain of X.509 authority certificates */
	free_crls();                /* free chain of X.509 CRLs */
	free_ca_infos();            /* free chain of X.509 CA information records */
	free_ocsp();                /* free ocsp cache */
	free_ifaces();
	ac_finalize();              /* free X.509 attribute certificates */
	scx_finalize();             /* finalize and unload PKCS #11 module */
	stop_adns();
	free_md_pool();
	free_crypto();
	free_myid();                /* free myids */
	free_events();              /* free remaining events */
	free_vendorid();            /* free all vendor id records */
	free_builder();
	delete_lock();
	options->destroy(options);
	pluto_deinit();
	lib->plugins->unload(lib->plugins);
	libhydra_deinit();
	library_deinit();
	close_log();
	exit(status);
}
示例#3
0
bool onconfirm_main_menu(MenuItem<int> choice)
{
	switch (activeLineIndexMain)
	{
	case 0:
		process_player_menu();
		break;
	case 1:
		process_teleport_menu(-1);
		break;
	case 2:
		process_weapon_menu();
		break;
	case 3:
		process_veh_menu();
		break;
	case 4:
		process_world_menu();
		break;
	case 5:
		process_time_menu();
		break;
	case 6:
		process_misc_menu();
		break;
	case 7:
		reset_globals();
		break;
	case 8:
		process_test_menu();
		break;
	}
	return false;
}
示例#4
0
/* leave pluto, with status.
 * Once child is launched, parent must not exit this way because
 * the lock would be released.
 *
 *  0 OK
 *  1 general discomfort
 * 10 lock file exists
 */
void
exit_pluto(int status)
{
    reset_globals();	/* needed because we may be called in odd state */
    free_preshared_secrets();
    free_remembered_public_keys();
    delete_every_connection();

    /* free memory allocated by initialization routines.  Please don't
       forget to do this. */

#ifdef HAVE_THREADS
    free_crl_fetch();          /* free chain of crl fetch requests */
#endif
#ifdef HAVE_OCSP
    free_ocsp_fetch();         /* free chain of ocsp fetch requests */
#endif
    free_authcerts();          /* free chain of X.509 authority certificates */
    free_crls();               /* free chain of X.509 CRLs */
    free_acerts();             /* free chain of X.509 attribute certificates */
    free_ocsp();               /* free ocsp cache */

    free_ifaces();          /* free interface list from memory */
    stop_adns();            /* Stop async DNS process (if running) */
    free_md_pool();         /* free the md pool */
    delete_lock();          /* delete any lock files */
#ifdef LEAK_DETECTIVE
    report_leaks();         /* report memory leaks now, after all free()s */
#endif /* LEAK_DETECTIVE */
    close_log();            /* close the logfiles */
    exit(status);           /* exit, with our error code */
}
示例#5
0
static void
aggr_outI1_continue(struct pluto_crypto_req_cont *pcrc
		    , struct pluto_crypto_req *r
		    , err_t ugh)
{
  struct ke_continuation *ke = (struct ke_continuation *)pcrc;
  struct msg_digest *md = ke->md;
  struct state *const st = md->st;
  stf_status e;
  
  DBG(DBG_CONTROLMORE
      , DBG_log("aggr outI1: calculated ke+nonce, sending I1"));
  
  /* XXX should check out ugh */
  passert(ugh == NULL);
  passert(cur_state == NULL);
  passert(st != NULL);

  passert(st->st_suspended_md == ke->md);
  st->st_suspended_md = NULL;	/* no longer connected or suspended */

  set_cur_state(st);

  st->st_calculating = FALSE;

  e = aggr_outI1_tail(pcrc, r);
  
  if(ke->md != NULL) {
      complete_state_transition(&ke->md, e);
      release_md(ke->md);
  }
  reset_globals();

  passert(GLOBALS_ARE_RESET());
}
示例#6
0
void mode_14_correct_answer() {
    play_feedback(MP3_CORRECT);
    speak_letters_in_word(mode_14_chosen_word);
    speak_word(mode_14_chosen_word);
    play_tada();
    score++;
    mode_14_play_stats();
    reset_globals();
    reset_stats();
}
int main()
{
    ///////////////////////////////////////////////////////////////////////////

    { // Client to A, instance of B
        clientA obj(hpx::components::new_<B>(hpx::find_here()));

        HPX_TEST_EQ(obj.test0(), "B");
    }

    // Make sure AGAS kicked in...
    hpx::agas::garbage_collect();
    hpx::this_thread::yield();

    HPX_TEST(a_ctor); HPX_TEST(a_dtor);
    HPX_TEST(b_ctor); HPX_TEST(b_dtor);

    reset_globals();

    ///////////////////////////////////////////////////////////////////////////

    { // Client to B, instance of B
        clientB obj(hpx::components::new_<B>(hpx::find_here()));

        HPX_TEST_EQ(obj.test0(), "B");
        HPX_TEST_EQ(obj.test1(), "B");

    }

    // Make sure AGAS kicked in...
    hpx::agas::garbage_collect();
    hpx::this_thread::yield();

    HPX_TEST(a_ctor); HPX_TEST(a_dtor);
    HPX_TEST(b_ctor); HPX_TEST(b_dtor);

    reset_globals();

    return 0;
}
示例#8
0
/*
 * @brief Internal MAC soft reset function
 *
 * This function resets the MAC variables, stops all running timers and
 * initializes the PIBs.
 *
 * @param init_pib Boolean indicates whether PIB attributes shall be
 * initialized or not.
 */
static void mac_soft_reset(uint8_t init_pib)
{
	reset_globals();

	/* Set trx to PHY_TRX_OFF */
	tal_rx_enable(PHY_TRX_OFF);

	ENTER_CRITICAL_REGION();
	mac_timers_stop();
	LEAVE_CRITICAL_REGION();

	if (init_pib) {
		do_init_pib();
	}
}
示例#9
0
/* leave pluto, with status.
 * Once child is launched, parent must not exit this way because
 * the lock would be released.
 *
 *  0 OK
 *  1 general discomfort
 * 10 lock file exists
 */
void
exit_pluto(int status)
{
    reset_globals();	/* needed because we may be called in odd state */
    free_preshared_secrets();
    free_remembered_public_keys();
    delete_every_connection();
    free_cacerts();	/* free chain of CA certificates */
    free_crls();	/* free chain of CRLS */
    free_mycert();	/* free default certificate (deprecated for X.509) */
    free_ifaces();
    stop_adns();
    free_md_pool();
    delete_lock();
#ifdef LEAK_DETECTIVE
    report_leaks();
#endif /* LEAK_DETECTIVE */
    close_log();
    exit(status);
}
示例#10
0
/*
 * leave pluto, with status.
 * Once child is launched, parent must not exit this way because
 * the lock would be released.
 *
 *  0 OK
 *  1 general discomfort
 * 10 lock file exists
 */
void exit_pluto(int status)
{
	/* needed because we may be called in odd state */
	reset_globals();
 #ifdef USE_SYSTEMD_WATCHDOG
	pluto_sd(PLUTO_SD_STOPPING, status);
 #endif
	free_preshared_secrets();
	free_remembered_public_keys();
	delete_every_connection();

	/*
	 * free memory allocated by initialization routines.  Please don't
	 * forget to do this.
	 */

#if defined(LIBCURL) || defined(LDAP_VER)
	free_crl_fetch();	/* free chain of crl fetch requests */
#endif

	lsw_conf_free_oco();	/* free global_oco containing path names */

	free_myFQDN();	/* free myid FQDN */

	free_ifaces();	/* free interface list from memory */
	free_md_pool();	/* free the md pool */
	lsw_nss_shutdown();
	delete_lock();	/* delete any lock files */
	free_virtual_ip();	/* virtual_private= */
	free_kernelfd();	/* stop listening to kernel FD, remove event */
	free_pluto_main();	/* our static chars */

	/* report memory leaks now, after all free_* calls */
	if (leak_detective)
		report_leaks();
	close_log();	/* close the logfiles */
#ifdef USE_SYSTEMD_WATCHDOG
	pluto_sd(PLUTO_SD_EXIT,status);
#endif
	exit(status);	/* exit, with our error code */
}
示例#11
0
void GameManager::set_frame(int index)
{
    ignore_controls = false;

#ifdef CHOWDREN_IS_DEMO
    idle_timer = 0.0;
    idle_timer_started = false;
#endif

#ifndef CHOWDREN_SAMPLES_OVER_FRAMES
    media.stop_samples();
#endif

    if (frame->index != -1)
        frame->on_end();

    if (index == -2) {
        platform_begin_draw();
        media.stop_samples();
        Render::clear(Color(0, 0, 0, 255));
        platform_swap_buffers();
#ifdef CHOWDREN_IS_DEMO
        reset_timer = 0.0;
#endif
        index = 0;
        // reset_global_data();
        reset_globals();
    }

    std::cout << "Setting frame: " << index << std::endl;

#ifdef CHOWDREN_USER_PROFILER
    std::string logline = "Setting frame: " + number_to_string(index) + "\n";
    user_log.write(&logline[0], logline.size());
#endif

    frame->set_index(index);

    std::cout << "Frame set" << std::endl;
}
示例#12
0
/* leave pluto, with status.
 * Once child is launched, parent must not exit this way because
 * the lock would be released.
 *
 *  0 OK
 *  1 general discomfort
 * 10 lock file exists
 */
void
exit_pluto(int status)
{
    reset_globals();	/* needed because we may be called in odd state */
    free_preshared_secrets();
    free_remembered_public_keys();
    delete_every_connection();

    /* free memory allocated by initialization routines.  Please don't
       forget to do this. */

#ifdef TPM
    free_tpm();
#endif

#if defined(LIBCURL) || defined(LDAP_VER)
    free_crl_fetch();          /* free chain of crl fetch requests */
#endif
    free_authcerts();          /* free chain of X.509 authority certificates */
    free_crls();               /* free chain of X.509 CRLs */
    free_acerts();             /* free chain of X.509 attribute certificates */

    lsw_conf_free_oco();	/* free global_oco containing path names */

    free_myFQDN();	    /* free myid FQDN */

    free_ifaces();          /* free interface list from memory */
    stop_adns();            /* Stop async DNS process (if running) */
    free_md_pool();         /* free the md pool */
    NSS_Shutdown();
    delete_lock();          /* delete any lock files */
#ifdef LEAK_DETECTIVE
    report_leaks();         /* report memory leaks now, after all free()s */
#endif /* LEAK_DETECTIVE */
    close_log();            /* close the logfiles */
    exit(status);           /* exit, with our error code */
}
示例#13
0
int
main(int argc, char **argv)
{
    if (detect_flag_options(argc, argv, "-help", "--help", NULL))
      help();

    char band[512], lut[512], mask_file_name[512];

    strcpy(band, "");
    strcpy(mask_file_name, "");

    int band_specified = extract_string_options(&argc, &argv, band,
        "-band", "--band", "-b", NULL);
    int lut_specified = extract_string_options(&argc, &argv, lut,
        "-colormap", "--colormap", "-lut", "--lut", NULL);
    int planner_mode = extract_flag_options(&argc, &argv,
        "-plan", "--plan", NULL);
    int mask_specified = extract_string_options(&argc, &argv, mask_file_name,
        "-mask", "--mask", "--layover-mask", "--layover-mask", NULL);
    generic_specified = extract_flag_options(&argc, &argv,
        "-generic", "--generic", NULL);
    if (generic_specified) {
       char type[512];
       if (!extract_int_options(&argc, &argv, &generic_bin_width,
                "-width", "--width", "-cols", "--cols", NULL) ||
           !extract_int_options(&argc, &argv, &generic_bin_height,
                "-height", "--height", "-rows", "--rows", NULL)) {
         asfPrintError("When reading generic data, specify the size "
            "(--width, --height).\n");
       }
       generic_bin_byteswap =
         extract_flag_options(&argc, &argv,
                              "--byteswap", "-byteswap", NULL);
       if (extract_string_options(&argc, &argv, type,
                "-type", "--type", NULL))
       {
         if (strcmp_case(type, "BYTE") == 0 ||
             strcmp_case(type, "INT8") == 0) {
           generic_bin_datatype = BYTE;
         }
         else if (strcmp_case(type, "FLOAT") == 0 ||
                  strcmp_case(type, "REAL32") == 0) {
           generic_bin_datatype = REAL32;
         }
         else {
           asfPrintError("Unknown generic data type: %s\n", type);
         }
       } else {
         asfPrintStatus("Generic binary: assuming REAL32 data.\n");
         generic_bin_datatype = REAL32;
       }
    }

    if (planner_mode) {
      if (detect_flag_options(argc, argv, "-calibrate-reference", NULL)) {
        calibrate_planner_reference();
        exit(EXIT_SUCCESS);
      }
    }

    handle_common_asf_args(&argc, &argv, "ASF View");

    // point to "polygon 0" as the one we initially work on
    g_poly = &g_polys[0];

    // set up image array
    curr = &image_info[0];
    curr->data_name = curr->meta_name = NULL;
    int ii;

    if (argc < 2) {
        curr->filename = STRDUP(find_in_share("startup.jpg"));
    }
    else {
        n_images_loaded = 0;
	for (ii=1; ii<argc; ++ii) {
           if (strlen(argv[ii]) > 0) {
               image_info[n_images_loaded].filename = STRDUP(argv[ii]);
               ++n_images_loaded;
           }
        }    
    }


    if (n_images_loaded == 1) {
        asfPrintStatus("Loading 1 image: %s\n", image_info[0].filename);
    }
    else {
        asfPrintStatus("Loading %d images:\n", n_images_loaded);
        for (ii=0; ii<n_images_loaded; ++ii)
            asfPrintStatus("%d: %s\n", ii+1, image_info[ii].filename);
    }

    if (mask_specified)
        asfPrintStatus("Mask: %s\n", mask_file_name);

    // we could call load_file() here, but don't because this way we can
    // interleave the call to gtk_init() with some of the loading code --
    // which keeps the window from showing up until after it has been loaded,
    // which looks much nicer

    // initialize globals
    reset_globals(TRUE);

    // Get rid of leftover (temporary) colormap luts if they exist, say if asf_view errored out
    // rather than being exited normally
    char embedded_tiff_lut_file[1024];
    char embedded_asf_colormap_file[1024];
    char *lut_loc = (char *)MALLOC(sizeof(char)*(strlen(get_asf_share_dir())+64));
    sprintf(lut_loc, "%s%clook_up_tables", get_asf_share_dir(), DIR_SEPARATOR);
    sprintf(embedded_tiff_lut_file,"%s%c%s", lut_loc, DIR_SEPARATOR, EMBEDDED_TIFF_COLORMAP_LUT_FILE);
    sprintf(embedded_asf_colormap_file,"%s%c%s", lut_loc, DIR_SEPARATOR,
            EMBEDDED_ASF_COLORMAP_LUT_FILE);
    FREE(lut_loc);
    if (fileExists(embedded_tiff_lut_file)) remove(embedded_tiff_lut_file);
    if (fileExists(embedded_asf_colormap_file)) remove(embedded_asf_colormap_file);

    if (mask_specified) {
        curr = mask = &mask_info;
        mask->filename = STRDUP(mask_file_name);

        if (mask->filename[strlen(mask->filename)-1] == '.')
            mask->filename[strlen(mask->filename)-1] = '\0';
        
        read_file(mask->filename, NULL, FALSE, TRUE);
        //set_lut("layover_mask");
    }
    
    // load the image we're going to actually show last
    for (ii=n_images_loaded-1; ii>=0; --ii)
    {
        curr = &image_info[ii];
        
        // strip off any trailing "."
        if (curr->filename[strlen(curr->filename)-1] == '.')
            curr->filename[strlen(curr->filename)-1] = '\0';
        
        read_file(curr->filename, band_specified ? band : NULL, FALSE, TRUE);
        check_for_embedded_tiff_lut(curr->filename, &lut_specified, lut);
        if (lut_specified)
            set_lut(lut);
        
        assert(curr->data_name);
        assert(curr->meta_name);
        
        // we load the thumbnail data before bringing up the window, looks
        // much nicer.  When loading an image within the GUI, we don't need
        // to do get_thumbnail_data() as a separate step.
        ThumbnailData *thumbnail_data = get_thumbnail_data(curr);
        
        // first time through the loop only, set up GTK
        if (ii == n_images_loaded-1) {
            gtk_init(&argc, &argv);
            
            gchar *glade_xml_file = (gchar *)find_in_share("asf_view.glade");
            printf("Found asf_view.glade: %s\n", glade_xml_file);
            glade_xml = glade_xml_new(glade_xml_file, NULL, NULL);
            free(glade_xml_file);
            
            // set up window title, etc
            set_button_images();
            
            // set up the acquisition planner, if we are in that mode
            if (planner_mode) {
                setup_planner();
                
                // getting rid of the info section makes more room for the found
                // acquisitions, and isn't really necessary in the planner
                show_widget("info_hbox", FALSE);
            }
            
            // populate the look up table list, and apply the default
            // look-up-table, if there is one.  In this case, we will need to
            // apply it retroactively to the thumbnail data we already loaded
            // (In new.c, this kludge isn't required - we load/apply in the
            // same pass -- here it is required because we pre-load the thumbnail)
            populate_lut_combo();
            if (check_for_embedded_tiff_lut(curr->filename, &lut_specified, lut)) {
                GtkWidget *option_menu = get_widget_checked("lut_optionmenu");
                gtk_option_menu_set_history(GTK_OPTION_MENU(option_menu), get_tiff_lut_index());
                set_current_index(get_tiff_lut_index());
            }
            else if (is_colormap_ASF_file(curr->filename)) {
                /*
                * lut_specified = 1;
                * strcpy(lut, EMBEDDED_ASF_COLORMAP_LUT);
                * GtkWidget *option_menu = get_widget_checked("lut_optionmenu");
                * gtk_option_menu_set_history(GTK_OPTION_MENU(option_menu), get_asf_lut_index());
                * set_current_index(get_asf_lut_index());
                * check_lut();
                * apply_lut_to_data(thumbnail_data);
                */
            }
        }
        else if (ii == 0) {
            set_title(band_specified, band);
        }

        if (curr->meta && curr->meta->general)  {
            if (set_lut_based_on_image_type(curr->meta->general->image_data_type))
            {
                check_lut();
                // data we loaded needs to be lutted
                apply_lut_to_data(thumbnail_data);
            }
        }
        
        // load the metadata & image data, other setup
        setup_gdk_window_ids();
        setup_small_image_size();
        fill_small_have_data(thumbnail_data, curr);
        fill_big(curr);
        update_pixel_info(curr);
        update_zoom();
        set_font();
        fill_meta_info();
        update_map_settings(curr);
        fill_stats(curr);
        set_mapping_defaults(curr);
        setup_bands_tab(curr->meta);
        disable_meta_button_if_necessary();
        if (lut_specified)
            select_lut(lut);
    }

    if (n_images_loaded>0) {
        asfPrintStatus("Currently displaying %d: %s\n",
                       current_image_info_index, curr->filename);
    }

    glade_xml_signal_autoconnect(glade_xml);
    gtk_main ();

    // If the last viewed file left behind a (temporary) color map lut,
    // then get rid of it
    if (fileExists(embedded_tiff_lut_file))
      remove(embedded_tiff_lut_file);
    if (fileExists(embedded_asf_colormap_file))
      remove(embedded_asf_colormap_file);

    image_info_free(curr);
    free_shapes();
    exit (EXIT_SUCCESS);
}
示例#14
0
void GameManager::init()
{
#ifdef CHOWDREN_USER_PROFILER
    user_log.open("log.txt", "w");
#endif

#ifdef CHOWDREN_USE_PROFILER
    PROFILE_SET_DAMPING(0.0);
#endif
    frame = &static_frames;

#ifdef CHOWDREN_IS_DEMO
    idle_timer_started = false;
    global_time = show_build_timer = reset_timer = manual_reset_timer = 0.0;
#endif

#ifdef CHOWDREN_USE_JOYTOKEY
    simulate_count = 0;
    axis_moved = false;
    last_axis = -1;
    deadzone = 0.4f;
    pad_selected = false;
    pad_disconnected = false;
    for (int i = 0; i < CHOWDREN_BUTTON_MAX-1; i++)
        key_mappings[i] = -1;
    for (int i = 0; i < CHOWDREN_AXIS_MAX-1; i++) {
        axis_pos_mappings[i] = -1;
        axis_neg_mappings[i] = -1;
        axis_values[i] = 0;
    }
#endif
    platform_init();
    media.init();
    set_window(false);

    // application setup
    preload_images();
    reset_globals();
    setup_keys(this);

    // setup random generator from start
    cross_srand((unsigned int)platform_get_global_time());

    fps_limit.start();
    set_framerate(FRAMERATE);

    int start_frame = 0;
#if defined(CHOWDREN_IS_AVGN)
    start_frame = 0;
#elif defined(CHOWDREN_IS_HFA)
    start_frame = 0;
#elif defined(CHOWDREN_IS_FP)
    player_died = false;
    lives = 3;
    start_frame = 0;
    // values->set(1, 2);
    // values->set(12, 2);
#elif defined(CHOWDREN_IS_NAH)
    platform_set_scale_type(2);
    // start_frame = 3;
    // set_local("fre");
    // values->set(13, 25);
    // strings->set(23, "OBJETS");
    // strings->set(9, "-fre");
#else
    start_frame = 0;
#endif

#ifdef NDEBUG
    set_frame(0);
#else
    set_frame(start_frame);
#endif
}
示例#15
0
int main(int argc, char **argv)
{
	bool fork_desired = TRUE;
	bool log_to_stderr_desired = FALSE;
	bool nat_traversal = FALSE;
	bool nat_t_spf = TRUE;  /* support port floating */
	unsigned int keep_alive = 0;
	bool force_keepalive = FALSE;
	char *virtual_private = NULL;
	int lockfd;
#ifdef CAPABILITIES
	int keep[] = { CAP_NET_ADMIN, CAP_NET_BIND_SERVICE };
#endif /* CAPABILITIES */

	/* initialize library and optionsfrom */
	if (!library_init(NULL))
	{
		library_deinit();
		exit(SS_RC_LIBSTRONGSWAN_INTEGRITY);
	}
	if (!libhydra_init("pluto"))
	{
		libhydra_deinit();
		library_deinit();
		exit(SS_RC_INITIALIZATION_FAILED);
	}
	if (!pluto_init(argv[0]))
	{
		pluto_deinit();
		libhydra_deinit();
		library_deinit();
		exit(SS_RC_DAEMON_INTEGRITY);
	}
	options = options_create();

	/* handle arguments */
	for (;;)
	{
#       define DBG_OFFSET 256
		static const struct option long_opts[] = {
			/* name, has_arg, flag, val */
			{ "help", no_argument, NULL, 'h' },
			{ "version", no_argument, NULL, 'v' },
			{ "optionsfrom", required_argument, NULL, '+' },
			{ "nofork", no_argument, NULL, 'd' },
			{ "stderrlog", no_argument, NULL, 'e' },
			{ "nocrsend", no_argument, NULL, 'c' },
			{ "strictcrlpolicy", no_argument, NULL, 'r' },
			{ "crlcheckinterval", required_argument, NULL, 'x'},
			{ "cachecrls", no_argument, NULL, 'C' },
			{ "uniqueids", no_argument, NULL, 'u' },
      { "disableuniqreqids", no_argument, NULL, 'Z'},			
			{ "interface", required_argument, NULL, 'i' },
			{ "ikeport", required_argument, NULL, 'p' },
			{ "ctlbase", required_argument, NULL, 'b' },
			{ "secretsfile", required_argument, NULL, 's' },
			{ "foodgroupsdir", required_argument, NULL, 'f' },
			{ "perpeerlogbase", required_argument, NULL, 'P' },
			{ "perpeerlog", no_argument, NULL, 'l' },
			{ "policygroupsdir", required_argument, NULL, 'f' },
#ifdef USE_LWRES
			{ "lwdnsq", required_argument, NULL, 'a' },
#else /* !USE_LWRES */
			{ "adns", required_argument, NULL, 'a' },
#endif /* !USE_LWRES */
			{ "pkcs11module", required_argument, NULL, 'm' },
			{ "pkcs11keepstate", no_argument, NULL, 'k' },
			{ "pkcs11initargs", required_argument, NULL, 'z' },
			{ "pkcs11proxy", no_argument, NULL, 'y' },
			{ "nat_traversal", no_argument, NULL, '1' },
			{ "keep_alive", required_argument, NULL, '2' },
			{ "force_keepalive", no_argument, NULL, '3' },
			{ "disable_port_floating", no_argument, NULL, '4' },
			{ "debug-natt", no_argument, NULL, '5' },
			{ "virtual_private", required_argument, NULL, '6' },
#ifdef DEBUG
			{ "debug-none", no_argument, NULL, 'N' },
			{ "debug-all", no_argument, NULL, 'A' },
			{ "debug-raw", no_argument, NULL, DBG_RAW + DBG_OFFSET },
			{ "debug-crypt", no_argument, NULL, DBG_CRYPT + DBG_OFFSET },
			{ "debug-parsing", no_argument, NULL, DBG_PARSING + DBG_OFFSET },
			{ "debug-emitting", no_argument, NULL, DBG_EMITTING + DBG_OFFSET },
			{ "debug-control", no_argument, NULL, DBG_CONTROL + DBG_OFFSET },
			{ "debug-lifecycle", no_argument, NULL, DBG_LIFECYCLE + DBG_OFFSET },
			{ "debug-klips", no_argument, NULL, DBG_KERNEL + DBG_OFFSET },
			{ "debug-kernel", no_argument, NULL, DBG_KERNEL + DBG_OFFSET },
			{ "debug-dns", no_argument, NULL, DBG_DNS + DBG_OFFSET },
			{ "debug-oppo", no_argument, NULL, DBG_OPPO + DBG_OFFSET },
			{ "debug-controlmore", no_argument, NULL, DBG_CONTROLMORE + DBG_OFFSET },
			{ "debug-private", no_argument, NULL, DBG_PRIVATE + DBG_OFFSET },

			{ "impair-delay-adns-key-answer", no_argument, NULL, IMPAIR_DELAY_ADNS_KEY_ANSWER + DBG_OFFSET },
			{ "impair-delay-adns-txt-answer", no_argument, NULL, IMPAIR_DELAY_ADNS_TXT_ANSWER + DBG_OFFSET },
			{ "impair-bust-mi2", no_argument, NULL, IMPAIR_BUST_MI2 + DBG_OFFSET },
			{ "impair-bust-mr2", no_argument, NULL, IMPAIR_BUST_MR2 + DBG_OFFSET },
#endif
			{ 0,0,0,0 }
			};
		/* Note: we don't like the way short options get parsed
		 * by getopt_long, so we simply pass an empty string as
		 * the list.  It could be "hvdenp:l:s:" "NARXPECK".
		 */
		int c = getopt_long(argc, argv, "", long_opts, NULL);

		/* Note: "breaking" from case terminates loop */
		switch (c)
		{
		case EOF:       /* end of flags */
			break;

		case 0: /* long option already handled */
			continue;

		case ':':       /* diagnostic already printed by getopt_long */
		case '?':       /* diagnostic already printed by getopt_long */
			usage("");
			break;   /* not actually reached */

		case 'h':       /* --help */
			usage(NULL);
			break;      /* not actually reached */

		case 'v':       /* --version */
			{
				const char **sp = ipsec_copyright_notice();

				printf("strongSwan "VERSION"%s\n", compile_time_interop_options);
				for (; *sp != NULL; sp++)
					puts(*sp);
			}
			exit_pluto(0);
			break;      /* not actually reached */

		case '+':       /* --optionsfrom <filename> */
			if (!options->from(options, optarg, &argc, &argv, optind))
			{
				exit_pluto(1);
			}
			continue;

		case 'd':       /* --nofork*/
			fork_desired = FALSE;
			continue;

		case 'e':       /* --stderrlog */
			log_to_stderr_desired = TRUE;
			continue;

		case 'c':       /* --nocrsend */
			no_cr_send = TRUE;
			continue;

		case 'r':       /* --strictcrlpolicy */
			strict_crl_policy = TRUE;
			continue;

		case 'x':       /* --crlcheckinterval <time>*/
			if (optarg == NULL || !isdigit(optarg[0]))
				usage("missing interval time");

			{
				char *endptr;
				long interval = strtol(optarg, &endptr, 0);

				if (*endptr != '\0' || endptr == optarg
				|| interval <= 0)
					usage("<interval-time> must be a positive number");
				crl_check_interval = interval;
			}
			continue;

		case 'C':       /* --cachecrls */
			cache_crls = TRUE;
			continue;

		case 'u':       /* --uniqueids */
			uniqueIDs = TRUE;
			continue;
	
	  case 'Z':       /* --disableuniqreqids */
	    disable_uniqreqids = TRUE;
	    continue;

		case 'i':       /* --interface <ifname> */
			if (!use_interface(optarg))
				usage("too many --interface specifications");
			continue;

		case 'p':       /* --port <portnumber> */
			if (optarg == NULL || !isdigit(optarg[0]))
				usage("missing port number");

			{
				char *endptr;
				long port = strtol(optarg, &endptr, 0);

				if (*endptr != '\0' || endptr == optarg
				|| port <= 0 || port > 0x10000)
					usage("<port-number> must be a number between 1 and 65535");
				pluto_port = port;
			}
			continue;

		case 'b':       /* --ctlbase <path> */
			if (snprintf(ctl_addr.sun_path, sizeof(ctl_addr.sun_path)
			, "%s%s", optarg, CTL_SUFFIX) == -1)
				usage("<path>" CTL_SUFFIX " too long for sun_path");
			if (snprintf(info_addr.sun_path, sizeof(info_addr.sun_path)
			, "%s%s", optarg, INFO_SUFFIX) == -1)
				usage("<path>" INFO_SUFFIX " too long for sun_path");
			if (snprintf(pluto_lock, sizeof(pluto_lock)
			, "%s%s", optarg, LOCK_SUFFIX) == -1)
				usage("<path>" LOCK_SUFFIX " must fit");
			continue;

		case 's':       /* --secretsfile <secrets-file> */
			shared_secrets_file = optarg;
			continue;

		case 'f':       /* --policygroupsdir <policygroups-dir> */
			policygroups_dir = optarg;
			continue;

		case 'a':       /* --adns <pathname> */
			pluto_adns_option = optarg;
			continue;

		case 'm':       /* --pkcs11module <pathname> */
			pkcs11_module_path = optarg;
			continue;

		case 'k':       /* --pkcs11keepstate */
			pkcs11_keep_state = TRUE;
			continue;

		case 'y':       /* --pkcs11proxy */
			pkcs11_proxy = TRUE;
			continue;

		case 'z':       /* --pkcs11initargs */
			pkcs11_init_args = optarg;
			continue;

#ifdef DEBUG
		case 'N':       /* --debug-none */
			base_debugging = DBG_NONE;
			continue;

		case 'A':       /* --debug-all */
			base_debugging = DBG_ALL;
			continue;
#endif

		case 'P':       /* --perpeerlogbase */
			base_perpeer_logdir = optarg;
			continue;

		case 'l':
			log_to_perpeer = TRUE;
			continue;

		case '1':       /* --nat_traversal */
			nat_traversal = TRUE;
			continue;
		case '2':       /* --keep_alive */
			keep_alive = atoi(optarg);
			continue;
		case '3':       /* --force_keepalive */
			force_keepalive = TRUE;
			continue;
		case '4':       /* --disable_port_floating */
			nat_t_spf = FALSE;
			continue;
		case '5':       /* --debug-nat_t */
			base_debugging |= DBG_NATT;
			continue;
		case '6':       /* --virtual_private */
			virtual_private = optarg;
			continue;

		default:
#ifdef DEBUG
			if (c >= DBG_OFFSET)
			{
				base_debugging |= c - DBG_OFFSET;
				continue;
			}
#       undef DBG_OFFSET
#endif
			bad_case(c);
		}
		break;
	}
	if (optind != argc)
		usage("unexpected argument");
	reset_debugging();
	lockfd = create_lock();

	/* select between logging methods */

	if (log_to_stderr_desired)
	{
		log_to_syslog = FALSE;
	}
	else
	{
		log_to_stderr = FALSE;
	}

	/* set the logging function of pfkey debugging */
#ifdef DEBUG
	pfkey_debug_func = DBG_log;
#else
	pfkey_debug_func = NULL;
#endif

	/* create control socket.
	 * We must create it before the parent process returns so that
	 * there will be no race condition in using it.  The easiest
	 * place to do this is before the daemon fork.
	 */
	{
		err_t ugh = init_ctl_socket();

		if (ugh != NULL)
		{
			fprintf(stderr, "pluto: %s", ugh);
			exit_pluto(1);
		}
	}

	/* If not suppressed, do daemon fork */

	if (fork_desired)
	{
		{
			pid_t pid = fork();

			if (pid < 0)
			{
				int e = errno;

				fprintf(stderr, "pluto: fork failed (%d %s)\n",
					errno, strerror(e));
				exit_pluto(1);
			}

			if (pid != 0)
			{
				/* parent: die, after filling PID into lock file.
				 * must not use exit_pluto: lock would be removed!
				 */
				exit(fill_lock(lockfd, pid)? 0 : 1);
			}
		}

		if (setsid() < 0)
		{
			int e = errno;

			fprintf(stderr, "setsid() failed in main(). Errno %d: %s\n",
				errno, strerror(e));
			exit_pluto(1);
		}
	}
	else
	{
		/* no daemon fork: we have to fill in lock file */
		(void) fill_lock(lockfd, getpid());
		fprintf(stdout, "Pluto initialized\n");
		fflush(stdout);
	}

	/* Redirect stdin, stdout and stderr to /dev/null
	 */
	{
		int fd;
		if ((fd = open("/dev/null", O_RDWR)) == -1)
			abort();
		if (dup2(fd, 0) != 0)
			abort();
		if (dup2(fd, 1) != 1)
			abort();
		if (!log_to_stderr && dup2(fd, 2) != 2)
			abort();
		close(fd);
	}

	init_constants();
	init_log("pluto");

	/* Note: some scripts may look for this exact message -- don't change
	 * ipsec barf was one, but it no longer does.
	 */
	plog("Starting IKEv1 pluto daemon (strongSwan "VERSION")%s",
		 compile_time_interop_options);

	if (lib->integrity)
	{
		plog("integrity tests enabled:");
		plog("lib    'libstrongswan': passed file and segment integrity tests");
		plog("lib    'libhydra': passed file and segment integrity tests");
		plog("daemon 'pluto': passed file integrity test");
	}

	/* load plugins, further infrastructure may need it */
	if (!lib->plugins->load(lib->plugins, NULL,
			lib->settings->get_str(lib->settings, "pluto.load", PLUGINS)))
	{
		exit(SS_RC_INITIALIZATION_FAILED);
	}
	print_plugins();

	init_builder();
	if (!init_secret() || !init_crypto())
	{
		plog("initialization failed - aborting pluto");
		exit_pluto(SS_RC_INITIALIZATION_FAILED);
	}
	init_nat_traversal(nat_traversal, keep_alive, force_keepalive, nat_t_spf);
	init_virtual_ip(virtual_private);
	scx_init(pkcs11_module_path, pkcs11_init_args);
	init_states();
	init_demux();
	init_kernel();
	init_adns();
	init_myid();
	fetch_initialize();
	ac_initialize();
	whack_attribute_initialize();

	/* drop unneeded capabilities and change UID/GID */
	prctl(PR_SET_KEEPCAPS, 1);

#ifdef IPSEC_GROUP
	{
		struct group group, *grp;
	char buf[1024];

		if (getgrnam_r(IPSEC_GROUP, &group, buf, sizeof(buf), &grp) != 0 ||
				grp == NULL || setgid(grp->gr_gid) != 0)
		{
			plog("unable to change daemon group");
			abort();
		}
	}
#endif
#ifdef IPSEC_USER
	{
		struct passwd passwd, *pwp;
	char buf[1024];

		if (getpwnam_r(IPSEC_USER, &passwd, buf, sizeof(buf), &pwp) != 0 ||
				pwp == NULL || setuid(pwp->pw_uid) != 0)
		{
			plog("unable to change daemon user");
			abort();
		}
		}
#endif

#ifdef CAPABILITIES_LIBCAP
	{
		cap_t caps;
		caps = cap_init();
		cap_set_flag(caps, CAP_EFFECTIVE, countof(keep), keep, CAP_SET);
		cap_set_flag(caps, CAP_INHERITABLE, countof(keep), keep, CAP_SET);
		cap_set_flag(caps, CAP_PERMITTED, countof(keep), keep, CAP_SET);
		if (cap_set_proc(caps) != 0)
		{
			plog("unable to drop daemon capabilities");
			abort();
		}
		cap_free(caps);
	}
#endif /* CAPABILITIES_LIBCAP */
#ifdef CAPABILITIES_NATIVE
	{
		struct __user_cap_data_struct caps = { .effective = 0 };
		struct __user_cap_header_struct header = {
			.version = _LINUX_CAPABILITY_VERSION,
		};
		int i;
		for (i = 0; i < countof(keep); i++)
		{
			caps.effective |= 1 << keep[i];
			caps.permitted |= 1 << keep[i];
			caps.inheritable |= 1 << keep[i];
		}
		if (capset(&header, &caps) != 0)
		{
			plog("unable to drop daemon capabilities");
			abort();
		}
	}
#endif /* CAPABILITIES_NATIVE */

	/* loading X.509 CA certificates */
	load_authcerts("ca", CA_CERT_PATH, X509_CA);
	/* loading X.509 AA certificates */
	load_authcerts("aa", AA_CERT_PATH, X509_AA);
	/* loading X.509 OCSP certificates */
	load_authcerts("ocsp", OCSP_CERT_PATH, X509_OCSP_SIGNER);
	/* loading X.509 CRLs */
	load_crls();
	/* loading attribute certificates (experimental) */
	ac_load_certs();

	lib->processor->set_threads(lib->processor,
			lib->settings->get_int(lib->settings, "pluto.threads",
								   DEFAULT_THREADS));

	daily_log_event();
	call_server();
	return -1;  /* Shouldn't ever reach this */
}

/* leave pluto, with status.
 * Once child is launched, parent must not exit this way because
 * the lock would be released.
 *
 *  0 OK
 *  1 general discomfort
 * 10 lock file exists
 */
void exit_pluto(int status)
{
	lib->processor->set_threads(lib->processor, 0);
	reset_globals();    /* needed because we may be called in odd state */
	free_preshared_secrets();
	free_remembered_public_keys();
	delete_every_connection();
	whack_attribute_finalize(); /* free in-memory pools */
	kernel_finalize();
	fetch_finalize();           /* stop fetching thread */
	free_crl_fetch();           /* free chain of crl fetch requests */
	free_ocsp_fetch();          /* free chain of ocsp fetch requests */
	free_authcerts();           /* free chain of X.509 authority certificates */
	free_crls();                /* free chain of X.509 CRLs */
	free_ca_infos();            /* free chain of X.509 CA information records */
	free_ocsp();                /* free ocsp cache */
	free_ifaces();
	ac_finalize();              /* free X.509 attribute certificates */
	scx_finalize();             /* finalize and unload PKCS #11 module */
	stop_adns();
	free_md_pool();
	free_crypto();
	free_myid();                /* free myids */
	free_events();              /* free remaining events */
	free_vendorid();            /* free all vendor id records */
	free_builder();
	delete_lock();
	options->destroy(options);
	pluto_deinit();
	lib->plugins->unload(lib->plugins);
	libhydra_deinit();
	library_deinit();
	close_log();
	exit(status);
}
示例#16
0
int main(int argc, char *argv[])
{
    char  *part[MAX_LINE_LEN/2];
    char   line[MAX_LINE_LEN];
    char   parts[3*MAX_LINE_LEN/2+1];
    int    n_parts;
    float time_s;
    int time_int;

    // if we have less than 2 arguments (executable+file to read)
    if (argc < 3)
    {
        printf("\n Usage: %s <record in> <record_out> \n", argv[0]);
        exit(0);
    }
    // open record (1st argument of executable) for input and check
    // if it can be opened

    if ( !(fptr_out = fopen(argv[2],"w")) )
    {
        fprintf(stderr, "\n Error: cannot open record %s\n",argv[2]);
        exit(0);
    }
    if ( !(fptr_in = fopen(argv[1],"r")) )
    {
        fprintf(stderr, "\n Error: cannot open record %s\n",argv[1]);
        exit(0);
    }

    // loop over the data until the end of the file
    while (parse_line(fptr_in, line, MAX_LINE_LEN, parts, part, &n_parts, NULL))
    {
        /* fprintf(stderr,"%d parts : last part is %s\n",n_parts,part[n_parts-1]); */
        time_int = atoi(part[3]);
        // time_float = atof(part[5]);
        time_s = (float)(time_int)/sample_freq;

        //    printf("%i %f\n",time_int,time_s);
        //        printf("%i %i %i %i %i %i %i %i\n",atoi(part[0]),atoi(part[1]),atoi(part[2]),atoi(part[3]),atoi(part[4]),atoi(part[5]),atoi(part[6]),atoi(part[7]));

        //    printf("%i %f\n",n_parts,time_s);
        if (n_parts < 8) fprintf(stderr," -20 "); // error
        else if (n_parts-1 == 7)
        {   // label state - if there is no other label third column is 0
            if (!strcmp(part[4],"N")) {
                fprintf(fptr_out,"%f 1\n",time_s);
                normals_in_5_min +=1;
            }
            else if (!strcmp(part[4],"L")) {
                fprintf(fptr_out,"%f 2\n",time_s);
                ectopics_in_5_min +=1;
            }
            else if (!strcmp(part[4],"R")) {
                fprintf(fptr_out,"%f 3\n",time_s);
                ectopics_in_5_min +=1;
            }
            else if (!strcmp(part[4],"B")) {
                fprintf(fptr_out,"%f 4\n",time_s);
                ectopics_in_5_min +=1;
            }
            else if (!strcmp(part[4],"A")) {
                fprintf(fptr_out,"%f 5\n",time_s);
                ectopics_in_5_min +=1;
            }
            else if (!strcmp(part[4],"a")) {
                fprintf(fptr_out,"%f 6\n",time_s);
                ectopics_in_5_min +=1;
            }
            else if (!strcmp(part[4],"J")) {
                fprintf(fptr_out,"%f 7\n",time_s);
                ectopics_in_5_min +=1;
            }
            else if (!strcmp(part[4],"S")) {
                fprintf(fptr_out,"%f 8\n",time_s);
                ectopics_in_5_min +=1;
            }
            else if (!strcmp(part[4],"V")) {
                fprintf(fptr_out,"%f 9\n",time_s);
                ectopics_in_5_min +=1;
            }
            else if (!strcmp(part[4],"r")) {
                fprintf(fptr_out,"%f 10\n",time_s);
                ectopics_in_5_min +=1;
            }
            else if (!strcmp(part[4],"F")) {
                fprintf(fptr_out,"%f 11\n",time_s);
                ectopics_in_5_min +=1;
            }
            else if (!strcmp(part[4],"e")) {
                fprintf(fptr_out,"%f 12\n",time_s);
                ectopics_in_5_min +=1;
            }
            else if (!strcmp(part[4],"j")) {
                fprintf(fptr_out,"%f 13\n",time_s);
                ectopics_in_5_min +=1;
            }
            else if (!strcmp(part[4],"n")) {
                fprintf(fptr_out,"%f 14\n",time_s);
                ectopics_in_5_min +=1;
            }
            else if (!strcmp(part[4],"E")) {
                fprintf(fptr_out,"%f 15\n",time_s);
                ectopics_in_5_min +=1;
            }
            else if (!strcmp(part[4],"f")) {
                fprintf(fptr_out,"%f 16\n",time_s);
                ectopics_in_5_min +=1;
            }
            else if (!strcmp(part[4],"Q")) {
                fprintf(fptr_out,"%f 17\n",time_s);
                ectopics_in_5_min +=1;
            }
            else if (!strcmp(part[4],"\?")) {
                fprintf(fptr_out,"%f 20\n",time_s);
                unspecified_in_5_min +=1;
            }
            else if (!strcmp(part[4],"P")) {
                fprintf(fptr_out,"%f 25\n",time_s);
                paced_in_5_min +=1;
            }
            else if (!strcmp(part[4],"|")) {
                fprintf(fptr_out,"%f 30\n",time_s);
                artefact_in_5_min +=1;
            }
            else if (!strcmp(part[4],"~")) {
                fprintf(fptr_out,"%f 31\n",time_s);
                artefact_in_5_min +=1;
            }
            else if (!strcmp(part[4],"{")) {
                fprintf(fptr_out,"%f 32\n",time_s);
                artefact_in_5_min +=1;
            }
            else if (!strcmp(part[4],"}")) {
                fprintf(fptr_out,"%f 33\n",time_s);
                artefact_in_5_min +=1;
            }
            else if (!strcmp(part[4],"\\")) {
                fprintf(fptr_out,"%f 33\n",time_s);
                artefact_in_5_min +=1;
            }
            else fprintf(fptr_out,"%f 0\n",time_s); // error
        }
        else if (n_parts-1 == 8) // we've clicked over onto the next day
        {
            time_int = atoi(part[4]);
            // time_float = atof(part[5]);
            time_s = (float)(time_int)/sample_freq;

            if (!strcmp(part[5],"N")) {
                fprintf(fptr_out,"%f 1\n",time_s);
                normals_in_5_min +=1;
            }
            else if (!strcmp(part[5],"L")) {
                fprintf(fptr_out,"%f 2\n",time_s);
                ectopics_in_5_min +=1;
            }
            else if (!strcmp(part[5],"R")) {
                fprintf(fptr_out,"%f 3\n",time_s);
                ectopics_in_5_min +=1;
            }
            else if (!strcmp(part[5],"B")) {
                fprintf(fptr_out,"%f 4\n",time_s);
                ectopics_in_5_min +=1;
            }
            else if (!strcmp(part[5],"A")) {
                fprintf(fptr_out,"%f 5\n",time_s);
                ectopics_in_5_min +=1;
            }
            else if (!strcmp(part[5],"a")) {
                fprintf(fptr_out,"%f 6\n",time_s);
                ectopics_in_5_min +=1;
            }
            else if (!strcmp(part[5],"J")) {
                fprintf(fptr_out,"%f 7\n",time_s);
                ectopics_in_5_min +=1;
            }
            else if (!strcmp(part[5],"S")) {
                fprintf(fptr_out,"%f 8\n",time_s);
                ectopics_in_5_min +=1;
            }
            else if (!strcmp(part[5],"V")) {
                fprintf(fptr_out,"%f 9\n",time_s);
                ectopics_in_5_min +=1;
            }
            else if (!strcmp(part[5],"r")) {
                fprintf(fptr_out,"%f 10\n",time_s);
                ectopics_in_5_min +=1;
            }
            else if (!strcmp(part[5],"F")) {
                fprintf(fptr_out,"%f 11\n",time_s);
                ectopics_in_5_min +=1;
            }
            else if (!strcmp(part[5],"e")) {
                fprintf(fptr_out,"%f 12\n",time_s);
                ectopics_in_5_min +=1;
            }
            else if (!strcmp(part[5],"j")) {
                fprintf(fptr_out,"%f 13\n",time_s);
                ectopics_in_5_min +=1;
            }
            else if (!strcmp(part[5],"n")) {
                fprintf(fptr_out,"%f 14\n",time_s);
                ectopics_in_5_min +=1;
            }
            else if (!strcmp(part[5],"E")) {
                fprintf(fptr_out,"%f 15\n",time_s);
                ectopics_in_5_min +=1;
            }
            else if (!strcmp(part[5],"f")) {
                fprintf(fptr_out,"%f 16\n",time_s);
                ectopics_in_5_min +=1;
            }
            else if (!strcmp(part[5],"Q")) {
                fprintf(fptr_out,"%f 17\n",time_s);
                ectopics_in_5_min +=1;
            }
            else if (!strcmp(part[5],"\?")) {
                fprintf(fptr_out,"%f 20\n",time_s);
                unspecified_in_5_min +=1;
            }
            else if (!strcmp(part[5],"P")) {
                fprintf(fptr_out,"%f 25\n",time_s);
                paced_in_5_min +=1;
            }
            else if (!strcmp(part[5],"|")) {
                fprintf(fptr_out,"%f 30\n",time_s);
                artefact_in_5_min +=1;
            }
            else if (!strcmp(part[5],"~")) {
                fprintf(fptr_out,"%f 31\n",time_s);
                artefact_in_5_min +=1;
            }
            else if (!strcmp(part[5],"{")) {
                fprintf(fptr_out,"%f 32\n",time_s);
                artefact_in_5_min +=1;
            }
            else if (!strcmp(part[5],"}")) {
                fprintf(fptr_out,"%f 33\n",time_s);
                artefact_in_5_min +=1;
            }
            else if (!strcmp(part[5],"\\")) {
                fprintf(fptr_out,"%f 33\n",time_s);
                artefact_in_5_min +=1;
            }
            else fprintf(fptr_out,"%f 0\n",time_s); // error
        }
        else fprintf(fptr_out,"%f -100\n",time_s); // big error
        //fprintf(stdout,"%i %s %i\n",time_int,part[n_parts-1], n_parts-1);

        //printf("%i ",((int)(time_s*1000))%(WINDOW*60*1000) );
        //    if( ((int)(time_s*1000))%(WINDOW*60*1000)<50){
        if( (time_s-start_of_wind)> (60*WINDOW) ) {
            start_of_wind=time_s;
            fivemin_HR = normals_in_5_min/WINDOW;
            printf("%f %f %i %i %i %i %i\n",time_s,fivemin_HR,normals_in_5_min,ectopics_in_5_min,artefact_in_5_min,unspecified_in_5_min,paced_in_5_min);
            reset_globals();
        }

    }
    return(1);
}
示例#17
0
int main(int argc, char *argv[])
{
    bool  recalculate = FALSE;
    int   len;
    err_t e;
    err_t err = NULL;
    char *infile;
    char *conn_name;
    int  lineno=0;
    struct connection *c1 = NULL;
    struct id moon, cassidy;
    struct adns_continuation *cr1 = NULL;

#ifdef HAVE_EFENCE
    EF_PROTECT_FREE=1;
#endif

    initproctitle(argc, argv);
    progname = argv[0];
    leak_detective = 1;

    if(argc != 3 && argc!=4) {
	fprintf(stderr, "Usage: %s [-r] <whackrecord> <conn-name>\n", progname);
	exit(10);
    }
    /* skip argv0 */
    argc--; argv++;

    if(strcmp(argv[0], "-r")==0) {
        recalculate = 1;    /* do all crypto */
        argc--; argv++;
    }

    tool_init_log();
    cur_debugging |= DBG_DNS;
    init_adns();

    {
    	int r;
	struct sigaction act;

	act.sa_handler = &childhandler;
	act.sa_flags   = SA_RESTART;
	r = sigaction(SIGCHLD, &act, NULL);
	passert(r == 0);
    }

    reset_globals();

    /* setup a query */
    cr1 = alloc_thing(struct adns_continuation, "moon lookup");
    moon.kind = ID_FQDN;
    strtochunk(moon.name, "moon.testing.openswan.org", "dns name");
    e = start_adns_query(&moon, NULL, ns_t_key,
                         moon_continue, cr1);
    freeanychunk(moon.name);
    process_dns_results();

#if 0
    cr1 = alloc_thing(struct adns_continuation, "cassidy lookup");
    cassidy.kind = ID_FQDN;
    strtochunk(cassidy.name, "cassidy.sandelman.ca", "dns name 2");
    e = start_adns_query(&cassidy, NULL, ns_t_key,
                         cassidy_continue, cr1);
    freeanychunk(cassidy.name);
    process_dns_results();
#endif

    /* re-use cassidy */
    cr1 = alloc_thing(struct adns_continuation, "cassidy A lookup");
    e = start_adns_hostname(AF_UNSPEC, "cassidy.sandelman.ca", cassidy_host_continue, cr1);
    process_dns_results();

    stop_adns();
    report_leaks();

    tool_close_log();
    exit(0);
}
示例#18
0
static void load_file_banded_imp(const char *file, const char *band,
                                 int reset_location, int multilook)
{
    char *old_file = NULL;
    if (curr->filename) {
      old_file = STRDUP(curr->filename);
      free(curr->filename);
      curr->filename = NULL;
    }

    reset_globals(reset_location);
    asfPrintStatus("\nLoading: %s\n", file);

    // start loading of the new file
    curr->filename = STRDUP(file);

    // strip off a trailing "."
    if (curr->filename[strlen(curr->filename)-1] == '.')
        curr->filename[strlen(curr->filename)-1] = '\0';

    // Determine if the current file is a new file
    static char *last_file = NULL;
    int new_file = 0;
    if (!last_file) last_file = STRDUP(curr->filename);
    if (last_file && strcmp(last_file, curr->filename) != 0) {
      new_file = 1;
      FREE(last_file);
      last_file = STRDUP(curr->filename);
    }

    if (read_file(curr->filename, band, multilook, FALSE)) {
      int dummy;
      char lut[256];
      static int tiff_lut_exists = 0;
      static int asf_colormap_exists = 0;
      char embedded_tiff_lut_file[1024];
      char embedded_asf_colormap_file[1024];
      char *lut_loc = (char *)MALLOC(sizeof(char)*(strlen(get_asf_share_dir())+128));
      sprintf(lut_loc, "%s%clook_up_tables", get_asf_share_dir(), DIR_SEPARATOR);
      sprintf(embedded_tiff_lut_file,"%s%c%s", lut_loc, DIR_SEPARATOR,
              EMBEDDED_TIFF_COLORMAP_LUT_FILE);
      sprintf(embedded_asf_colormap_file, "%s%c%s", lut_loc, DIR_SEPARATOR,
              EMBEDDED_ASF_COLORMAP_LUT_FILE);
      FREE(lut_loc);
      tiff_lut_exists      = new_file ? 0 : tiff_lut_exists;
      asf_colormap_exists  = new_file ? 0 : asf_colormap_exists;
      tiff_lut_exists     += fileExists(embedded_tiff_lut_file)     ? 1 : 0;
      asf_colormap_exists += fileExists(embedded_asf_colormap_file) ? 1 : 0;
      GtkWidget *om = get_widget_checked("lut_optionmenu");
      int idx = gtk_option_menu_get_history(GTK_OPTION_MENU(om));
      if (tiff_lut_exists <= 1 &&
          check_for_embedded_tiff_lut(curr->filename, &dummy, lut))
      {
        // On first read of a TIFF file, check for embedded colormap and turn it into a
        // look up table if it exists ...then select it
        // (Run this stuff ONCE ...else the embedded lut will keep getting selected, even if changed)
        if (fileExists(embedded_asf_colormap_file)) {
          remove(embedded_asf_colormap_file);
          asf_colormap_exists = 0;
        }

        if (get_tiff_lut_index() == 0) {
            populate_lut_combo();

            GtkWidget *option_menu = get_widget_checked("lut_optionmenu");
            gtk_option_menu_set_history(GTK_OPTION_MENU(option_menu), get_tiff_lut_index());
            set_current_index(get_tiff_lut_index());
            select_lut(lut);
        }
        else {
            set_current_index(idx);
        }
      }
      else if (tiff_lut_exists &&
               !check_for_embedded_tiff_lut(curr->filename, &dummy, lut))
      {
        // If a tiff colormap look up table exists, but the current file being
        // read is not a color map tiff, then delete the existing tiff color map
        // look up table
        remove(embedded_tiff_lut_file);
        tiff_lut_exists = 0;
        populate_lut_combo(); // Re-populate since tiff colormap lut was removed
        GtkWidget *option_menu = get_widget_checked("lut_optionmenu");
        gtk_option_menu_set_history(GTK_OPTION_MENU(option_menu), 0); // Default to None
        set_current_index(0);
      }
      if (asf_colormap_exists <= 1 && is_colormap_ASF_file(curr->filename)) {
        // On first read of an ASF file, check for a colormap and turn it into a
        // look up table if it exists ...then select it
        // (Run this stuff ONCE ...else the embedded lut will keep getting selected, even if changed)
        if (fileExists(embedded_tiff_lut_file)) {
          remove(embedded_tiff_lut_file);
          tiff_lut_exists = 0;
        }
        if (get_asf_lut_index() == 0) {
            populate_lut_combo();
            select_lut(EMBEDDED_ASF_COLORMAP_LUT);

            GtkWidget *option_menu = get_widget_checked("lut_optionmenu");
            gtk_option_menu_set_history(GTK_OPTION_MENU(option_menu), get_asf_lut_index());
            set_current_index(get_asf_lut_index());
        }
        else {
            set_current_index(idx);
        }
      }
      else if (asf_colormap_exists && !is_colormap_ASF_file(curr->filename)) {
        // If an ASF colormap look up table exists, but the current file being
        // read does not contain a color map in the metadata, then delete the existing ASF color map
        // look up table
        remove(embedded_asf_colormap_file);
        asf_colormap_exists = 0;
        populate_lut_combo(); // Re-populate since tiff colormap lut was removed
        GtkWidget *option_menu = get_widget_checked("lut_optionmenu");
        gtk_option_menu_set_history(GTK_OPTION_MENU(option_menu), 0); // Default to None
        set_current_index(0);
      }
      if (new_file && !tiff_lut_exists && !asf_colormap_exists &&
           reset_location && curr->meta && curr->meta->general)
      {
        // Change LUT selection if necessary
        set_lut_based_on_image_type(curr->meta->general->image_data_type);
      }
      else if (!new_file) {
          // Respect any changes made by the user to the look-up table selection after
          // the file has loaded the first time ...
          set_current_index(idx);
      }
      check_lut();
      set_title(band != NULL, band);

      // load the metadata & image data, other setup
      fill_small_force_reload(curr);
      fill_big(curr);
      update_pixel_info(curr);
      update_zoom();
      fill_meta_info();
      fill_stats(curr);
      setup_bands_tab(curr->meta);

      FREE(old_file);
    }
    else {
      // file failed to load, re-load the old one

      // this is to prevent trying to re-load the old file again & again,
      // if for some reason that fails
      if (strcmp(curr->filename, old_file) == 0) {
          // if this does happen, just quit
          asfPrintError("Failed to load %s.\n", curr->filename);
      }

      asfPrintStatus("Failed to load %s.  Re-loading %s.\n", curr->filename, old_file);
      load_file_banded_imp(old_file, band, reset_location, multilook);

      if (reset_location) {
        center_samp = (double)(curr->ns)/2.;
        center_line = (double)(curr->nl)/2.;
        crosshair_samp = (double)(curr->ns)/2.;
        crosshair_line = (double)(curr->nl)/2.;
      }
    }
}