Ejemplo n.º 1
0
static void init_performance(void) {
#ifdef CONFIG_HIP_PERFORMANCE
    HIP_DEBUG("Creating perf set\n");
    set = hip_perf_create(1);
    check_and_create_dir("results", HIP_DIR_MODE);
    hip_perf_set_name(set, PERF_BLACKBOX, "results/PERF_BLACKBOX.csv");
    hip_perf_open(set);
#endif
}
Ejemplo n.º 2
0
static int create_path(char *path, int has_filename)
{
    char *sep = find_reverse_path_sep(path);

    /* if there's still a separator, and it's not the root, nuke it and recurse */
    if (sep && sep > path && !is_pathsep(sep[-1]))
    {
        *sep = 0;
        if (!create_path(path, 0))
            return 0;
        *sep = '/';
    }

    /* if we have a filename, we're done */
    if (has_filename)
        return 1;

    /* create the path */
    return check_and_create_dir(path) ? FALSE : TRUE;
}
Ejemplo n.º 3
0
void
init_netsukuku(char **argv)
{
	xsrand();

	if (geteuid())
		fatal("Need root privileges");

	destroy_netsukuku_mutex = pid_saved = 0;
	sigterm_timestamp = sighup_timestamp = sigalrm_timestamp = 0;
	setzero(&me, sizeof(struct current_globals));

	if (is_ntkd_already_running())
		fatal("ntkd is already running. If it is not, remove \"%s\"",
			  server_opt.pid_file);
	else
		save_pid();

	my_family = server_opt.family;
	restricted_mode = server_opt.restricted;
	restricted_class =
		server_opt.restricted_class ? RESTRICTED_172 : RESTRICTED_10;

	/* Check if the DATA_DIR exists, if not create it */
	if (check_and_create_dir(DATA_DIR))
		fatal("Cannot access to the %s directory. Exiting.", DATA_DIR);

	/*
	 * Device initialization
	 */
	if (if_init_all(server_opt.ifs, server_opt.ifs_n,
					me.cur_ifs, &me.cur_ifs_n) < 0)
		fatal("Cannot initialize any network interfaces");

	/*
	 * ANDNA init
	 */
	if (!server_opt.disable_andna)
		andna_init();

	/*
	 * Initialize the Internet gateway stuff
	 */
	if (server_opt.my_upload_bw && server_opt.my_dnload_bw)
		me.my_bandwidth = bandwidth_in_8bit((server_opt.my_upload_bw +
											 server_opt.my_dnload_bw) / 2);
	init_internet_gateway_search();

	pkts_init(me.cur_ifs, me.cur_ifs_n, 0);
	qspn_init(FAMILY_LVLS);

	me.cur_erc = e_rnode_init(&me.cur_erc_counter);

	/* Radar init */
	rq_wait_idx_init(rq_wait_idx);
	first_init_radar();
	total_radars = 0;

	ntk_load_maps();

#if 0
	/* TODO: activate and test it !! */
	debug(DBG_NORMAL, "ACPT: Initializing the accept_tbl: \n"
		  "	max_connections: %d,\n"
		  "	max_accepts_per_host: %d,\n"
		  "	max_accept_per_host_time: %d",
		  server_opt.max_connections,
		  server_opt.max_accepts_per_host,
		  server_opt.max_accepts_per_host_time);
	init_accept_tbl(server_opt.max_connections,
					server_opt.max_accepts_per_host,
					server_opt.max_accepts_per_host_time);
#endif

	if (restricted_mode)
		loginfo("NetsukukuD is in restricted mode. "
				"Restricted class: %s",
				server_opt.
				restricted_class ? RESTRICTED_172_STR : RESTRICTED_10_STR);

	hook_init();
	rehook_init();

	me.uptime = time(0);
}
Ejemplo n.º 4
0
info_lib::info_lib(char** set_name_array, char** list_name_array,
                   char* info_lib_dir, char* selected_base_name, 
		   char* infoLibName, int des) :
set_nm_list(set_name_array), list_nm_list(list_name_array),
f_bad_base_array_size(0), f_bad_info_bases(0), 
f_bad_info_base_names(0), f_bad_info_base_paths(0), f_descriptor(des)

