예제 #1
0
/*---------------------------------------------------------------------------*/
void
rime_init(const struct mac_driver *m)
{
  queuebuf_init();
  route_init();
  packetbuf_clear();
  neighbor_init();
  announcement_init();
  rime_mac = m;
  rime_mac->set_receive_function(input);

  chameleon_init(&chameleon_bitopt);
#if ! RIME_CONF_NO_POLITE_ANNOUCEMENTS
  /* XXX This is initializes the transmission of announcements but it
   * is not currently certain where this initialization is supposed to
   * be. Also, the times are arbitrarily set for now. They should
   * either be configurable, or derived from some MAC layer property
   * (duty cycle, sleep time, or something similar). But this is OK
   * for now, and should at least get us started with experimenting
   * with announcements.
   */
  polite_announcement_init(POLITE_ANNOUNCEMENT_CHANNEL,
			   POLITE_ANNOUNCEMENT_START_TIME,
			   POLITE_ANNOUNCEMENT_MAX_TIME);
#endif /* ! RIME_CONF_NO_POLITE_ANNOUCEMENTS */
}
예제 #2
0
파일: ipv4.c 프로젝트: nak0f/openfortivpn
int ipv4_add_split_vpn_route(struct tunnel *tunnel, char *dest, char *mask,
                             char *gateway)
{
	struct rtentry *route;
	char env_var[21];

	if (tunnel->ipv4.split_routes == MAX_SPLIT_ROUTES)
		return ERR_IPV4_NO_MEM;

	sprintf(env_var, "VPN_ROUTE_DEST_%d", tunnel->ipv4.split_routes);
	setenv(env_var, dest, 0);
	sprintf(env_var, "VPN_ROUTE_MASK_%d", tunnel->ipv4.split_routes);
	setenv(env_var, mask, 0);
	if (*gateway) {
		sprintf(env_var, "VPN_ROUTE_GATEWAY_%d",
		        tunnel->ipv4.split_routes);
		setenv(env_var, gateway, 0);
	}

	route = &tunnel->ipv4.split_rt[tunnel->ipv4.split_routes++];

	route_init(route);
	route_dest(route).s_addr = inet_addr(dest);
	route_mask(route).s_addr = inet_addr(mask);
	route_gtw(route).s_addr = inet_addr(gateway);
	route->rt_flags |= RTF_GATEWAY;

	return 0;
}
예제 #3
0
파일: route.c 프로젝트: sundajiang/routes
int main(int argc, char *argv[])
{
	if (argc < 3) {
		sys_info("too few parameter, please input net-system-pid");
		return -1;
	}
	net_system_pid = atoi(argv[1]);
	if (net_system_pid <= 0) {
		sys_info("invalid parameter, exit");
		return -1;
	}
	SRC_ADDR = atoi(argv[2]);
	if (SRC_ADDR<=0 | SRC_ADDR>MAX_NODES) {
		sys_info("invalid parameter, exit");
		return -1;
	}
	if (route_init() < 0) {
		sys_info("route_init failed, exit");
		return -1;
	}
		
	
	switch(rt_cache->rp) {
	  case FHR:
	  	fhr_main();
	  	break;
/*	  case DSR:
	  	dsr_main();
	  	break;
	  case PDQR:
	  	pdqr_main();*/
	}
	
	route_exit();
}
예제 #4
0
void service_init(struct service *sv, uint16_t port, const char *key, const char *capture, const char *playback, uint32_t bitrate,
        void (*handler)(enum service_event event, const uint8_t uid[20], void *args), void *args)
{
    sv->state = STATE_IDLE;
    sv->state_handler = handler;
    sv->state_args = args;
    sv->epfd = epoll_create1(0); assert(sv->epfd > 0);
    sv->timerfd = timerfd_create(CLOCK_MONOTONIC, 0); assert(sv->timerfd > 0);
    service_pollfd(sv, sv->timerfd, (void(*)(void*))timer_handler, sv);

    const int optval = 1;
    const struct sockaddr_in addr = { AF_INET, htons(port) };
    sv->sockfd = socket(AF_INET, SOCK_DGRAM, 0); assert(sv->sockfd > 0);
    int res = setsockopt(sv->sockfd, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval)); assert(res == 0);
    if(bind(sv->sockfd, (struct sockaddr*)&addr, sizeof(addr)) != 0) { ERROR("Cannot bind socket"); abort(); }
    service_pollfd(sv, sv->sockfd, (void(*)(void*))socket_handler, sv);

    route_init(sv->table);
    sv->crypto = (struct crypto*)((void*)sv + sizeof(struct service));
    crypto_init(sv->crypto, key, sv->srcid);
    sv->media = (struct media*)((void*)sv + sizeof(struct service) + crypto_sizeof());
    media_init(sv->media, capture, playback);
    sv->packet_size = bitrate / 8 / 50;
    INFO("Media: bitrate = %u, capture = %s, playback = %s", bitrate, capture, playback);

    char tmp[128]; INFO("User ID is %.40s", hexify(sv->srcid, tmp, 20));
}
예제 #5
0
파일: slurm_route.c 프로젝트: c02y/slurm
/*
 * route_g_next_collector_backup
 *
 * RET: slurm_addr_t* - address of backup node to send messages to be aggregated.
 */
extern slurm_addr_t* route_g_next_collector_backup(void)
{
	if (route_init(NULL) != SLURM_SUCCESS)
		return NULL;

	return (*(ops.next_collector_backup))();
}
예제 #6
0
파일: slurm_route.c 프로젝트: c02y/slurm
/*
 * route_g_next_collector - return address of next collector
 *
 * IN: is_collector - bool* - flag indication if this node is a collector
 *
 * RET: slurm_addr_t* - address of node to send messages to be aggregated.
 */
extern slurm_addr_t* route_g_next_collector(bool *is_collector)
{
	if (route_init(NULL) != SLURM_SUCCESS)
		return NULL;

	return (*(ops.next_collector))(is_collector);
}
예제 #7
0
파일: slurm_route.c 프로젝트: c02y/slurm
/*
 * route_g_reconfigure - reset during reconfigure
 *
 * RET: SLURM_SUCCESS - int
 */
extern int route_g_reconfigure(void)
{
	if (route_init(NULL) != SLURM_SUCCESS)
		return SLURM_ERROR;
	debug_flags = slurm_get_debug_flags();
	tree_width = slurm_get_tree_width();

	return (*(ops.reconfigure))();
}
예제 #8
0
파일: routenif.c 프로젝트: aunali1/exopc
static void
ip_init_table() {
  ip_table->hostname[0] = 0;
  ip_table->domainname[0] = 0;
  bzero(ip_table,sizeof(ip_table_t));

  if_init();
  route_init();

}
예제 #9
0
/*---------------------------------------------------------------------------*/
void
mesh_open(struct mesh_conn *c, uint16_t channels,
	  const struct mesh_callbacks *callbacks)
{
  route_init();
  multihop_open(&c->multihop, channels, &data_callbacks);
  route_discovery_open(&c->route_discovery_conn,
		       CLOCK_SECOND * 2,
		       channels + 1,
		       &route_discovery_callbacks);
  c->cb = callbacks;
}
예제 #10
0
int main(int argc1, char *argv[])
{
     route_init(NULL, 0);
     route_register(&rt_filea_method);
     route_register(&rt_fileov_method);
     route_register(&rt_stdin_method);
     route_register(&rt_stdout_method);
     route_register(&rt_stderr_method);
     route_register(&rt_rs_method);
     if ( ! elog_init(1, "cascade test", NULL))
	  elog_die(FATAL, "didn't initialise elog\n");
     out = route_open("stdout", NULL, NULL, 0);
     err = route_open("stderr", NULL, NULL, 0);
     rs_init();

     /* run cascade with all the possible modes */
     test_cascade(CASCADE_AVG, "avg", 
		  TAB_SING, TAB_SINGINFO, TAB_SINGINFOKEY,
		  TAB_MULT, TAB_MULTINFO, TAB_MULTINFOKEY,
		  RES_AVGSING, RES_AVGSINGKEY, RES_AVGMULT, RES_AVGMULTKEY);
     test_cascade(CASCADE_MIN, "min", 
		  TAB_SING, TAB_SINGINFO, TAB_SINGINFOKEY,
		  TAB_MULT, TAB_MULTINFO, TAB_MULTINFOKEY,
		  RES_MINSING, RES_MINSINGKEY, RES_MINMULT, RES_MINMULTKEY);
     test_cascade(CASCADE_MAX, "max", 
		  TAB_SING, TAB_SINGINFO, TAB_SINGINFOKEY,
		  TAB_MULT, TAB_MULTINFO, TAB_MULTINFOKEY,
		  RES_MAXSING, RES_MAXSINGKEY, RES_MAXMULT, RES_MAXMULTKEY);
     test_cascade(CASCADE_SUM, "sum", 
		  TAB_SING, TAB_SINGINFO, TAB_SINGINFOKEY,
		  TAB_MULT, TAB_MULTINFO, TAB_MULTINFOKEY,
		  RES_SUMSING, RES_SUMSINGKEY, RES_SUMMULT, RES_SUMMULTKEY);
     test_cascade(CASCADE_FIRST, "first", 
		  TAB_SING, TAB_SINGINFO, TAB_SINGINFOKEY,
		  TAB_MULT, TAB_MULTINFO, TAB_MULTINFOKEY,
		  RES_FIRSTSING, RES_FIRSTSINGKEY, RES_FIRSTMULT, 
		  RES_FIRSTMULTKEY);
     test_cascade(CASCADE_LAST, "last", 
		  TAB_SING, TAB_SINGINFO, TAB_SINGINFOKEY,
		  TAB_MULT, TAB_MULTINFO, TAB_MULTINFOKEY,
		  RES_LASTSING, RES_LASTSINGKEY, RES_LASTMULT, 
		  RES_LASTMULTKEY);

     rs_fini();
     elog_fini();
     route_close(err);
     route_close(out);
     route_fini();
     printf("tests finished successfully\n");
     exit(0);
}
예제 #11
0
/* *****************************************************************************
 * call the external module and insert the calculated route into gpsdrive
 */
