Exemplo n.º 1
0
static void match_return(struct expression *ret_value)
{
	if (__inline_fn)
		return;
	if (is_reachable())
		returned = 1;
}
Exemplo n.º 2
0
static void match_func_end(struct symbol *sym)
{
	if (__inline_fn)
		return;
	if (!is_reachable() && !returned)
		sm_info("info: add to no_return_funcs");
	returned = 0;
}
Exemplo n.º 3
0
 inline bool is_connected(const VertexListGraph& g, VertexColorMap color)
 {
   typedef typename property_traits<VertexColorMap>::value_type ColorValue;
   typedef color_traits<ColorValue> Color;
   typename graph_traits<VertexListGraph>::vertex_iterator 
     ui, ui_end, vi, vi_end, ci, ci_end;
   for (boost::tie(ui, ui_end) = vertices(g); ui != ui_end; ++ui)
     for (boost::tie(vi, vi_end) = vertices(g); vi != vi_end; ++vi)
       if (*ui != *vi) {
         for (boost::tie(ci, ci_end) = vertices(g); ci != ci_end; ++ci) 
           put(color, *ci, Color::white());
         if (! is_reachable(*ui, *vi, g, color))
           return false;
       }
   return true;
 }
Exemplo n.º 4
0
void check_reachability(Graph graph, int size){
	int vertex_u, vertex_v;

	cout << "Checking out reachability..." << endl;
	cin  >> vertex_u >> vertex_v;

	bool are_reachable = is_reachable(graph,size,vertex_u,vertex_v);

	cout << vertex_u << " and " << vertex_v << " are ";
	
	if(!are_reachable){
		cout << "not ";
	}

	cout << "reachable each other" << endl;
}
Exemplo n.º 5
0
bool
AbortTask::fill_reachable(const AIRCRAFT_STATE &state,
                          AlternateVector &approx_waypoints,
                          const GlidePolar &polar,
                          const bool only_airfield,
                          const bool final_glide)
{
  if (task_full()) {
    return false;
  }
  bool found = false;
  std::priority_queue<Alternate, AlternateVector, AlternateRank> q;
  for (AlternateVector::iterator v = approx_waypoints.begin();
       v!=approx_waypoints.end(); ) {

    if (only_airfield && !v->first.Flags.Airport) {
      ++v;
      continue;
    }
    UnorderedTaskPoint t(v->first, task_behaviour);
    const GlideResult result = TaskSolution::glide_solution_remaining(t, state, polar);
    if (is_reachable(result, final_glide)) {
      q.push(std::make_pair(v->first, result));
      // remove it since it's already in the list now      
      approx_waypoints.erase(v);

      found = true;

    } else {
      ++v;
    }
  }
  while (!q.empty() && !task_full()) {
    const Alternate top = q.top();
    tps.push_back(std::make_pair(new UnorderedTaskPoint(top.first, task_behaviour),
                                 top.second));

    const int i = tps.size()-1;
    if (tps[i].first->get_waypoint().id == active_waypoint) {
      activeTaskPoint = i;
    }

    q.pop();
  }
  return found;
}
Exemplo n.º 6
0
//Is there exist a path connect 'from' and 'to'.
bool GRAPH::is_reachable(VERTEX * from, VERTEX * to)
{
	IS_TRUE(m_pool != NULL, ("not yet initialized."));
	IS_TRUE(from != NULL && to != NULL, ("parameters cannot be NULL"));
	EDGE_C * el = VERTEX_out_list(from);
	EDGE * e = NULL;
	if (el == NULL) return false;
	
	//Walk through each succ of 'from'
	for (e = EC_edge(el); e != NULL; el = EC_next(el), 
		 e = el ? EC_edge(el):NULL) {
		VERTEX * succ = EDGE_to(e);
		if (VERTEX_id(succ) == VERTEX_id(to)) {
			return true;
		} else {
			if (is_reachable(succ, to)) {
				return true;
			}
		}
	} //end for
	return false;
}
Exemplo n.º 7
0
void 
AbortTask::update_offline(const AIRCRAFT_STATE &state)
{
  update_polar();
  m_landable_reachable = false;

  AlternateVector approx_waypoints; 

  WaypointVisitorVector wvv(approx_waypoints);
  waypoints.visit_within_radius(state.Location, abort_range(state), wvv);

  for (AlternateVector::iterator v = approx_waypoints.begin();
       v!=approx_waypoints.end(); ++v) {

    UnorderedTaskPoint t(v->first, task_behaviour);
    const GlideResult result = TaskSolution::glide_solution_remaining(t, state, polar_safety);
    if (is_reachable(result, true)) {
      m_landable_reachable = true;
      return;
    }
  }
}
Exemplo n.º 8
0
 bool is_reachable(typename graph_traits<Graph>::vertex_descriptor u,
                   typename graph_traits<Graph>::vertex_descriptor v,
                   Graph const& g) {
     one_bit_color_map<> map(num_vertices(g));
     return is_reachable(u, v, g, map);
 }