{
//debug(cerr, info_lib_dir);
//debug(cerr, infoLibName);

   f_obj_dict = new object_dict;

   if ( info_lib_dir == 0 ) {
      throw(stringException("NULL info lib path"));
   }

   if ( check_and_create_dir(info_lib_dir) == false )
      throw(stringException(
        form("infolib %s does not exist or can't be created", info_lib_dir)
                           )
           );

   strcpy(info_lib_path, info_lib_dir);
   strcpy(info_lib_name, infoLibName);

   fstream *map_in = 0;

   if ( exist_file(MAP_FILE_8_3, info_lib_dir) == true ) {

      map_in = new fstream(form("%s/%s", info_lib_dir, MAP_FILE_8_3), ios::in);

      g_mode_8_3 = 1;

      if ( !map_in -> getline(info_lib_name, PATHSIZ, '\t') ||
           !map_in -> getline(info_lib_uid, UIDSIZ, '\n')
         )
      {
         throw(stringException(
           form("infolib %s does not have correct name-id entry", info_lib_dir)
                              )
              );
      }
   } else
   if ( exist_file(MAP_FILE, info_lib_dir) == true )
      map_in = new fstream(form("%s/%s", info_lib_dir, MAP_FILE), ios::in);
   else {
      return;
   }

   char base_name[PATHSIZ];
   char base_desc[PATHSIZ];
   char base_uid[UIDSIZ];
   char base_locale[PATHSIZ];
   char db_path_name[PATHSIZ];

   int major_mm_version = 0;
   int minor_mm_version = 0;


   while ( map_in -> getline(base_name, PATHSIZ, '\t') ) {

      map_in -> getline(base_desc, PATHSIZ, '\t');

      if ( g_mode_8_3 == 1 ) {
         map_in -> getline(base_uid, PATHSIZ, '\t');
	 map_in -> getline(base_locale, PATHSIZ, '\t');
      }
      else
         base_uid[0] = 0;

      (*map_in) >> major_mm_version >> minor_mm_version;

      map_in -> get();

      if ( base_name[0] != CommentChar ) {

//debug(cerr, base_name);
//debug(cerr, base_desc);
//fprintf(stderr, "base_name = %s\n", base_name);

	 char* mmdb_lang = getenv("MMDB_LANG");
#ifdef MMDB_LANG_DEBUG
	 cerr << "base_locale=" << base_locale << endl;
	 if (mmdb_lang)
	   cerr << "mmdb_lang=" << mmdb_lang << endl;
#endif

         if ((selected_base_name == 0 ||
	      strcmp(selected_base_name, base_name) == 0) &&
	     (mmdb_lang == NULL ||
	      strcmp(mmdb_lang, base_locale) == 0 ||
	      strcmp("C.ISO-8859-1", base_locale) == 0))
         {

            strcpy(db_path_name, 
                   form("%s/%s", info_lib_dir, base_name)
                  );
 
            mm_version mmv_code(MAJOR, MINOR);
            mm_version mmv_base_data(2, 1);
            mm_version mmv_data(major_mm_version, minor_mm_version);

///////////////////////////////////////////////
// Hardcoded knowledge of discontinuation of 
// backward compatibility
///////////////////////////////////////////////
            if ( mmv_data < mmv_base_data ||
                 mmv_data == mmv_base_data || 
	         mmv_code < mmv_data
               ) 
	    {


               if ( f_bad_base_array_size == 0 ||
                    f_bad_base_array_size <= f_bad_info_bases 
                  ) 
               {
                 
                 if ( f_bad_base_array_size == 0 ) {
                    f_bad_base_array_size = 10;
                    f_bad_info_base_names = new charPtr[f_bad_base_array_size];
                    f_bad_info_base_paths = new charPtr[f_bad_base_array_size];

                    for (int i=0; i<f_bad_base_array_size; i++) {
                      f_bad_info_base_paths[i] = 0;
                      f_bad_info_base_names[i] = 0;
                    }

                 } else {
                    char** x = new charPtr[2*f_bad_base_array_size];
                    char** y = new charPtr[2*f_bad_base_array_size];

                    for (int i=0; i<2*f_bad_base_array_size; i++) {
                      x[i] = 0;
                      y[i] = 0;
                    }

                    memcpy(x, f_bad_info_base_names, sizeof(charPtr)*f_bad_base_array_size);
                    memcpy(y, f_bad_info_base_paths, sizeof(charPtr)*f_bad_base_array_size);
                    f_bad_base_array_size *= 2;

                    delete f_bad_info_base_names;
                    delete f_bad_info_base_paths;

                    f_bad_info_base_names = x;
                    f_bad_info_base_paths = y;
                     
                 }


               } 


               f_bad_info_base_paths[f_bad_info_bases] = strdup(info_lib_dir);
               f_bad_info_base_names[f_bad_info_bases] = strdup(base_name);

               f_bad_info_bases++;

               MESSAGE(cerr, "Data and code version mismatch");

               MESSAGE(cerr, form("Data version: v%d.%d",
                    major_mm_version, minor_mm_version
                           ));

               MESSAGE(cerr, form("Code version: v%d.%d", 
               		MAJOR, MINOR
    			   ));

               MESSAGE(cerr, form("infobase %s is not available.", base_name));

               continue;
            }

//reset_total();
            _init_info_base(db_path_name, base_name, base_desc, base_uid, base_locale,
		            mm_version(major_mm_version, minor_mm_version));
//report_total();
         }
      }

   }
   map_in -> close();
   delete map_in ;
}
Ejemplo n.º 5
0
Boolean 
info_lib::define_info_base( char* base_name, char* base_desc, 
                            char* spec_file_path
                          )
{
//MESSAGE(cerr, "define_info_base()");
//debug(cerr, base_name);
//debug(cerr, base_desc);
//debug(cerr, spec_file_path);

   char new_db_path[PATHSIZ]; 
   char f_name[PATHSIZ]; 
   char base_uid[UIDSIZ]; 

   strcpy(new_db_path, form("%s/%s", info_lib_path, base_name));

   strcpy(base_uid, unique_id());

   g_mode_8_3 = 1;

   info_base* base = get_info_base(base_name) ;

/* no checking here. DDK assures unique base name case
   if ( base == 0 ) {
*/
      
//////////////////////////
// check info base path
//////////////////////////
      if ( check_and_create_dir(new_db_path) == false ) {
         throw(stringException(form("bad base bath %s", new_db_path)));
      }

//////////////////////////
// remove any old files 
//////////////////////////

      strcpy(f_name, form("%s.%s", base_name, DATA_FILE_SUFFIX));
      if ( exist_file(f_name, new_db_path) == true )
         del_file(f_name, new_db_path);

      strcpy(f_name, form("%s.%s", base_name, INDEX_FILE_SUFFIX));
      if ( exist_file(f_name, new_db_path) == true )
         del_file(f_name, new_db_path);

      strcpy(f_name, form("%s.%s", base_name, SCHEMA_FILE_SUFFIX));
      if ( exist_file(f_name, new_db_path) == true )
         del_file(f_name, new_db_path);


      f_obj_dict -> init_a_base(spec_file_path, new_db_path, base_name);

      const char* lang;
      if ((lang = getenv("LC_ALL")) == NULL)
	if ((lang = getenv("LC_CTYPE")) == NULL)
	  if ((lang = getenv("LANG")) == NULL)
	    lang = "C";

#ifdef DtinfoClient
      _DtXlateDb db    = NULL;
      char* std_locale = NULL;

      if (_DtLcxOpenAllDbs(&db) == 0)
      {
	char platform[_DtPLATFORM_MAX_LEN + 1];
	int execver, compver;

	if (_DtXlateGetXlateEnv(db, platform, &execver, &compver) == 0)
	{
	  _DtLcxXlateOpToStd(db, platform, compver, DtLCX_OPER_SETLOCALE,
					lang, &std_locale, NULL, NULL, NULL);
	}
	_DtLcxCloseDb(&db);
	db = NULL;
      }
#endif

      base = new info_base(*f_obj_dict, set_nm_list, list_nm_list,
                           new_db_path, base_name, base_desc, base_uid,
#ifdef DtinfoClient
			   std_locale ? std_locale : lang,
#else
			   lang,
#endif
                           mm_version(MAJOR, MINOR)
                          );

      info_base_list.insert_as_tail(new dlist_void_ptr_cell(base));

/*************************************/
// add the base name and description
// to the names file
/*************************************/
      char* lib_nm = form("%s/%s", info_lib_path, MAP_FILE_8_3);

      fstream nm_out(lib_nm, ios::app, open_file_prot());

      if ( !nm_out ) {
         MESSAGE(cerr, form("can't open %s/%s for append", 
                            info_lib_path, MAP_FILE_8_3)
                );
         throw(streamException(nm_out.rdstate()));
      }

      if ( bytes(nm_out) == 0 ) {
         char* lib_entry = form("%s\t%s\n", info_lib_name, unique_id());

         if ( !(nm_out << lib_entry) ) {
            MESSAGE(cerr, 
	       form("write %s.%s failed", info_lib_path, MAP_FILE_8_3));
            throw(streamException(nm_out.rdstate()));
         }
      }

      char* base_entry = form("%s\t%s\t%s\t%s\t%d\t%d\n", 
                              base_name, base_desc, base_uid,
#ifdef DtinfoClient
			      std_locale ? std_locale: lang,
#else
			      lang,
#endif
			      MAJOR, MINOR
                             );
#ifdef DtinfoClient
      if (std_locale)
	free(std_locale);
#endif

      if ( !(nm_out << base_entry) ) {
         MESSAGE(cerr, form("write %s.%s failed", info_lib_path, MAP_FILE_8_3));
         throw(streamException(nm_out.rdstate()));
      }

      nm_out.close();

      if ( nm_out.fail() ) {
         MESSAGE(cerr, form("close %s.%s failed", info_lib_path, MAP_FILE_8_3));
         throw(streamException(nm_out.rdstate()));
      }

   //}


//MESSAGE(cerr, "define() done");
   return true;
}