gboolean nav_get_route (gdouble slat, gdouble slon, gdouble elat, gdouble elon, gint type)
{
    navigation_struct *data;
    gint i = 0;

    if (!nav_module)
        return FALSE;

    if (mydebug > 20)
        g_print (_("Calculating route with external module '%s'\n"), g_module_name (nav_module));

    /* calculate fast car route if type value is not valid */
    if (type > NAVTYPE_N_TYPES)
        type = NAVTYPE_CAR_FAST;

    /* trying to get route from external module */
    data = calculate_route (slat, slon, elat, elon, type, NULL);

    if (data == NULL)
    {
        g_print (_("ERROR in external navigation module...\n"));
        popup_error (NULL, _("No route found!"));
        return FALSE;
    }

    /* init new gpsdrive route list and fill it from route data */
    route_init ("Calculated route", "using external module", NULL);

    while (data[i-1].number != -1)
    {
        if (mydebug > 30)
        {
            g_print ("------ Routepoint %d ------\n", data[i].number);
            g_print ("  lat: %.6f / lon: %.6f\n", data[i].lat, data[i].lon);
            g_print ("  %d : %s\n", data[i].type, data[i].name);
            g_print ("  %s\n", data[i].instruction);
        }
        if (data[i].type >= NAV_N_ELEMENTS)
            data[i].type = NAV_ROUTEPOINT;
        add_arbitrary_point_to_route
        (data[i].name, data[i].instruction, routing_types[data[i].type],
         data[i].lat, data[i].lon);
        i++;
    };

    g_free (data);

    return TRUE;
}
예제 #12
0
파일: iiab.c 프로젝트: SystemGarden/habitat
/*
 * Initialise nroute and register all the possible destinations.
 * Expect iiab_cf to be initialised and all the callbacks used in
 * the register to be available (eg rt_filea_method, etc)
 */
void iiab_init_routes() {
     route_init(iiab_cf, 0);
     route_register(&rt_none_method);
     route_register(&rt_filea_method);
     route_register(&rt_fileov_method);
     route_register(&rt_stdin_method);
     route_register(&rt_stdout_method);
     route_register(&rt_stderr_method);
     route_register(&rt_http_method);
     route_register(&rt_https_method);
     route_register(&rt_sqlrs_method);
     route_register(&rt_grs_method);
     /*route_register(&rt_brs_method);*/
     route_register(&rt_local_method);
     route_register(&rt_localmeta_method);
}
예제 #13
0
/*---------------------------------------------------------------------------*/
void
uip_over_mesh_init(uint16_t channels)
{

  PRINTF("Our address is %d.%d (%d.%d.%d.%d)\n",
	 linkaddr_node_addr.u8[0], linkaddr_node_addr.u8[1],
	 uip_hostaddr.u8[0], uip_hostaddr.u8[1],
	 uip_hostaddr.u8[2], uip_hostaddr.u8[3]);

  unicast_open(&dataconn, channels, &data_callbacks);
  route_discovery_open(&route_discovery, ROUTE_DISCOVERY_INTERVAL,
		       channels + 1, &rdc);
  trickle_open(&gateway_announce_conn, ROUTE_TRICKLE_INTERVAL, channels + 3,
	       &trickle_call);

  route_init();
  /* Set lifetime to 30 seconds for non-refreshed routes. */
  route_set_lifetime(30);
}
예제 #14
0
파일: slurm_route.c 프로젝트: c02y/slurm
/*
 * route_g_split_hostlist - logic to split an input hostlist into
 *                          a set of hostlists to forward to.
 *
 * IN: hl        - hostlist_t   - list of every node to send message to
 *                                will be empty on return which is same behavior
 *                                as similar code replaced in forward.c
 * OUT: sp_hl    - hostlist_t** - the array of hostlists that will be malloced
 * OUT: count    - int*         - the count of created hostlists
 * RET: SLURM_SUCCESS - int
 *
 * Note: created hostlist will have to be freed independently using
 *       hostlist_destroy by the caller.
 * Note: the hostlist_t array will have to be xfree.
 */