Exemplo n.º 9
0
void test() {
    int A[] = {3,2,1,0,4};
    std::vector<int> input(A, A + 5);
    std::cout<<is_reachable(input);
}
Exemplo n.º 10
0
/*
 * The actual main function.
 */
int  
sntp_main (
	int argc, 
	char **argv
	) 
{
	register int c;
	struct kod_entry *reason = NULL;
	int optct;
	/* boolean, u_int quiets gcc4 signed overflow warning */
	u_int sync_data_suc;
	struct addrinfo **bcastaddr = NULL;
	struct addrinfo **resh = NULL;
	struct addrinfo *ai;
	int resc;
	int kodc;
	int ow_ret;
	int bcast = 0;
	char *hostname;

	optct = optionProcess(&sntpOptions, argc, argv);
	argc -= optct;
	argv += optct; 

	/* Initialize logging system */
	init_logging();
	if (HAVE_OPT(LOGFILE))
		open_logfile(OPT_ARG(LOGFILE));

	msyslog(LOG_NOTICE, "Started sntp");

	/* IPv6 available? */
	if (isc_net_probeipv6() != ISC_R_SUCCESS) {
		ai_fam_pref = AF_INET;
#ifdef DEBUG
		printf("No ipv6 support available, forcing ipv4\n");
#endif
	} else {
		/* Check for options -4 and -6 */
		if (HAVE_OPT(IPV4))
			ai_fam_pref = AF_INET;
		else if (HAVE_OPT(IPV6))
			ai_fam_pref = AF_INET6;
	}

	/* Parse config file if declared TODO */

	/* 
	 * If there's a specified KOD file init KOD system.  If not use
	 * default file.  For embedded systems with no writable
	 * filesystem, -K /dev/null can be used to disable KoD storage.
	 */
	if (HAVE_OPT(KOD))
		kod_init_kod_db(OPT_ARG(KOD));
	else
		kod_init_kod_db("/var/db/ntp-kod");

	if (HAVE_OPT(KEYFILE))
		auth_init(OPT_ARG(KEYFILE), &keys);

#ifdef EXERCISE_KOD_DB
	add_entry("192.168.169.170", "DENY");
	add_entry("192.168.169.171", "DENY");
	add_entry("192.168.169.172", "DENY");
	add_entry("192.168.169.173", "DENY");
	add_entry("192.168.169.174", "DENY");
	delete_entry("192.168.169.174", "DENY");
	delete_entry("192.168.169.172", "DENY");
	delete_entry("192.168.169.170", "DENY");
	if ((kodc = search_entry("192.168.169.173", &reason)) == 0)
		printf("entry for 192.168.169.173 not found but should have been!\n");
	else
		free(reason);
#endif

	/* Considering employing a variable that prevents functions of doing anything until 
	 * everything is initialized properly 
	 */
	resc = resolve_hosts((void *)argv, argc, &resh, ai_fam_pref);
	if (resc < 1) {
		printf("Unable to resolve hostname(s)\n");
		return -1;
	}
	bcast = ENABLED_OPT(BROADCAST);
	if (bcast) {
		const char * myargv[2];

		myargv[0] = OPT_ARG(BROADCAST);
		myargv[1] = NULL;
		bcast = resolve_hosts(myargv, 1, &bcastaddr, ai_fam_pref);
	}

	/* Select a certain ntp server according to simple criteria? For now
	 * let's just pay attention to previous KoDs.
	 */
	sync_data_suc = FALSE;
	for (c = 0; c < resc && !sync_data_suc; c++) {
		ai = resh[c];
		do {
			hostname = addrinfo_to_str(ai);
			if ((kodc = search_entry(hostname, &reason)) == 0) {
				if (is_reachable(ai)) {
					ow_ret = on_wire(ai, bcast ? bcastaddr[0] : NULL);
					if (0 == ow_ret)
						sync_data_suc = TRUE;
				}
			} else {
				printf("%d prior KoD%s for %s, skipping.\n", 
					kodc, (kodc > 1) ? "s" : "", hostname);
				free(reason);
			}
			free(hostname);
			ai = ai->ai_next;
		} while (NULL != ai);
		freeaddrinfo(resh[c]);
	}
	free(resh);

	if (!sync_data_suc)
		return 1;
	return 0;
}
Exemplo n.º 11
0
/*! Main
@param argc number of arguments
@param argv arguments
 @return fuse_main()s return value
*/
int main(int argc, char **argv)
{
    /* return value of fuse_main() */
    int ret;

    /* for signal handling */
    struct sigaction sig;

    /* argument handling */
    struct fuse_args args = FUSE_ARGS_INIT(argc, argv);

    /* file name for database */
    char *db_file;


    /*------------------------*
     * install signal handler *
     *------------------------*/

    /* set handling function */
    sig.sa_handler = sig_handler;

    /* set (no) flags */
    sig.sa_flags = 0;

    /* don't ignore any signal */
    sigemptyset(&sig.sa_mask);

    /* install signal handler for USR1 and USR2 */
    sigaction(SIGUSR1, &sig, NULL);
    sigaction(SIGUSR2, &sig, NULL);


    /*------------------*
     * handle arguments *
     *------------------*/

    if (fuse_opt_parse(&args, &discofs_options, discofs_opts, discofs_opt_proc) == -1)
        return EXIT_FAILURE;

    /* after option parsing, remote mount point must be set */
    if (!REMOTE_ROOT)
    {
        fprintf(stderr, "no remote filesystem given\n");
        return EXIT_FAILURE;
    }

    /* a mount point for discofs must also be set */
    if (!discofs_options.discofs_mp)
    {
        fprintf(stderr, "no mount point given\n");
        return EXIT_FAILURE;
    }

    /* add "use_ino" to display inodes in stat(1)*/
    fuse_opt_add_arg(&args, "-ouse_ino");


    /*---------------*
     * set UID / GID *
     *---------------*/

    /* set GID first since permissions might not be
       sufficient if UID was set beforehand */
    if (discofs_options.gid)
    {
        VERBOSE("setting gid to %d\n", discofs_options.gid);
        if (setgid(discofs_options.gid))
        {
            perror("setting gid");
            return EXIT_FAILURE;
        }
    }
    if (discofs_options.uid)
    {
        VERBOSE("setting uid to %d\n", discofs_options.uid);
        if (setuid(discofs_options.uid))
        {
            perror("setting uid");
            return EXIT_FAILURE;
        }
    }


    /*--------------------*
     * initialize logging *
     *--------------------*/

    /* if -d is specified, override logging settings */
    if (discofs_options.debug)
        log_init(LOG_DEBUG, NULL);
    else
        log_init(discofs_options.loglevel, discofs_options.logfile);



    /*=========================*
     * INITIALIZE CACHE AND DB *
     *=========================*/

    /* compute data root if not passed as option */
    if (!discofs_options.data_root)
        discofs_options.data_root = paths_data_root(REMOTE_ROOT);

    if (!is_dir(discofs_options.data_root))
    {
        if (mkdir_rec(discofs_options.data_root))
            FATAL("failed to create data directory %s\n", discofs_options.data_root);
    }


    /*----------------------*
     * initialize cache dir *
     *----------------------*/

    /* set cache dir */
    CACHE_ROOT = join_path(discofs_options.data_root, "cache");

    /* store length of cache root (to save a few hundred strlen() calls)  */
    CACHE_ROOT_LEN = strlen(CACHE_ROOT);

    /* delete cache if "clear" specified */
    if (discofs_options.clear)
    {
        VERBOSE("deleting cache\n");
        rmdir_rec(CACHE_ROOT);
    }

    /* create cache root if needed */
    if (!is_dir(CACHE_ROOT))
    {
        if (mkdir(CACHE_ROOT, S_IRWXU) != 0)
            FATAL("failed to create cache directory %s\n", CACHE_ROOT);
    }


    /*---------------------*
     * initialize database *
     *---------------------*/

    /* set db filename */
    db_file = join_path(discofs_options.data_root, "db.sqlite");

    /* create database file if it doesn't exist  */
    int fd = open(db_file, (O_RDONLY | O_CREAT), (S_IRUSR | S_IWUSR));
    if (fd == -1)
    {
        perror(db_file);
        FATAL("couldn't open or create database file\n");
    }
    close(fd);

    /* initialize tables etc */
    db_init(db_file, discofs_options.clear);

    /* try to load filesystem features from DB */
    if (db_cfg_get_int(CFG_FS_FEATURES, &discofs_options.fs_features))
    {

        /* if loading failed, try to determine them */
        if (is_mounted(REMOTE_ROOT) && is_reachable(discofs_options.host))
        {
            if (test_fs_features(&discofs_options.fs_features))
            {
                ERROR("failed to test remote fs features\n");
                discofs_options.fs_features = 0;
            }
            /* test succeeded, store value for next time */
            else
                db_cfg_set_int(CFG_FS_FEATURES, discofs_options.fs_features);
        }
        /* nag and assume that no features available (but don't save that) */
        else
        {
            ERROR("could not determine remote fs features");
            discofs_options.fs_features = 0;
        }
    }


    /*------------------*
     * initialize stuff *
     *------------------*/
    #define INIT(name)                          \
        if (name ## _init())                    \
            FATAL("error initializing " #name)
    INIT(lock);
    INIT(sync);
    INIT(job);
    #undef INIT


    /*----------------------*
     * print options to log *
     *----------------------*/
    log_options(LOG_VERBOSE, discofs_options);


    /*-----------------*
     * run fuse_main() *
     *-----------------*/
    ret = fuse_main(args.argc, args.argv, &discofs_oper, NULL);


    /*------*
     * exit *
     *------*/

    lock_destroy();
    sync_destroy();
    job_destroy();

    /* free arguments */
    fuse_opt_free_args(&args);

    /* close database connection */
    db_destroy();


    /* end logging */
    INFO("exiting\n");
    log_destroy();


    /* return fuse_main()s return value */
    return ret;
}