extern int route_g_split_hostlist(hostlist_t hl,
				  hostlist_t** sp_hl,
				  int* count)
{
	int rc;
	int j, nnodes, nnodex;
	char *buf;

	nnodes = nnodex = 0;
	if (route_init(NULL) != SLURM_SUCCESS)
		return SLURM_ERROR;

	if (debug_flags & DEBUG_FLAG_ROUTE) {
		/* nnodes has to be set here as the hl is empty after the
		 * split_hostlise call.  */
		nnodes = hostlist_count(hl);
		buf = hostlist_ranged_string_xmalloc(hl);
		info("ROUTE: split_hostlist: hl=%s",buf);
		xfree(buf);
	}

	rc = (*(ops.split_hostlist))(hl, sp_hl, count);
	if (debug_flags & DEBUG_FLAG_ROUTE) {
		/* Sanity check to make sure all nodes in msg list are in
		 * a child list */
		nnodex = 0;
		for (j = 0; j < *count; j++) {
			nnodex += hostlist_count((*sp_hl)[j]);
		}
		if (nnodex != nnodes) {	/* CLANG false positive */
			info("ROUTE: number of nodes in split lists (%d)"
			     " is not equal to number in input list (%d)",
			     nnodex, nnodes);
		}
	}
	return rc;
}
예제 #15
0
파일: job.c 프로젝트: SystemGarden/habitat
int main(int argc, char **argv) {
     time_t now;

     /* Initialise route, runq and job classes */
     now = time(NULL);
     route_init(NULL, 0);
     route_register(&rt_filea_method);
     route_register(&rt_fileov_method);
     route_register(&rt_stdin_method);
     route_register(&rt_stdout_method);
     route_register(&rt_stderr_method);
     if ( ! elog_init(1, "job test", NULL))
	  elog_die(FATAL, "didn't initialise elog\n");
     sig_init();
     callback_init();
     runq_init(now);
     meth_init();
     job_init();

     /* Test should fail due to incorrect method */
     elog_printf(DEBUG, "Expect a complaint! -> ");
     if (job_add(5, 5, 0, 1, "test1a1", "internal_test", "stdout", 
		  "stderr", 100, NULL, "echo \"Hello, world\"") != -1)
     {
	  elog_die(FATAL, "[1a] Shouldn't be able to add\n");
     }

     /* Single test in five seconds, never to run */
     if (job_add(5, 5, 0, 1, "test1a2", "internal_test", "stdout", 
		  "stderr", 100, "exec", "echo \"Hello, world\"") == -1)
     {
	  elog_die(FATAL, "[1a] Can't add\n");
     }
				/* Attention: some white box testing */
     itree_first(runq_event);
     if (itree_getkey(runq_event) != now+5) {
	  elog_die(FATAL, "[1a] Queued at an incorrect time\n");
     }
     job_clear();
     if (!itree_empty(runq_event) || !itree_empty(runq_tab)) {
	  elog_die(FATAL, 
		  "[1a] Trees not emptied. runq_events=%d, runq_tab=%d\n", 
		  itree_n(runq_event), itree_n(runq_tab));
     }
     now = time(NULL);
     
     /* Two tests both in five seconds, never to run */
     if (job_add(5, 5, 0, 1, "test1b1", "internal_test", "stdout",
		  "stderr", 100, "exec", "echo \"Hello, world\"") == -1)
     {
	  elog_die(FATAL, "[1b] Can't add first\n");
     }
     if (job_add(5, 5, 0, 1, "test1b2", "internal_test", "stdout",
		  "stderr", 100, "exec", "echo \"Hello, world\"") == -1)
     {
	  elog_die(FATAL, "[1b] Can't add second\n");
     }
     itree_first(runq_event);
     if (itree_getkey(runq_event) != now+5) {
	  elog_die(FATAL, "[1b] First queued at an incorrect time\n");
     }
     itree_next(runq_event);
     if (itree_getkey(runq_event) != now+5) {
	  elog_die(FATAL, "[1b] Second queued at an incorrect time\n");
     }
     job_clear();
     if (!itree_empty(runq_event) || !itree_empty(runq_tab)) {
	  elog_die(FATAL, 
		  "[1b] Trees not emptied. runq_events=%d, runq_tab=%d\n", 
		  itree_n(runq_event), itree_n(runq_tab));
     }
     now = time(NULL);

     /* Two tests one in five seconds, the other in six, never to run */
     if (job_add(6, 6, 0, 1, "test1c1", "internal_test", "stdout",
		  "stderr", 100, "exec", "echo \"Hello, world\"") == -1)
     {
	  elog_die(FATAL, "[1c] Can't add first\n");
     }
     if (job_add(now+5, 5, 0, 1, "test1c2", "internal_test", "stdout",
		  "stderr", 100, "exec", "echo \"Hello, world\"") == -1)
     {
	  elog_die(FATAL, "[1c] Can't add second\n");
     }
     itree_first(runq_event);
     if (itree_getkey(runq_event) != now+5) {
	  elog_die(FATAL, "[1c] First queued at an incorrect time\n");
     }
     itree_next(runq_event);
     if (itree_getkey(runq_event) != now+6) {
	  elog_die(FATAL, "[1c] Second queued at an incorrect time\n");
     }
     job_clear();
     if (!itree_empty(runq_event) || !itree_empty(runq_tab)) {
	  elog_die(FATAL, 
		  "[1c] Trees not emptied. runq_events=%d, runq_tab=%d\n", 
		  itree_n(runq_event), itree_n(runq_tab));
     }
     now = time(NULL);
     
     /* Continuous single test supposed to start two seconds ago, 
      * next run in three; never to run */
     if (job_add(-2, 5, 0, 0, "test1d1", "internal_test", "stdout",
		  "stderr", 100, "exec", "echo \"Hello, world\"") == -1)
     {
	  elog_die(FATAL, "[1d] Can't add\n");
     }
     itree_first(runq_event);
     if (itree_getkey(runq_event) != now+3) {
	  elog_die(FATAL, 
		  "[1d] Event queued at an incorrect time: bad=%d good=%ld\n", 
		  itree_getkey(runq_event), now+3);
     }
     job_clear();
     if (runq_nsched() > 0) {
	  elog_die(FATAL, "[1d] Still active work scheduled. runq_events=%d, "
		  "runq_tab=%d runq_nsched()=%d\n", 
		  itree_n(runq_event), itree_n(runq_tab), runq_nsched());
	  runq_dump();
     }
     now = time(NULL);
     
     /* Two continous tests, starting two seconds ago, next next run in four;
      * never to run */
     if (job_add(-2, 6, 0, 0, "test1e1", "internal_test", "stdout",
		  "stderr", 100, "exec", "echo \"Hello, world\"") == -1)
     {
	  elog_die(FATAL, "[1e] Can't add first\n");
     }
     if (job_add(-3, 5, 0, 0, "test1e2", "internal_test", "stdout",
		  "stderr", 100, "exec", "echo \"Hello, world\"") == -1)
     {
	  elog_die(FATAL, "[1e] Can't add second\n");
     }
     itree_first(runq_event);
     while (((struct runq_work*) itree_get(runq_event))->expired)
	  itree_next(runq_event);
     if (itree_getkey(runq_event) != now+2) {
	  elog_die(FATAL, "[1e] First queued at an incorrect time\n");
     }
     itree_next(runq_event);
     while (((struct runq_work*) itree_get(runq_event))->expired)
	  itree_next(runq_event);
     if (itree_getkey(runq_event) != now+4) {
	  elog_die(FATAL, "[1e] Second queued at an incorrect time\n");
     }
     job_clear();
     if (runq_nsched() > 0) {
	  elog_die(FATAL, "[1e] Still active work scheduled. runq_events=%d, "
		  "runq_tab=%d runq_nsched()=%d\n", 
		  itree_n(runq_event), itree_n(runq_tab), runq_nsched());
	  runq_dump();
     }
     now = time(NULL);
     
     /* Two 5 run jobs, scheduled to start 10 seconds ago, with periods
      * of 5 and 6 seconds; never to run */
     if (job_add(-10, 6, 0, 5, "test1f1", "internal_test", "stdout",
		  "stderr", 100, "exec", "echo \"Hello, world\"") == -1)
     {
	  elog_die(FATAL, "[1f] Can't add first\n");
     }
     if (job_add(-10, 5, 0, 5, "test1f2", "internal_test", "stdout",
		  "stderr", 100, "exec", "echo \"Hello, world\"") == -1)
     {
	  elog_die(FATAL, "[1f] Can't add second\n");
     }

     itree_first(runq_event);
     while (((struct runq_work*) itree_get(runq_event))->expired)
	  itree_next(runq_event);
     if (itree_getkey(runq_event) != now+2) {
	  elog_die(FATAL, "[1f] First queued at an incorrect time\n");
     }
     itree_next(runq_event);
     while (((struct runq_work*) itree_get(runq_event))->expired)
	  itree_next(runq_event);
     if (itree_getkey(runq_event) != now+5) {
	  elog_die(FATAL, "[1f] Second queued at an incorrect time\n");
     }
     job_clear();
     if (runq_nsched() > 0) {
	  elog_die(FATAL, "[1f] Still active work scheduled. runq_events=%d, "
		  "runq_tab=%d runq_nsched()=%d\n", 
		  itree_n(runq_event), itree_n(runq_tab), runq_nsched());
	  runq_dump();
     }
     now = time(NULL);
     
     /* Two 5 run jobs, scheduled to start 100 seconds ago, with periods
      * of 5 and 6 seconds; they should never be scheduled */
     if (job_add(-100, 6, 0, 5, "test1g1", "internal_test", "stdout",
		  "stderr", 100, "exec", "echo \"Hello, world\"") == -1)
     {
	  elog_die(FATAL, "[1g] Can't add first\n");
     }
     if (job_add(-100, 5, 0, 5, "test1g2", "internal_test", "stdout",
		  "stderr", 100, "exec", "echo \"Hello, world\"") == -1)
     {
	  elog_die(FATAL, "[1g] Can't add second\n");
     }
     if (runq_nsched() > 0) {
	  elog_die(FATAL, "[1g] Still active work scheduled. runq_events=%d, "
		  "runq_tab=%d runq_nsched()=%d\n", 
		  itree_n(runq_event), itree_n(runq_tab), runq_nsched());
	  runq_dump();
     }
     job_clear();
     now = time(NULL);

     /* Two five run tests, starting at different times in the past,
      * five runs each wittth different periods; they should both
      * run now */
     if (job_add(-24, 6, 0, 5, "test1h1", "internal_test", "stdout",
		  "stderr", 100, "exec", "echo \"Hello, world\"") == -1)
     {
	  elog_die(FATAL, "[1h] Can't add first\n");
     }
     if (job_add(-20, 5, 0, 5, "test1h2", "internal_test", "stdout",
		  "stderr", 100, "exec", "echo \"Hello, world\"") == -1)
     {
	  elog_die(FATAL, "[1h] Can't add second\n");
     }
     if (runq_nsched() != 2) {
	  elog_die(FATAL, "[1h] Two jobs should be scheduled not %d\n",
		  runq_nsched());
	  runq_dump();
     }
     sig_on();
     sleep(6);		/* let it run */
     sleep(1);		/* let it run */
     sleep(1);		/* let it run */
     sleep(1);		/* let it run */
     sig_off();
     if (runq_nsched() > 0) {
	  elog_die(FATAL, "[1h] Still active work scheduled. runq_events=%d, "
		  "runq_tab=%d runq_nsched()=%d\n", 
		  itree_n(runq_event), itree_n(runq_tab), runq_nsched());
	  runq_dump();
     }

     job_clear();

#if 0
     /* check all tables/lists are empty */
     if (!itree_empty(runq_event) || !itree_empty(runq_tab)) {
	  elog_die(FATAL, "[1i] Still entries in tables. runq_events=%d, "
		  "runq_tab=%d runq_nsched()=%d\n", 
		  itree_n(runq_event), itree_n(runq_tab), runq_nsched());
	  runq_dump();
     }
#endif

     job_fini();
     meth_fini();
     runq_fini();
     elog_fini();
     route_fini();
     callback_fini();

     printf("%s: tests finished\n", argv[0]);
     exit(0);
}
예제 #16
0
파일: ipv4.c 프로젝트: nak0f/openfortivpn
static int ipv4_set_default_routes(struct tunnel *tunnel)
{
	int ret;
	struct rtentry *def_rt = &tunnel->ipv4.def_rt;
	struct rtentry *gtw_rt = &tunnel->ipv4.gtw_rt;
	struct rtentry *ppp_rt = &tunnel->ipv4.ppp_rt;

	route_init(def_rt);
	route_init(ppp_rt);

	// Back up default route
	route_dest(def_rt).s_addr = inet_addr("0.0.0.0");
	route_mask(def_rt).s_addr = inet_addr("0.0.0.0");

	ret = ipv4_get_route(def_rt);
	if (ret != 0) {
		log_warn("Could not get current default route (%s).\n",
		         err_ipv4_str(ret));
		goto err_destroy;
	}

	// Set the default route as the route to the tunnel gateway
	memcpy(gtw_rt, def_rt, sizeof(*gtw_rt));
	route_dest(gtw_rt).s_addr = tunnel->config->gateway_ip.s_addr;
	route_mask(gtw_rt).s_addr = inet_addr("255.255.255.255");
	gtw_rt->rt_flags |= RTF_GATEWAY;
	gtw_rt->rt_metric = 0;

	log_debug("Setting route to tunnel gateway...\n");
	ret = ipv4_set_route(gtw_rt);
	if (ret == ERR_IPV4_SEE_ERRNO && errno == EEXIST)
		log_warn("Route to gateway exists already.\n");
	else if (ret != 0)
		log_warn("Could not set route to tunnel gateway (%s).\n",
		         err_ipv4_str(ret));

	// Delete the current default route
	log_debug("Deleting the current default route...\n");
	ret = ipv4_del_route(def_rt);
	if (ret != 0)
		log_warn("Could not delete the current default route (%s).\n",
		         err_ipv4_str(ret));

	// Set the new default route
	// ip route add to 0/0 dev ppp0
	route_dest(ppp_rt).s_addr = inet_addr("0.0.0.0");
	route_mask(ppp_rt).s_addr = inet_addr("0.0.0.0");
	route_gtw(ppp_rt).s_addr = inet_addr("0.0.0.0");
	strncpy(route_iface(ppp_rt), tunnel->ppp_iface, ROUTE_IFACE_LEN - 1);

	log_debug("Setting new default route...\n");
	ret = ipv4_set_route(ppp_rt);
	if (ret == ERR_IPV4_SEE_ERRNO && errno == EEXIST)
		log_warn("Default route exists already.\n");
	else if (ret != 0)
		log_warn("Could not set the new default route (%s).\n",
		         err_ipv4_str(ret));

	return 0;

err_destroy:
	route_destroy(ppp_rt);
	route_destroy(def_rt);

	return ret;
}
예제 #17
0
파일: main.c 프로젝트: justinzane/navit
int main(int argc, char **argv)
{
    GError *error = NULL;
    char *config_file = NULL;
    char *s;
    int l;


#ifndef _WIN32
    signal(SIGCHLD, sigchld);
#endif

    setenv("LC_NUMERIC","C",1);
    setlocale(LC_ALL,"");
    setlocale(LC_NUMERIC,"C");

    if (file_exists("navit.c") || file_exists("navit.o")) {
        char buffer[PATH_MAX];
        printf(_("Running from source directory\n"));
        getcwd(buffer, PATH_MAX);
        setenv("NAVIT_PREFIX", buffer, 0);
        setenv("NAVIT_LIBDIR", buffer, 0);
        setenv("NAVIT_SHAREDIR", buffer, 0);
        setenv("NAVIT_LIBPREFIX", "*/.libs/", 0);
        s=g_strdup_printf("%s/../locale", buffer);
        setenv("NAVIT_LOCALEDIR", s, 0);
        g_free(s);
    } else {
        if (!getenv("NAVIT_PREFIX")) {
            l=strlen(argv[0]);
            if (l > 10 && !strcmp(argv[0]+l-10,"/bin/navit")) {
                s=g_strdup(argv[0]);
                s[l-10]='\0';
                if (strcmp(s, PREFIX))
                    printf(_("setting '%s' to '%s'\n"), "NAVIT_PREFIX", s);
                setenv("NAVIT_PREFIX", s, 0);
                g_free(s);
            } else
                setenv("NAVIT_PREFIX", PREFIX, 0);
        }
#ifdef _WIN32
        s=g_strdup_printf("locale");
#else
        s=g_strdup_printf("%s/share/locale", getenv("NAVIT_PREFIX"));
#endif
        setenv("NAVIT_LOCALEDIR", s, 0);
        g_free(s);
#ifdef _WIN32
        s=g_strdup_printf(".");
#else
        s=g_strdup_printf("%s/share/navit", getenv("NAVIT_PREFIX"));
#endif
        setenv("NAVIT_SHAREDIR", s, 0);
        g_free(s);
        s=g_strdup_printf("%s/lib/navit", getenv("NAVIT_PREFIX"));
        setenv("NAVIT_LIBDIR", s, 0);
        g_free(s);
    }
    bindtextdomain(PACKAGE, getenv("NAVIT_LOCALEDIR"));
    bind_textdomain_codeset (PACKAGE, "UTF-8");
    textdomain(PACKAGE);

    debug_init();
#ifndef USE_PLUGINS
    extern void builtin_init(void);
    builtin_init();
#endif
#if 0
    /* handled in gui/gtk */
    gtk_set_locale();
    gtk_init(&argc, &argv);
    gdk_rgb_init();
#endif
    s = getenv("NAVIT_WID");
    if (s) {
        setenv("SDL_WINDOWID", s, 0);
    }
    route_init();
    navigation_init();
    config_file=NULL;
    if (argc > 1)
        config_file=argv[1];
    if (! config_file) {
        config_file=g_strjoin(NULL,get_home_directory(), "/.navit/navit.xml" , NULL);
        if (!file_exists(config_file)) {
            g_free(config_file);
            config_file=NULL;
        }
    }
    if (! config_file) {
        if (file_exists("navit.xml.local"))
            config_file="navit.xml.local";
    }
    if (! config_file) {
        if (file_exists("navit.xml"))
            config_file="navit.xml";
    }
    if (! config_file) {
        config_file=g_strjoin(NULL,getenv("NAVIT_SHAREDIR"), "/navit.xml.local" , NULL);
        if (!file_exists(config_file)) {
            g_free(config_file);
            config_file=NULL;
        }
    }
    if (! config_file) {
        config_file=g_strjoin(NULL,getenv("NAVIT_SHAREDIR"), "/navit.xml" , NULL);
        if (!file_exists(config_file)) {
            g_free(config_file);
            config_file=NULL;
        }
    }
    if (!config_file) {
        printf(_("No config file navit.xml, navit.xml.local found\n"));
        exit(1);
    }
    if (!config_load(config_file, &error)) {
        printf(_("Error parsing '%s': %s\n"), config_file, error->message);
        exit(1);
    } else {
        printf(_("Using '%s'\n"), config_file);
    }
    if (! navit) {
        printf(_("No instance has been created, exiting\n"));
        exit(1);
    }
    if (main_loop_gui) {
        gui_run_main_loop(main_loop_gui);
    } else {
#ifdef USE_GTK_MAIN_LOOP
        gtk_main();
#else
        loop = g_main_loop_new (NULL, TRUE);
        if (g_main_loop_is_running (loop))
        {
            g_main_loop_run (loop);
        }
#endif
    }

    return 0;
}
예제 #18
0
파일: rib.c 프로젝트: 1514louluo/lagopus
void
rib_init(void) {
  ip_addr_init();
  arp_init();
  route_init();
}
예제 #19
0
int main (int argc, char**argv)
{
	int ret = 0;
	int heartbeat_usec = 50000; //20Hz is ok by default
	uint64_t last_beat = 0;

	Log_info ("cloudvpn starting");
	Log (0, "You are using CloudVPN, which is Free software.");
	Log (0, "For more information please see the GNU GPL license,");
	Log (0, "which you should have received along with this program.");

	setup_sighandler (kill_cloudvpn);

	/*
	 * initialization
	 */

	if (!config_parse (argc, argv) ) {
		Log_error ("failed to parse config, terminating.");
		ret = 1;
		goto failed_config;
	}

	if (!config_get_int ("heartbeat", heartbeat_usec) )
		heartbeat_usec = 50000;
	Log_info ("heartbeat is set to %d usec", heartbeat_usec);

	timestamp_update(); //get initial timestamp

	status_init();
	route_init();
	squeue_init();
	network_init();

	if (poll_init() ) {
		Log_fatal ("poll initialization failed");
		ret = 2;
		goto failed_poll;
	}

	if (do_memlock() ) {
		Log_fatal ("locking process to memory failed");
		ret = 3;
		goto failed_poll;
	}

	if (comm_load() ) {
		Log_fatal ("failed to load comm data");
		ret = 4;
		goto failed_poll;
	}

	if (comm_init() ) {
		Log_fatal ("communication initialization failed");
		ret = 5;
		goto failed_comm;
	}

	if (gate_init() ) {
		Log_fatal ("gate initialization failed");
		ret = 6;
		goto failed_gate;
	}
	if (do_chroot() ) {
		Log_fatal ("chrooting failed");
		ret = 7;
		goto failed_sec;
	}

	if (do_switch_user() ) {
		Log_fatal ("user switch failed");
		ret = 8;
		goto failed_sec;
	}


	/*
	 * main loop
	 */

	Log_info ("initialization complete, entering main loop");

	last_beat = 0; //update immediately.

	while (!g_terminate) {

		timestamp_update();

		if ( (timestamp() - last_beat)
		        < (unsigned int) heartbeat_usec) {
			//poll more stuff
			poll_wait_for_event (heartbeat_usec
			                     - timestamp()
			                     + last_beat);
			//send the results
			comm_flush_data();
			gate_flush_data();
			continue;
		}

		last_beat = timestamp();

		gate_periodic_update();
		comm_periodic_update();
		route_periodic_update();

		status_try_export();
	}

	/*
	 * deinitialization
	 */

	Log_info ("shutting down");

failed_sec:

	gate_shutdown();

failed_gate:

	comm_shutdown();

failed_comm:

	if (poll_deinit() )
		Log_warn ("poll_deinit somehow failed!");

failed_poll:
failed_config:
	if (!ret) Log_info ("cloudvpn exiting gracefully");
	else Log_error ("cloudvpn exiting with code %d", ret);
	return ret;
}
예제 #20
0
파일: gpsapp.c 프로젝트: empeg/gpsapp
int main(int argc, char **argv)
{
    const char *menu[] = { "GPSapp", NULL };
    struct timeval timeout;
    int rc = 0;

    if (empeg_init() == -1)
	exit(0);

    /* set a default protocol, now we only complain when the user specifies an
     * unknown protocol in config.ini */
    serial_protocol("NMEA");

    /* For backward compatibility as the user can specify the protocol in
     * config.ini */
    if (argc > 1)
	serial_protocol(argv[1]);

    init_gpsapp();

    printf("GPS app started\n");

    vfdlib_registerFont("empeg/lib/fonts/small.bf", 0);
    vfdlib_registerFont("empeg/lib/fonts/large.bf", 1);
    h0 = vfdlib_getTextHeight(0);

    route_init();

    while (rc != -1) {
	if (empeg_waitmenu(menu) == -1)
	    break;

	serial_open();

	draw_msg("Waiting for data from GPS receiver");
	draw_display();

	while(1) {
	    rc = handle_input();
	    if (rc) break;

	    if (do_refresh)
		refresh_display();

	    /* pause a bit to avoid burning CPU cycles */
	    timeout.tv_sec = 0;
	    timeout.tv_usec = 100000;
	    select(0, NULL, NULL, NULL, &timeout);
	}
#ifndef __arm__
	break;
#endif
    }

    serial_close();
    route_init();

    draw_msg("GPS app dying...");
    draw_display();
    sleep(5);

    vfdlib_unregisterAllFonts();
    empeg_free();
    exit(0);
}
예제 #21
0
int main_real(int argc, char **argv)
{
	xmlerror *error = NULL;
	char *config_file = NULL;
	int opt;
	char *cp;
	struct attr navit;

	GList *list = NULL, *li;
	main_argc=argc;
	main_argv=argv;


#ifdef HAVE_GLIB
	event_glib_init();
#else
	_g_slice_thread_init_nomessage();
#endif
	atom_init();
	main_init(argv[0]);
	main_init_nls();
	debug_init(argv[0]);

	cp = getenv("NAVIT_LOGFILE");
	if (cp)
		debug_set_logfile(cp);
#ifdef HAVE_API_WIN32_CE
	else
		debug_set_logfile("/Storage Card/navit.log");
#endif
	file_init();
#ifndef USE_PLUGINS
	extern void builtin_init(void);
	builtin_init();
#endif
	route_init();
	navigation_init();
	tracking_init();
	search_init();
	linguistics_init();
	config_file=NULL;
	opterr=0;  //don't bomb out on errors.
	if (argc > 1) {
		/* DEVELOPPERS : don't forget to update the manpage if you modify theses options */
		while((opt = getopt(argc, argv, ":hvc:d:")) != -1) {
			switch(opt) {
			case 'h':
				print_usage();
				exit(0);
				break;
			case 'v':
				printf("%s %s\n", "navit", version);
				exit(0);
				break;
			case 'c':
				printf("config file n is set to `%s'\n", optarg);
	            config_file = optarg;
				break;
			case 'd':
				printf("TODO Verbose option is set to `%s'\n", optarg);
				break;
			case ':':
				fprintf(stderr, "navit: Error - Option `%c' needs a value\n", optopt);
				print_usage();
				exit(1);
				break;
			case '?':
				fprintf(stderr, "navit: Error - No such option: `%c'\n", optopt);
				print_usage();
				exit(1);
			}
	    }
	}
	// use 1st cmd line option that is left for the config file
	if (optind < argc) config_file = argv[optind];

    // if config file is explicitely given only look for it, otherwise try std paths
	if (config_file) list = g_list_append(list,g_strdup(config_file));
    else {
		list = g_list_append(list,g_strjoin(NULL,getenv("NAVIT_USER_DATADIR"), "/navit.xml" , NULL));
		list = g_list_append(list,g_strdup("navit.xml.local"));
		list = g_list_append(list,g_strdup("navit.xml"));
#ifdef HAVE_API_ANDROID
		list = g_list_append(list,g_strdup("/sdcard/navit.xml"));
#endif
		list = g_list_append(list,g_strjoin(NULL,getenv("NAVIT_SHAREDIR"), "/navit.xml.local" , NULL));
		list = g_list_append(list,g_strjoin(NULL,getenv("NAVIT_SHAREDIR"), "/navit.xml" , NULL));
#ifndef _WIN32
		list = g_list_append(list,g_strdup("/etc/navit/navit.xml"));
#endif
	}
	li = list;
	for (;;) {
		if (li == NULL) {
			// We have not found an existing config file from all possibilities
			dbg(0,_("No config file navit.xml, navit.xml.local found\n"));
			return 1;
		}
        // Try the next config file possibility from the list
		config_file = li->data;
		if (file_exists(config_file))
			break;
		else
			g_free(config_file);
		li = g_list_next(li);
	}

	if (!config_load(config_file, &error)) {
		dbg(0, _("Error parsing '%s': %s\n"), config_file, error ? error->message : "");
	} else {
		dbg(0, _("Using '%s'\n"), config_file);
	}
	while (li) {
		g_free(li->data);
		li = g_list_next(li);
	}
	g_list_free(list);
	if (! config_get_attr(config, attr_navit, &navit, NULL) && !config_empty_ok) {
		dbg(0, _("No instance has been created, exiting\n"));
		exit(1);
	}
	event_main_loop_run();

#ifndef HAVE_API_ANDROID
	debug_finished();
#endif
	return 0;
}
예제 #22
0
int main_real(int argc, char **argv)
{
	dbg(0, "in main loop 001 ##########################\n");


	xmlerror *error = NULL;
	char *config_file = NULL;
	int opt;
	char *cp;
	struct attr navit;

	GList *list = NULL, *li;
	main_argc = argc;
	main_argv = argv;

	//dbg(0, "in main loop 002 ##########################\n");

#ifdef HAVE_GLIB
	event_glib_init();
	//dbg(0,"in main loop 003 ##########################\n");
#else
	_g_slice_thread_init_nomessage();
	//dbg(0, "in main loop 004 ##########################\n");
#endif


	atom_init();
	main_init(argv[0]);
	main_init_nls();
	debug_init(argv[0]); // ??


	cp = getenv("NAVIT_LOGFILE");
	if (cp)
	{
		debug_set_logfile(cp);
	}
#ifdef HAVE_API_WIN32_CE
	else
	{
		debug_set_logfile("/Storage Card/navit.log");
	}
#endif




	//dbg(0, "in main loop 005 ##########################\n");
	file_init();
	//dbg(0, "in main loop 006 ##########################\n");

#ifndef USE_PLUGINS
	//dbg(0, "in main loop 007 ##########################\n");
	builtin_init();
#endif

	//dbg(0, "in main loop 008 ##########################\n");
	route_init();
	//dbg(0, "in main loop 008.1 ##########################\n");
	navigation_init();
	//dbg(0, "in main loop 008.2 ##########################\n");
	tracking_init();
	//dbg(0, "in main loop 008.3 ##########################\n");
	search_init();
	//dbg(0, "in main loop 008.4 ##########################\n");
	linguistics_init();
	//dbg(0, "in main loop 0014 ##########################\n");


	config_file = NULL;
#ifdef HAVE_GETOPT_H
	opterr=0; //don't bomb out on errors.
#endif /* _MSC_VER */
	if (argc > 1)
	{
		/* DEVELOPPERS : don't forget to update the manpage if you modify theses options */
		while ((opt = getopt(argc, argv, ":hvc:d:")) != -1)
		{
			switch (opt)
			{
				case 'h':
					print_usage();
					exit(0);
					break;
				case 'v':
					printf("%s %s\n", "navit", version);
					exit(0);
					break;
				case 'c':
					printf("config file n is set to `%s'\n", optarg);
					config_file = optarg;
					break;
				case 'd':
					printf("TODO Verbose option is set to `%s'\n", optarg);
					break;
#ifdef HAVE_GETOPT_H
					case ':':
					fprintf(stderr, "navit: Error - Option `%c' needs a value\n", optopt);
					print_usage();
					exit(1);
					break;
					case '?':
					fprintf(stderr, "navit: Error - No such option: `%c'\n", optopt);
					print_usage();
					exit(1);
#endif
			}
		}
		// use 1st cmd line option that is left for the config file
		if (optind < argc)
			config_file = argv[optind];
	}

	// if config file is explicitely given only look for it, otherwise try std paths
	//if (config_file)
	//{
	//	list = g_list_append(list, g_strdup(config_file));
	//}
	//else
	//{

		dbg(0, "navit_share_dir=%s\n", navit_share_dir);
		list = g_list_append(list, g_strjoin(NULL, navit_share_dir, "/navit.xml", NULL));
		//list = g_list_append(list, g_strdup("navit.xml"));

#ifdef HAVE_API_ANDROID
		// **disabled** // new preferred location (the new one should have priority over the legacy!)
		// **disabled** // list = g_list_append(list,g_strdup("/sdcard/zanavi/navit.xml"));
#endif

		//list = g_list_append(list, g_strjoin(NULL, getenv("NAVIT_SHAREDIR"), "/navit.xml", NULL));

#ifndef _WIN32
		//list = g_list_append(list, g_strdup("/etc/navit/navit.xml"));
#endif


	//}
	li = list;
	for (;;)
	{
		if (li == NULL)
		{
			// We have not found an existing config file from all possibilities
			dbg(0, "No config file navit.xml, navit.xml.local found\n");
			return 1;
		}
		// Try the next config file possibility from the list
		config_file = li->data;
		if (file_exists(config_file))
		{
			break;
		}
		else
		{
			g_free(config_file);
		}
		li = g_list_next(li);
	}


	// ############### load XML config file, and call all the init/new functions ################
	// ############### load XML config file, and call all the init/new functions ################
	// ############### load XML config file, and call all the init/new functions ################
	clock_t s_ = debug_measure_start();
	if (!config_load(config_file, &error))
	{
	}
	debug_mrp("load and init xmlconfig:", debug_measure_end(s_));
	// ############### load XML config file, and call all the init/new functions ################
	// ############### load XML config file, and call all the init/new functions ################
	// ############### load XML config file, and call all the init/new functions ################

	while (li)
	{
		g_free(li->data);
		li = g_list_next(li);
	}

	g_list_free(list);


	if (!config_get_attr(config, attr_navit, &navit, NULL) && !config_empty_ok)
	{
		dbg(0, "No instance has been created, exiting\n");
		exit(1);
	}

	dbg(0, "in main loop 026 ##########################\n");
	event_main_loop_run();
	dbg(0, "after main loop ##########################");

#ifndef HAVE_API_ANDROID
	debug_finished();
#endif


	return 0;
}
예제 #23
0
int
main (int argc, char **argv)
{
  int status = 0;
  int i;
  char *filename = NULL;

  progname = argv[0];

  bufsiz = resolv_number (BGPDUMP_BUFSIZ_DEFAULT, NULL);
  nroutes = resolv_number (ROUTE_LIMIT_DEFAULT, NULL);

  status = bgpdump_getopt (argc, argv);

  argc -= optind;
  argv += optind;

  if (status)
    return status;

  if (argc == 0)
    {
      printf ("specify rib files.\n");
      usage ();
      exit (-1);
    }

  if (verbose)
    {
      printf ("bufsiz = %llu\n", bufsiz);
      printf ("nroutes = %llu\n", nroutes);
    }

  /* default cmd */
  if (! brief && ! show && ! route_count && ! plen_dist && ! udiff &&
      ! lookup && ! peer_table_only && ! stat && ! compat_mode &&
      ! autsiz && ! heatmap)
    show++;

  if (stat)
    peer_stat_init ();

  char *buf;
  buf = malloc (bufsiz);
  if (! buf)
    {
      printf ("can't malloc %lluB-size buf: %s\n",
              bufsiz, strerror (errno));
      exit (-1);
    }

  peer_table_init ();

  if (peer_spec_size)
    {
      for (i = 0; i < peer_spec_size; i++)
        {
          peer_route_table[i] = route_table_create ();
          peer_route_size[i] = 0;
          peer_ptree[i] = ptree_create ();
        }
    }

  if (lookup)
    {
      route_init ();
      ptree[AF_INET] = ptree_create ();
      ptree[AF_INET6] = ptree_create ();
    }

  if (udiff)
    {
      diff_table[0] = malloc (nroutes * sizeof (struct bgp_route));
      diff_table[1] = malloc (nroutes * sizeof (struct bgp_route));
      assert (diff_table[0] && diff_table[1]);
      memset (diff_table[0], 0, nroutes * sizeof (struct bgp_route));
      memset (diff_table[1], 0, nroutes * sizeof (struct bgp_route));

      if (udiff_lookup)
        {
          diff_ptree[0] = ptree_create ();
          diff_ptree[1] = ptree_create ();
        }
    }

  /* for each rib files. */
  for (i = 0; i < argc; i++)
    {
      filename = argv[i];

      file_format_t format;
      struct access_method *method;
      void *file;
      size_t ret;

      format = get_file_format (filename);
      method = get_access_method (format);
      file = method->fopen (filename, "r");
      if (! file)
        {
          fprintf (stderr, "# could not open file: %s\n", filename);
          continue;
        }

      size_t datalen = 0;

      while (1)
        {
          ret = method->fread (buf + datalen, bufsiz - datalen, 1, file);
          if (debug)
            printf ("read: %lu bytes to buf[%lu]. total %lu bytes\n",
                    ret, datalen, ret + datalen);
          datalen += ret;

          /* end of file. */
          if (ret == 0 && method->feof (file))
            {
              if (debug)
                printf ("read: end-of-file.\n");
              break;
            }

          bgpdump_process (buf, &datalen);

          if (debug)
            printf ("process rest: %lu bytes\n", datalen);
        }

      if (datalen)
        {
          printf ("warning: %lu bytes unprocessed data remains: %s\n",
                  datalen, filename);
        }
      method->fclose (file);

      /* For each end of the processing of files. */
      if (route_count)
        {
          peer_route_count_show ();
          peer_route_count_clear ();
        }

      if (plen_dist)
        {
          peer_route_count_by_plen_show ();
          peer_route_count_by_plen_clear ();
        }
    }

  /* query_table construction. */
  if (lookup)
    {
      query_limit = 0;

      if (lookup_file)
        query_limit = query_file_count (lookup_file);

      if (lookup_addr)
        query_limit++;

      query_init ();

      if (lookup_addr)
        query_addr (lookup_addr);

      if (lookup_file)
        query_file (lookup_file);

      if (debug)
        query_list ();
    }

  /* query to route_table (ptree). */
  if (lookup)
    {
      if (benchmark)
        benchmark_start ();

      if (peer_spec_size)
        {
          for (i = 0; i < peer_spec_size; i++)
            {
              printf ("peer %d:\n", peer_spec_index[i]);
              if (verbose)
                ptree_list (peer_ptree[i]);
              ptree_query (peer_ptree[i], query_table, query_size);
            }
        }
      else
        {
          if (verbose)
            ptree_list (ptree[qaf]);
          ptree_query (ptree[qaf], query_table, query_size);
        }

      if (benchmark)
        {
          benchmark_stop ();
          benchmark_print (query_size);
        }
    }

  if (heatmap)
    {
      for (i = 0; i < peer_spec_size; i++)
        {
          heatmap_image_hilbert_gplot (i);
          heatmap_image_hilbert_data (i);
          //heatmap_image_hilbert_data_aspath_max_distance (i);
        }
    }

  if (lookup)
    {
      free (query_table);
      ptree_delete (ptree[AF_INET]);
      ptree_delete (ptree[AF_INET6]);
      route_finish ();
    }

  if (udiff)
    {
      free (diff_table[0]);
      free (diff_table[1]);

      if (lookup)
        {
          ptree_delete (diff_ptree[0]);
          ptree_delete (diff_ptree[1]);
        }
    }

  if (stat)
    {
      peer_stat_show ();
      //peer_stat_finish ();
    }

  free (buf);

  return status;
}
예제 #24
0
파일: start_real.c 프로젝트: swkim01/navit
int main_real(int argc, char * const* argv)
{
	xmlerror *error = NULL;
	char *config_file = NULL, *command=NULL, *startup_file=NULL;
	int opt;
	char *cp;
	struct attr navit, conf;

	GList *list = NULL, *li;
	main_argc=argc;
	main_argv=argv;

#ifdef HAVE_GLIB
	event_glib_init();
#else
	_g_slice_thread_init_nomessage();
#endif
	atom_init();
	main_init(argv[0]);
	navit_nls_main_init();
	debug_init(argv[0]);

	cp = getenv("NAVIT_LOGFILE");
	if (cp) {
		debug_set_logfile(cp);
	}
#ifdef HAVE_API_WIN32_CE
	else {	
		debug_set_logfile("/Storage Card/navit.log");
	}
#endif
	file_init();
#ifndef USE_PLUGINS
	builtin_init();
#endif
	route_init();
	navigation_init();
	tracking_init();
	search_init();
	linguistics_init();
	geom_init();
	config_file=NULL;
#ifdef HAVE_GETOPT_H
	opterr=0;  //don't bomb out on errors.
#endif /* _MSC_VER */
	/* ingore iphone command line argument */
	if (argc == 2 && !strcmp(argv[1],"-RegisterForSystemEvents"))
		argc=1;
	if (argc > 1) {
		/* Don't forget to update the manpage if you modify theses options */
		while((opt = getopt(argc, argv, ":hvc:d:e:s:")) != -1) {
			switch(opt) {
			case 'h':
				print_usage();
				exit(0);
				break;
			case 'v':
				printf("%s %s\n", "navit", version);
				exit(0);
				break;
			case 'c':
				printf("config file n is set to `%s'\n", optarg);
	            config_file = optarg;
				break;
			case 'd':
				debug_set_global_level(atoi(optarg), 1);
				break;
			case 'e':
				command=optarg;
				break;
			case 's':
				startup_file=optarg;
				break;
#ifdef HAVE_GETOPT_H
			case ':':
				fprintf(stderr, "navit: Error - Option `%c' needs a value\n", optopt);
				print_usage();
				exit(2);
				break;
			case '?':
				fprintf(stderr, "navit: Error - No such option: `%c'\n", optopt);
				print_usage();
				exit(3);
#endif
			}
	  }
		// use 1st cmd line option that is left for the config file
		if (optind < argc) config_file = argv[optind];
	}

	// if config file is explicitely given only look for it, otherwise try std paths
	if (config_file) {
		list = g_list_append(list,g_strdup(config_file));
	} else {
		list = g_list_append(list,g_strjoin(NULL,getenv("NAVIT_USER_DATADIR"), "/navit.xml" , NULL));
		list = g_list_append(list,g_strdup("navit.xml.local"));
		list = g_list_append(list,g_strdup("navit.xml"));
#ifdef HAVE_API_ANDROID
		// new preferred location (the new one should have priority over the legacy!)
		list = g_list_append(list,g_strdup("/sdcard/navit/navit.xml"));
		// legacy location, still supported
		list = g_list_append(list,g_strdup("/sdcard/navit.xml"));
#endif
		list = g_list_append(list,g_strjoin(NULL,getenv("NAVIT_SHAREDIR"), "/navit.xml.local" , NULL));
		list = g_list_append(list,g_strjoin(NULL,getenv("NAVIT_SHAREDIR"), "/navit.xml" , NULL));
#ifndef _WIN32
		list = g_list_append(list,g_strdup("/etc/navit/navit.xml"));
#endif
	}
	li = list;
	for (;;) {
		if (li == NULL) {
			// We have not found an existing config file from all possibilities
			dbg(0, "%s", _("No config file navit.xml, navit.xml.local found\n"));
			return 4;
		}
        // Try the next config file possibility from the list
		config_file = li->data;
		dbg(1,"trying %s\n",config_file);
		if (file_exists(config_file)) {
			break;
		}
		g_free(config_file);
		li = g_list_next(li);
	}

	dbg(0,"Loading %s\n",config_file);
	if (!config_load(config_file, &error)) {
		dbg(0, _("Error parsing config file '%s': %s\n"), config_file, error ? error->message : "");
	} else {
		dbg(0, _("Using config file '%s'\n"), config_file);
	}
	while (li) {
		g_free(li->data);
		li = g_list_next(li);
	}
	g_list_free(list);
	if (! config_get_attr(config, attr_navit, &navit, NULL) && !config_empty_ok) {
		dbg(0, "%s", _("Internal initialization failed, exiting. Check previous error messages.\n"));
		exit(5);
	}
	conf.type=attr_config;
	conf.u.config=config;
	if (startup_file) {
		FILE *f=fopen(startup_file,"r");
		if (f) {
			char buffer[4096];
			while(fgets(buffer, sizeof(buffer), f)) {
				command_evaluate(&conf, buffer);
			}
		}
	}
	if (command) {
		command_evaluate(&conf, command);
	}
	event_main_loop_run();

	/* TODO: Android actually has no event loop, so we can't free all allocated resources here. Have to find better place to
	 *  free all allocations on program exit. And don't forget to free all the stuff allocated in the code above.
	 */
#ifndef HAVE_API_ANDROID
	linguistics_free();
	debug_finished();
#endif
	return 0;
}
예제 #25
0
파일: elog.c 프로젝트: SystemGarden/habitat
int main(int argc, char **argv) {
     ROUTE err, saveroute;
     int i;
     TABLE tab;
     char *str;

     route_init(NULL, 0);
     route_register(&rt_filea_method);
     route_register(&rt_fileov_method);
     route_register(&rt_stdin_method);
     route_register(&rt_stdout_method);
     route_register(&rt_stderr_method);
     route_register(&rt_rs_method);
     rs_init();
     if ( ! elog_init(1, argv[0], NULL))
	  elog_die(FATAL, "Didn't initialise elog\n");
     err = route_open("stderr", NULL, NULL, 0);

     /* first lot of messages sent to the default places */
     elog_send(INFO, "This is an eventlog test");
     elog_send(INFO, NULL);
     elog_send(INFO, "");
     elog_send(INFO, "Event!!");
     elog_send(DEBUG, "Event!!");
     elog_send(WARNING, "Event!!");
     elog_send(ERROR, "Event!!");
     elog_send(INFO, "Event!!");

     /* change origin */
     elog_setorigin("etest");
     elog_send(INFO, "test of set origin");

     /* set one new purl route */
     elog_setsevpurl(DEBUG, FILE1);
     elog_send(INFO, "on screen");
     elog_send(DEBUG, "in file");
     elog_send(WARNING, "on screen");

     /* set second identical purl route to reuse the previous one */
     elog_setsevpurl(ERROR, FILE1);
     if (elog_opendest[DEBUG].route != 
	 elog_opendest[ERROR].route)
	  route_die(err, "[13] didnt reuse already open DEBUG route\n");
     elog_send(ERROR, "in file");

     /* set identical below purl route */
     if ( !elog_setbelowpurl(INFO, FILE1))
	  route_die(err, "[14] unable to setbelowpurl() file\n");
     if (elog_opendest[DEBUG].route != 
	 elog_opendest[ERROR].route ||
	 elog_opendest[INFO].route != 
	 elog_opendest[ERROR].route)
	  route_die(err, "[14] didnt reuse already open ERROR route\n");
     elog_send(DEBUG, "in file");
     elog_send(INFO, "in file");
     elog_send(WARNING, "on screen");
     elog_send(ERROR, "in file");
     elog_send(FATAL, "on screen");

     /* set identical above purl route */
     if ( !elog_setabovepurl(ERROR, FILE1))
	  route_die(err, "[19] unable to setabovepurl() file\n");
     if (elog_opendest[ERROR].route != 
	 elog_opendest[INFO].route ||
	 elog_opendest[FATAL].route != 
	 elog_opendest[INFO].route)
	  route_die(err, "[19] didnt reuse already open INFO route\n");
     elog_send(DEBUG, "in file");
     elog_send(INFO, "in file");
     elog_send(WARNING, "on screen");
     elog_send(ERROR, "in file");
     elog_send(FATAL, "in file");

     /* set identical all purl route */
     saveroute = elog_opendest[DEBUG].route;
     if ( !elog_setallpurl(FILE1))
	  route_die(err, "[24] unable to setallpurl() file\n");
     for (i=0; i < ELOG_NSEVERITIES; i++)
	  if (elog_opendest[i].route != saveroute)
	       route_die(err, "[24] didnt reuse already open %s route\n",
			 elog_sevstring[i]);
     elog_send(DEBUG, "in file");
     elog_send(INFO, "in file");
     elog_send(WARNING, "in file");
     elog_send(ERROR, "in file");
     elog_send(FATAL, "in file");

     /* set one different purl - timestore that we currently have to set up
      * ourselves */
     saveroute = route_open(RS1, "event log test", NULL, 10);
     if ( ! saveroute)
	  route_die(err, "[29] unable to create/open timestore\n");
     route_close(saveroute);
     if ( ! elog_setsevpurl(INFO, RS1))
	  route_die(err, "[29] unable to setsevpurl() timestore\n");
     if (elog_opendest[INFO].route == 
	 elog_opendest[WARNING].route)
	  route_die(err, "[29] different route same as WARNING\n");
     elog_send(DEBUG, "in file");
     elog_send(INFO, "in timestore");
     elog_send(WARNING, "in file");
     elog_send(ERROR, "in file");
     elog_send(FATAL, "in file");

     /* set one different route */

#if 0
     elog_send(INFO, "");
     elog_send(INFO, "Event!!");
     elog_send(DEBUG, "Event!!");
     elog_send(WARNING, "Event!!");
     elog_send(ERROR, "Event!!");
     elog_send(INFO, "Event!!");

     elog_send(INFO, "Event!!");
     elog_send(INFO, "Event!!");
     elog_send(INFO, "Event!!");
     elog_send(INFO, "Event!!");
     elog_send(INFO, "Event!!");
     elog_send(INFO, "Event!!");
     elog_send(INFO, "Event!!");
#endif

     /* change format */
     elog_setsevroute(WARNING, err);
     elog_setformat(WARNING, "%s %s");
     elog_send(WARNING, "still works??");

     /* safe logging */
     elog_safeprintf(INFO, "This is an eventlog test 35");
     elog_safeprintf(INFO, NULL);
     elog_safeprintf(INFO, "");
     elog_safeprintf(INFO, "Event!! 38");
     elog_safeprintf(DEBUG, "Event!! 39");
     elog_safeprintf(WARNING, "Event!! 40");
     elog_safeprintf(ERROR, "Event!! 41");
     elog_safeprintf(INFO, "Event!!");

     /* print the status out */
     tab = elog_getstatus();
     str = table_printcols_a(tab, elog_colnames);
     printf("%s\n", str);
     nfree(str);
     table_destroy(tab);

     rs_fini();
     elog_fini();
     route_close(err);
     route_fini();

     exit(0);
}
예제 #26
0
int main(int argc, char **argv)
{
	int			ret = EX_OK;
	int			i;
	struct group		*grgid;
	struct passwd		*pwuid;
	timer_t			timerid_mld, timerid_pim;
	struct pollfd		fds[4];
	nfds_t			nfds = 0;
	struct sockaddr_storage	from, to;
	socklen_t		addrlen = sizeof(struct sockaddr_storage);
	unsigned int		from_ifindex;
	char			*buf;

	ret = parse_args(argc, argv);
	if (ret)
		return -ret;

	if (getuid()) {
		fprintf(stderr, "need to run as root\n");
		return EX_NOPERM;
	}

	if (!nofork) {
		pid_t pid = fork();

		if (pid < 0) {
			perror("fork()");
			return EX_OSERR;
		} else if (pid > 0)
			return EX_OK;

		if (setsid() < 0) {
			perror("setsid()");
			return EX_OSERR;
		}

		if (chdir("/") < 0) {
			perror("chdir(\"/\")");
			return EX_OSERR;
		}

		openlog(basename(argv[0]), LOG_PID, LOG_DAEMON);
	} else
		openlog(basename(argv[0]), LOG_PID | LOG_PERROR, LOG_DAEMON);
	setlogmask(LOG_UPTO(debug));

	logger(LOG_NOTICE, 0, "started");

	errno = 0;
	mroute4 = socket(AF_INET, SOCK_RAW, IPPROTO_IGMP);
	if (mroute4 >= 0) {
		if (pktinfo(mroute4) < 0) {
			close(mroute4);
			mroute4 = -1;
		} else {
			pim4 = pim_init(mroute4);
			if (pim4 < 0) {
				close(mroute4);
				mroute4 = -1;
			} else {
				add_poll(fds, &nfds, mroute4);
				add_poll(fds, &nfds, pim4);
			}
		}
	}
	if (mroute4 < 0)
		logger(LOG_WARNING, errno, "no IPv4 support");
	errno = 0;
	mroute6 = socket(AF_INET6, SOCK_RAW, IPPROTO_ICMPV6);
	if (mroute6 >= 0) {
		if (pktinfo(mroute6) < 0) {
			close(mroute6);
			mroute6 = -1;
		} else {
			pim6 = pim_init(mroute6);
			if (pim6 < 0) {
				close(mroute6);
				mroute6 = -1;
			} else {
				add_poll(fds, &nfds, mroute6);
				add_poll(fds, &nfds, pim6);
			}
		}
	}
	if (mroute6 < 0)
		logger(LOG_WARNING, errno, "no IPv6 support");

	if (mroute4 < 0 && mroute6 < 0) {
		logger(LOG_ERR, 0, "multicast routing unavailable");
		ret = -EX_OSERR;
		goto exit;
	}

	ret = route_init();
	if (ret)
		goto mroute;

	errno = 0;
	grgid = getgrnam(gid);
	if (grgid) {
		if (setgid(grgid->gr_gid))
			logger(LOG_WARNING, errno, "unable to drop group privileges");
	} else
		logger(LOG_WARNING, errno, "unable to find group '%s' to drop privileges to", gid);
	errno = 0;
	pwuid = getpwnam(uid);
	if (pwuid) {
		if (setuid(pwuid->pw_uid))
			logger(LOG_WARNING, errno, "unable to drop user privileges");
	} else
		logger(LOG_WARNING, errno, "unable to find user '%s' to drop privileges to", uid);

	ret = signals(&sig_handler);
	if (ret)
		goto route;

	ret = prime_timers(&timerid_mld, &timerid_pim);
	if (ret)
		goto signal;

	buf = malloc(SOCK_BUFLEN);
	if (buf == NULL) {
		logger(LOG_ERR, 0, "malloc()");
		ret = -EX_OSERR;
		goto timer;
	}

	while (running) {
		ret = poll(fds, nfds, -1);
		if (ret == -1) {
			if (errno == EINTR)
				continue;

			logger(LOG_ERR, errno, "poll()");
			ret = -EX_OSERR;
			running = 0;
			continue;
		}

		for (i = 0; i < nfds; i++) {
			/* TODO handle errors */
			assert(!(fds[i].revents & (POLLERR | POLLHUP)));

			/* either a non-event or there is something to read */
			assert(!fds[i].revents || fds[i].revents & POLLIN);

			if (!fds[i].revents)
				continue;

			if (fds[i].revents & POLLIN) {
				ret = recvfromto(fds[i].fd, buf, SOCK_BUFLEN, 0,
						(struct sockaddr *)&from,
						(struct sockaddr *)&to,
						&addrlen, &from_ifindex);
				if (ret == -1)
					continue;

				if (fds[i].fd == pim4 || fds[i].fd == pim6)
					pim_recv(fds[i].fd, buf, ret,
							&from, &to, addrlen,
							from_ifindex);
				else
					mld_recv(fds[i].fd, buf, ret,
							&from, &to, addrlen,
							from_ifindex);
			}
		}
	}

	free(buf);

timer:
	timer_delete(timerid_mld);
	timer_delete(timerid_pim);
signal:
	signals(SIG_IGN);
route:
	route_shutdown();
mroute:
	if (mroute4 > 0) {
		close(pim4);
		pim_shutdown(mroute4);
	}
	if (mroute6 > 0) {
		close(pim6);
		pim_shutdown(mroute6);
	}
exit:
	logger(LOG_NOTICE, 0, "exiting");

	closelog();

	assert(ret <= 0);

	return -ret;
}
예제 #27
0
파일: tpg_main.c 프로젝트: Rao-DS/warp17
/*****************************************************************************
 * main()
 ****************************************************************************/
int main(int argc, char **argv)
{
    global_config_t *cfg;
    int              ret;

    /*
     * Initialize DPDK infrastructure before we do anything else
     */
    ret = rte_eal_init(argc, argv);
    if (ret < 0)
        rte_panic("Cannot init EAL\n");

    /*
     * Initialize RTE timer library
     */
    rte_timer_subsystem_init();
    /*
     * Precalculate the number of cycles per us so we don't do it everytime.
     */
    cycles_per_us = (rte_get_timer_hz() / 1000000);

    /*
     * Return value above to be used to scan app specific options
     */
    argc -= ret;
    argv += ret;

    /*
     * General checks
     */
    if (rte_lcore_count() < 3)
        TPG_ERROR_EXIT(EXIT_FAILURE, "ERROR: %s\n",
                       "WARP17 needs at least three cores!");
    /* We only support at most 64 cores right now (to make parsing easier). */
    if (rte_lcore_count() > (sizeof(uint64_t) * 8))
        TPG_ERROR_EXIT(EXIT_FAILURE,
                       "ERROR: WARP17 supports at most %"PRIu32" cores!\n",
                       (uint32_t)sizeof(uint64_t) * 8);
    if (rte_eth_dev_count() > TPG_ETH_DEV_MAX)
        TPG_ERROR_EXIT(EXIT_FAILURE,
                       "ERROR: WARP17 works with at most %u ports!\n",
                       TPG_ETH_DEV_MAX);

    /*
     * Initialize various submodules
     */

    if (!cli_init())
        TPG_ERROR_EXIT(EXIT_FAILURE, "ERROR: %s!\n",
                       "Failed initializing the command line interface");

    if (!rpc_init())
        TPG_ERROR_EXIT(EXIT_FAILURE, "ERROR: %s!\n",
                       "Failed initializing the RPC server");

    if (!cfg_init())
        TPG_ERROR_EXIT(EXIT_FAILURE, "ERROR: %s\n",
                       "Failed initializing default configuration!\n");

    if (!cfg_handle_command_line(argc, argv))
        exit(EXIT_FAILURE); /* Error reporting is handled by the function itself */

    if (!trace_init())
        TPG_ERROR_EXIT(EXIT_FAILURE, "ERROR: %s!\n",
                       "Failed initializing the tracing module");

    if (!trace_filter_init())
        TPG_ERROR_EXIT(EXIT_FAILURE, "ERROR: %s!\n",
                       "Failed initializing the trace filter module");

    if (!mem_init())
        TPG_ERROR_EXIT(EXIT_FAILURE, "ERROR: %s!\n",
                       "Failed allocating required mbufs");

    /* WARNING: Careful when adding code above this point. Up until ports are
     * initialized DPDK can't know that there might be ring interfaces that
     * still need to be created. Therefore any call to rte_eth_dev_count()
     * doesn't include them.
     */
    if (!port_init())
        TPG_ERROR_EXIT(EXIT_FAILURE, "ERROR: %s!\n",
                       "Failed initializing the Ethernets ports");

    if (!msg_sys_init())
        TPG_ERROR_EXIT(EXIT_FAILURE, "ERROR: %s!\n",
                       "Failed initializing the message queues");

    if (!test_mgmt_init())
        TPG_ERROR_EXIT(EXIT_FAILURE, "ERROR: %s!\n",
                       "Failed initializing test mgmt");

    if (!test_init())
        TPG_ERROR_EXIT(EXIT_FAILURE, "ERROR: %s!\n",
                       "Failed initializing tests");

    if (!eth_init())
        TPG_ERROR_EXIT(EXIT_FAILURE, "ERROR: %s!\n",
                       "Failed initializing the Ethernets pkt handler");

    if (!arp_init())
        TPG_ERROR_EXIT(EXIT_FAILURE, "ERROR: %s!\n",
                       "Failed initializing the ARP pkt handler");

    if (!route_init())
        TPG_ERROR_EXIT(EXIT_FAILURE, "ERROR: %s!\n",
                       "Failed initializing the ROUTE module");

    if (!ipv4_init())
        TPG_ERROR_EXIT(EXIT_FAILURE, "ERROR: %s!\n",
                       "Failed initializing the IPv4 pkt handler");

    if (!tcp_init())
        TPG_ERROR_EXIT(EXIT_FAILURE, "ERROR: %s!\n",
                       "Failed initializing the TCP pkt handler");

    if (!udp_init())
        TPG_ERROR_EXIT(EXIT_FAILURE, "ERROR: %s!\n",
                       "Failed initializing the UDP pkt handler");

    if (!tlkp_init())
        TPG_ERROR_EXIT(EXIT_FAILURE, "ERROR: %s!\n",
                       "Failed initializing the Session lookup engine");

    if (!tlkp_tcp_init())
        TPG_ERROR_EXIT(EXIT_FAILURE, "ERROR: %s!\n",
                       "Failed initializing the TCP lookup engine");

    if (!tlkp_udp_init())
        TPG_ERROR_EXIT(EXIT_FAILURE, "ERROR: %s!\n",
                       "Failed initializing the UDP lookup engine");

    if (!tsm_init())
        TPG_ERROR_EXIT(EXIT_FAILURE, "ERROR: %s!\n",
                       "Failed initializing the TSM module");

    if (!timer_init())
        TPG_ERROR_EXIT(EXIT_FAILURE, "ERROR: %s!\n",
                       "Failed initializing the TCP timers module");

    if (!pkt_loop_init())
        TPG_ERROR_EXIT(EXIT_FAILURE, "ERROR: %s!\n",
                       "Failed initializing the pkt loop");

    if (!raw_init())
        TPG_ERROR_EXIT(EXIT_FAILURE, "ERROR: %s!\n",
                       "Failed initializing the RAW Application module");

    if (!http_init())
        TPG_ERROR_EXIT(EXIT_FAILURE, "ERROR: %s!\n",
                       "Failed initializing the RAW Application module");

    start_cores();

    /*
     * Process startup command file, if any.
     */
    cfg = cfg_get_config();
    if (cfg != NULL && cfg->gcfg_cmd_file) {
        if (!cli_run_input_file(cfg->gcfg_cmd_file))
            TPG_ERROR_EXIT(EXIT_FAILURE, "Failed to run command file: %s!\n",
                           cfg->gcfg_cmd_file);
    }

    /*
     * Process CLI commands, and other house keeping tasks...
     */
    cli_interact();
    tpg_exit = true;

    /*
     * Exit!!!
     */
    rte_eal_mp_wait_lcore();

    /*
     * Destroy the CLI.
     */
    cli_exit();

    /*
     * Destroy the mgmt RPC server.
     */
    rpc_destroy();
    return 0;
}