static void conf_devices_load(const char *dirname, nfc_context *context) { DIR *d = opendir(dirname); if (!d) { log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "Unable to open directory: %s", dirname); } else { struct dirent *de; while ((de = readdir(d)) != NULL) { // FIXME add a way to sort devices if (de->d_name[0] != '.') { const size_t filename_len = strlen(de->d_name); const size_t extension_len = strlen(".conf"); if ((filename_len > extension_len) && (strncmp(".conf", de->d_name + (filename_len - extension_len), extension_len) == 0)) { char filename[BUFSIZ] = LIBNFC_DEVICECONFDIR"/"; strcat(filename, de->d_name); struct stat s; if (stat(filename, &s) == -1) { perror("stat"); continue; } if (S_ISREG(s.st_mode)) { conf_parse_file(filename, conf_keyvalue_device, context); } } } } closedir(d); } }
int conf_parse_all_files(struct conf_option *opts, size_t len) { int ret; const char *file, *home; char *path; ret = 0; file = "/etc/kmscon.conf"; if (!access(file, F_OK)) { if (access(file, R_OK)) log_warning("config file %s exists but read access was denied", file); else ret = conf_parse_file(opts, len, file); } if (ret) goto err_out; home = getenv("HOME"); if (home) { ret = asprintf(&path, "%s/.kmscon.conf", home); if (ret < 0) { log_warning("cannot allocate enough resources to build a config-path"); ret = -ENOMEM; } else { ret = 0; if (!access(path, F_OK)) { if (access(path, R_OK)) log_warning("config file %s exists but read access was denied", path); else ret = conf_parse_file(opts, len, path); } free(path); } } err_out: return ret; }
void test_conf_parse_file(void) { /* Writes test content in test configuration file */ char path[256] = CONF_TEST_PATH; // printf("%s", __FILE__); // sprintf(path, "%s/../%s", dirname(__FILE__), CONF_TEST_PATH); // sprintf(path, "%s/../%s", dirname(__FILE__), CONF_TEST_PATH); FILE *fp = fopen(path, "w"); if (NULL == fp) { perror("fopen()"); CU_FAIL("could not create test config file"); return; } int octets = fprintf(fp, "%s", CONF_TEST_FILE); if (octets != strlen(CONF_TEST_FILE)) { CU_FAIL("test content could not be copied in test file"); return; } fclose(fp); /* Tests parsed configuration */ service_list_t* list = conf_parse_file(path); CU_ASSERT_PTR_NOT_NULL_FATAL(list); CU_ASSERT_EQUAL(list->count, 4); service_t* srv = service_list_lookup(list, "SRV12"); CU_ASSERT_PTR_NOT_NULL_FATAL(srv); CU_ASSERT_STRING_EQUAL(srv->warn, "1"); CU_ASSERT_STRING_EQUAL(srv->crit, "2"); srv = service_list_lookup(list, "SRV34"); CU_ASSERT_PTR_NOT_NULL_FATAL(srv); CU_ASSERT_PTR_NOT_NULL(srv); CU_ASSERT_STRING_EQUAL(srv->warn, "3"); CU_ASSERT_STRING_EQUAL(srv->crit, "4"); srv = service_list_lookup(list, "SRV56"); CU_ASSERT_PTR_NOT_NULL_FATAL(srv); CU_ASSERT_STRING_EQUAL(srv->warn, "5"); CU_ASSERT_STRING_EQUAL(srv->crit, "6"); srv = service_list_lookup(list, "SRV78"); CU_ASSERT_PTR_NOT_NULL_FATAL(srv); CU_ASSERT_STRING_EQUAL(srv->warn, "a"); CU_ASSERT_STRING_EQUAL(srv->crit, "-1"); service_list_free(list); }
/* See documentation in header file. */ int conf_parse(const char* filename, int (*handler)(void*, const char*, const char*, const char*), void* user) { FILE* file; int error; file = fopen(filename, "r"); if (!file) return -1; error = conf_parse_file(file, handler, user); fclose(file); return error; }
// USR1 signal: re-read configuration file static void sigusr1_cb (G_GNUC_UNUSED evutil_socket_t sig, G_GNUC_UNUSED short events, G_GNUC_UNUSED void *user_data) { ConfData *conf_new = conf_create(); ConfData *conf_old = _app->conf; LOG_err (APP_LOG, "Got SIGUSR1"); if (!conf_parse_file (conf_new, _app->conf_path)) { LOG_err (APP_LOG, "Failed to parse configuration file: %s", _app->conf_path); conf_destroy(conf_new); } else { const gchar *copy_entries[] = {"s3.host", "s3.port", "s3.access_key_id", "s3.secret_access_key", "s3.bucket_name", NULL}; int i; _app->conf = conf_new; for (i = 0; copy_entries[i]; i++) { conf_copy_entry (_app->conf, conf_old, copy_entries[i], FALSE); } conf_destroy (conf_old); log_level = conf_get_int(_app->conf, "log.level"); } }
int main(int argc, char *argv[]) { int c, rc = 0, restart; struct option opt[] = { { "once", 0, 0, '1' }, { "continue-on-error", 0, 0, 'c' }, { "exec", 1, 0, 'e' }, { "config", 1, 0, 'f' }, { "iface", 1, 0, 'i' }, { "loglevel", 1, 0, 'l' }, { "help", 0, 0, 'h' }, { "foreground", 0, 0, 'n' }, { "pidfile", 1, 0, 100 }, { "drop-privs", 1, 0, 'p' }, { "syslog", 0, 0, 's' }, { "startup-delay", 1, 0, 't' }, { "version", 0, 0, 'v' }, { NULL, 0, 0, 0 } }; ddns_t *ctx = NULL; while ((c = getopt_long(argc, argv, "1ce:f:h?i:l:np:st:v", opt, NULL)) != EOF) { switch (c) { case '1': /* --once */ once = 1; break; case 'c': /* --continue-on-error */ ignore_errors = 1; break; case 'e': /* --exec=CMD */ script_exec = strdup(optarg); break; case 'f': /* --config=FILE */ config = strdup(optarg); break; case 'i': /* --iface=IFNAME */ iface = strdup(optarg); break; case 'l': /* --loglevel=LEVEL */ loglevel = loglvl(optarg); if (-1 == loglevel) return usage(1); break; case 'n': /* --foreground */ background = 0; break; case 100: /* --pidfile=BASENAME */ pidfile_name = strdup(optarg); break; case 'p': /* --drop-privs=USER[:GROUP] */ parse_privs(optarg); break; case 's': /* --syslog */ use_syslog = 1; break; case 't': /* --startup-delay=SEC */ startup_delay = atoi(optarg); break; case 'v': puts(VERSION); return 0; case 'h': /* --help */ case ':': /* Missing parameter for option. */ case '?': /* Unknown option. */ default: return usage(0); } } if (background) { if (daemon(0, 0) < 0) { fprintf(stderr, "Failed daemonizing %s: %m\n", __progname); return RC_OS_FORK_FAILURE; } use_syslog = 1; } if (use_syslog) { openlog(NULL, LOG_PID, LOG_USER); setlogmask(LOG_UPTO(loglevel)); } if (drop_privs()) { logit(LOG_WARNING, "Failed dropping privileges: %s", strerror(errno)); return RC_OS_CHANGE_PERSONA_FAILURE; } /* "Hello!" Let user know we've started up OK */ logit(LOG_NOTICE, "%s", VERSION_STRING); if (!config) config = strdup(DEFAULT_CONFIG_FILE); /* Prepare SSL library, if enabled */ ssl_init(); do { restart = 0; rc = alloc_context(&ctx); if (rc != RC_OK) break; if (os_install_signal_handler(ctx)) return RC_OS_INSTALL_SIGHANDLER_FAILED; cfg = conf_parse_file(config, ctx); if (!cfg) { free_context(ctx); return RC_FILE_IO_MISSING_FILE; } rc = ddns_main_loop(ctx); if (rc == RC_RESTART) restart = 1; free_context(ctx); cfg_free(cfg); } while (restart); if (use_syslog) closelog(); free(config); ssl_exit(); return rc; }
/*{{{ main */ int main (int argc, char *argv[]) { Application *app; gboolean verbose = FALSE; gboolean version = FALSE; GError *error = NULL; GOptionContext *context; gchar **s_params = NULL; gchar **s_config = NULL; gboolean foreground = FALSE; gchar conf_str[1023]; struct stat st; gchar **cache_dir = NULL; gchar **s_fuse_opts = NULL; gchar **s_log_file = NULL; guint32 part_size = 0; gboolean disable_syslog = FALSE; gboolean disable_stats = FALSE; gboolean force_head_requests = FALSE; gint uid = -1; gint gid = -1; gint fmode = -1; gint dmode = -1; struct event_config *ev_config; srand (time (NULL)); app = g_new0 (Application, 1); app->conf_path = g_build_filename (SYSCONFDIR, "riofs.conf.xml", NULL); g_snprintf (conf_str, sizeof (conf_str), "Path to configuration file. Default: %s", app->conf_path); GOptionEntry entries[] = { { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_STRING_ARRAY, &s_params, NULL, NULL }, { "config", 'c', 0, G_OPTION_ARG_FILENAME_ARRAY, &s_config, conf_str, NULL}, { "uid", 0, 0, G_OPTION_ARG_INT, &uid, "Set UID of filesystem owner.", NULL }, { "gid", 0, 0, G_OPTION_ARG_INT, &gid, "Set GID of filesystem owner.", NULL }, { "fmode", 0, 0, G_OPTION_ARG_INT, &fmode, "Set mode for all files.", NULL }, { "dmode", 0, 0, G_OPTION_ARG_INT, &dmode, "Set mode for all directories.", NULL }, { "foreground", 'f', 0, G_OPTION_ARG_NONE, &foreground, "Flag. Do not daemonize process.", NULL }, { "cache-dir", 0, 0, G_OPTION_ARG_STRING_ARRAY, &cache_dir, "Set cache directory.", NULL }, { "fuse-options", 'o', 0, G_OPTION_ARG_STRING_ARRAY, &s_fuse_opts, "Fuse options.", "\"opt[,opt...]\"" }, { "disable-syslog", 0, 0, G_OPTION_ARG_NONE, &disable_syslog, "Flag. Disable logging to syslog.", NULL }, { "disable-stats", 0, 0, G_OPTION_ARG_NONE, &disable_stats, "Flag. Disable Statistics HTTP interface.", NULL }, { "part-size", 0, 0, G_OPTION_ARG_INT, &part_size, "Set file part size (in bytes).", NULL }, { "log-file", 'l', 0, G_OPTION_ARG_STRING_ARRAY, &s_log_file, "File to write output.", NULL }, { "force-head-requests", 0, 0, G_OPTION_ARG_NONE, &force_head_requests, "Flag. Send HEAD request for each file.", NULL }, { "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose, "Verbose output.", NULL }, { "version", 'V', 0, G_OPTION_ARG_NONE, &version, "Show application version and exit.", NULL }, { NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL } }; // init libraries CRYPTO_set_mem_functions (g_malloc0, g_realloc, g_free); ENGINE_load_builtin_engines (); ENGINE_register_all_complete (); ERR_load_crypto_strings (); OpenSSL_add_all_algorithms (); #ifdef SSL_ENABLED SSL_load_error_strings (); SSL_library_init (); #endif g_random_set_seed (time (NULL)); // init main app structure ev_config = event_config_new (); #if defined(__APPLE__) // method select is the preferred method on OS X. kqueue and poll are not supported. event_config_avoid_method (ev_config, "kqueue"); event_config_avoid_method (ev_config, "poll"); #endif app->evbase = event_base_new_with_config (ev_config); event_config_free (ev_config); if (!app->evbase) { LOG_err (APP_LOG, "Failed to create event base !"); application_destroy (app); return -1; } app->dns_base = evdns_base_new (app->evbase, 1); if (!app->dns_base) { LOG_err (APP_LOG, "Failed to create DNS base !"); application_destroy (app); return -1; } app->f_log = NULL; app->log_file_name = NULL; /*{{{ cmd line args */ // parse command line options context = g_option_context_new ("[bucketname] [mountpoint]"); g_option_context_add_main_entries (context, entries, NULL); g_option_context_set_description (context, "Please set both AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY environment variables!"); if (!g_option_context_parse (context, &argc, &argv, &error)) { g_fprintf (stderr, "Failed to parse command line options: %s\n", error->message); application_destroy (app); g_option_context_free (context); return -1; } g_option_context_free (context); // check if --version is specified if (version) { g_fprintf (stdout, "RioFS File System v%s\n", VERSION); g_fprintf (stdout, "Copyright (C) 2012-2014 Paul Ionkin <*****@*****.**>\n"); g_fprintf (stdout, "Copyright (C) 2012-2014 Skoobe GmbH. All rights reserved.\n"); g_fprintf (stdout, "Libraries:\n"); g_fprintf (stdout, " GLib: %d.%d.%d libevent: %s fuse: %d.%d", GLIB_MAJOR_VERSION, GLIB_MINOR_VERSION, GLIB_MICRO_VERSION, LIBEVENT_VERSION, FUSE_MAJOR_VERSION, FUSE_MINOR_VERSION ); #if defined(__APPLE__) || defined(__FreeBSD__) || !defined(__GLIBC__) g_fprintf (stdout, "\n"); #else g_fprintf (stdout, " glibc: %s\n", gnu_get_libc_version ()); #endif g_fprintf (stdout, "Features:\n"); g_fprintf (stdout, " libevent backend method: %s\n", event_base_get_method(app->evbase)); #ifdef SSL_ENABLED g_fprintf (stdout, " SSL enabled\n"); #endif /* { int i; const char **methods = event_get_supported_methods (); g_fprintf (stdout, " Available libevent backend methods:\n"); for (i = 0; methods[i] != NULL; ++i) { g_fprintf (stdout, " %s\n", methods[i]); } } */ return 0; } if (!s_params || g_strv_length (s_params) != 2) { LOG_err (APP_LOG, "Wrong number of provided arguments!\nTry `%s --help' for more information.", argv[0]); application_destroy (app); return -1; } if (verbose) log_level = LOG_debug; else log_level = LOG_msg; /*}}}*/ /*{{{ parse config file */ // user provided alternative config path if (s_config && g_strv_length (s_config) > 0) { g_free (app->conf_path); app->conf_path = g_strdup (s_config[0]); g_strfreev (s_config); } app->conf = conf_create (); if (access (app->conf_path, R_OK) == 0) { LOG_debug (APP_LOG, "Using config file: %s", app->conf_path); if (!conf_parse_file (app->conf, app->conf_path)) { LOG_err (APP_LOG, "Failed to parse configuration file: %s", app->conf_path); application_destroy (app); return -1; } } else { LOG_err (APP_LOG, "Configuration file is not found !"); application_destroy (app); return -1; } if (!conf_check_keys (app->conf, conf_keys_str, conf_keys_len)) { LOG_err (APP_LOG, "Configuration file is missing keys, please re-check your configuration file: %s", app->conf_path); application_destroy (app); return -1; } if (disable_syslog) { conf_set_boolean (app->conf, "log.use_syslog", FALSE); } // update logging settings logger_set_syslog (conf_get_boolean (app->conf, "log.use_syslog")); logger_set_color (conf_get_boolean (app->conf, "log.use_color")); if (cache_dir && g_strv_length (cache_dir) > 0) { conf_set_string (app->conf, "filesystem.cache_dir", cache_dir[0]); g_strfreev (cache_dir); } if (!verbose) log_level = conf_get_int (app->conf, "log.level"); if (uid >= 0) conf_set_int (app->conf, "filesystem.uid", uid); if (gid >= 0) conf_set_int (app->conf, "filesystem.gid", gid); if (fmode >= 0) conf_set_int (app->conf, "filesystem.file_mode", fmode); if (dmode >= 0) conf_set_int (app->conf, "filesystem.dir_mode", dmode); /*}}}*/ // try to get access parameters from the environment if (getenv ("AWS_ACCESS_KEY_ID")) { conf_set_string (app->conf, "s3.access_key_id", getenv ("AWS_ACCESS_KEY_ID")); // else check if it's set it the config file } else { if (!conf_node_exists (app->conf, "s3.access_key_id")) { LOG_err (APP_LOG, "Environment variables are not set!\nTry `%s --help' for more information.", argv[0]); application_destroy (app); return -1; } } if (getenv ("AWS_SECRET_ACCESS_KEY")) { conf_set_string (app->conf, "s3.secret_access_key", getenv ("AWS_SECRET_ACCESS_KEY")); } else { if (!conf_node_exists (app->conf, "s3.secret_access_key")) { LOG_err (APP_LOG, "Environment variables are not set!\nTry `%s --help' for more information.", argv[0]); application_destroy (app); return -1; } } // check if both strings are set if (!conf_get_string (app->conf, "s3.access_key_id") || !conf_get_string (app->conf, "s3.secret_access_key")) { LOG_err (APP_LOG, "Environment variables are not set!\nTry `%s --help' for more information.", argv[0]); application_destroy (app); return -1; } // foreground is set if (foreground) conf_set_boolean (app->conf, "app.foreground", foreground); if (part_size) conf_set_uint (app->conf, "s3.part_size", part_size); if (disable_stats) conf_set_boolean (app->conf, "statistics.enabled", FALSE); if (force_head_requests) conf_set_boolean (app->conf, "s3.force_head_requests_on_lookup", TRUE); else conf_set_boolean (app->conf, "s3.force_head_requests_on_lookup", FALSE); conf_set_string (app->conf, "s3.bucket_name", s_params[0]); if (!application_set_url (app, conf_get_string (app->conf, "s3.endpoint"))) { application_destroy (app); return -1; } if (s_fuse_opts && g_strv_length (s_fuse_opts) > 0) { app->fuse_opts = g_strdup (s_fuse_opts[0]); g_strfreev (s_fuse_opts); } if (s_log_file && g_strv_length (s_log_file) > 0) { app->log_file_name = g_strdup (s_log_file[0]); app->f_log = fopen (s_log_file[0], "a+"); if (!app->f_log) { LOG_err (APP_LOG, "Failed to open log file: %s Error: %s", s_log_file[0], strerror (errno)); application_destroy (app); return -1; } LOG_debug (APP_LOG, "Using %s for storing application logs.", s_log_file[0]); logger_set_file (app->f_log); g_strfreev (s_log_file); } conf_set_string (app->conf, "app.mountpoint", s_params[1]); // check if directory exists if (stat (conf_get_string (app->conf, "app.mountpoint"), &st) == -1) { LOG_err (APP_LOG, "Mountpoint %s does not exist! Please check directory permissions!", conf_get_string (app->conf, "app.mountpoint")); application_destroy (app); return -1; } // check if it's a directory if (!S_ISDIR (st.st_mode)) { LOG_err (APP_LOG, "Mountpoint %s is not a directory!", conf_get_string (app->conf, "app.mountpoint")); application_destroy (app); return -1; } g_strfreev (s_params); #ifdef SSL_ENABLED app->ssl_ctx = SSL_CTX_new (SSLv23_client_method ()); if (!app->ssl_ctx) { LOG_err (APP_LOG, "Failed to initialize SSL engine !"); application_exit (app); return -1; } SSL_CTX_set_options (app->ssl_ctx, SSL_OP_ALL); #endif #ifdef MAGIC_ENABLED app->magic_ctx = magic_open(MAGIC_MIME_TYPE); if (!app->magic_ctx) { LOG_err(APP_LOG, "Failed to initialize magic library\n"); return -1; } if (magic_load(app->magic_ctx, NULL)) { LOG_err(APP_LOG, "Failed to load magic database: %s\n", magic_error(app->magic_ctx)); magic_close(app->magic_ctx); return -1; } #endif app->stat_srv = stat_srv_create (app); if (!app->stat_srv) { application_exit (app); return -1; } // perform the initial request to get bucket ACL (handles redirect as well) app->service_con = http_connection_create (app); if (!app->service_con) { application_destroy (app); return -1; } bucket_client_get (app->service_con, "/?acl", application_on_bucket_acl_cb, app); // start the loop event_base_dispatch (app->evbase); application_destroy (app); return 0; }
int main(int argc, char **argv) { extern char *__progname; char *cfgfile = 0; int ch; if (geteuid() != 0) { /* No point in continuing. */ fprintf(stderr, "%s: This daemon needs to be run as root.\n", __progname); return 1; } while ((ch = getopt(argc, argv, "c:dv")) != -1) { switch (ch) { case 'c': if (cfgfile) usage(); cfgfile = optarg; break; case 'd': cfgstate.debug++; break; case 'v': cfgstate.verboselevel++; break; default: usage(); } } argc -= optind; argv += optind; if (argc > 0) usage(); log_init(__progname); timer_init(); cfgstate.runstate = INIT; LIST_INIT(&cfgstate.peerlist); cfgstate.listen_port = SASYNCD_DEFAULT_PORT; cfgstate.flags |= CTL_DEFAULT; if (!cfgfile) cfgfile = SASYNCD_CFGFILE; if (conf_parse_file(cfgfile) == 0 ) { if (!cfgstate.sharedkey) { fprintf(stderr, "config: " "no shared key specified, cannot continue"); exit(1); } } else { exit(1); } carp_demote(CARP_INC, 0); if (carp_init()) return 1; if (pfkey_init(0)) return 1; if (net_init()) return 1; if (!cfgstate.debug) if (daemon(1, 0)) { perror("daemon()"); exit(1); } if (monitor_init()) { /* Parent, with privileges. */ monitor_loop(); exit(0); } /* Child, no privileges left. Run main loop. */ sasyncd_run(getppid()); /* Shutdown. */ log_msg(0, "shutting down..."); net_shutdown(); pfkey_shutdown(); return 0; }
void server_init( char* conf_file_name, int map_szx, int map_szy, int tdepth, int speed_min, int speed_max, int apple_map_ratio, int apple_pl_ratio, int wall_map_ratio, int wall_pl_ratio, char* balname ) { int i; rand_seed = (unsigned int) time( NULL ); srand( (unsigned int) time( NULL ) ); conf_t* c = conf_create(); assert(c); conf_parse_file( c, conf_file_name ); /* server */ sv.port = conf_get_int( c, "server.port" ); //sv.num_threads = conf_get_int( c, "server.number_of_threads" ); sv.update_interval = conf_get_int( c, "server.update_interval" ); sv.stats_interval = conf_get_int( c, "server.stats_interval" ); assert( sv.port > 1023 ); assert( sv.num_threads > 0 && sv.num_threads <= MAX_THREADS ); assert( sv.update_interval > 0 ); assert( sv.stats_interval > 0 ); /* quests */ sv.quest_between = conf_get_int( c, "server.quest_between" ); sv.quest_length = conf_get_int( c, "server.quest_length" ); assert( sv.quest_between > 0 && sv.quest_length > 0 ); assert( sv.quest_between > sv.update_interval && sv.quest_length > sv.update_interval ); /* initialize clients array */ sv.n_clients = 0; sv.clients = new tm_p_tm_sv_client_t[MAX_ENTITIES]; assert( sv.clients ); /* initialize world */ server_traces_init(); actions_init( c ); server_init_multiple_actions(); entity_types_init( c ); // override the speed settings read from the config file entity_types[ ET_PLAYER ]->attr_types[ PL_SPEED ].min = speed_min; entity_types[ ET_PLAYER ]->attr_types[ PL_SPEED ].max = speed_max; // override the ratio settings read from the config file entity_types[ ET_APPLE ]->ratio = apple_map_ratio; entity_types[ ET_APPLE ]->pl_ratio = apple_pl_ratio; entity_types[ ET_WALL ]->ratio = wall_map_ratio; entity_types[ ET_WALL ]->pl_ratio = wall_pl_ratio; tm_worldmap_init( c, map_szx, map_szy, tdepth ); server_init_quests(); tm_worldmap_generate(); tm_worldmap_is_valid(); /* //burceam: if heuristic1 is turned on, allocate structures for feedback/info sv.h1_dbg_num_ent = NULL; sv.h1_dbg_num_set = NULL; //temporarily turned it always on, for potential study; //if (sv.heuristic1 != 0) { sv.h1_dbg_num_ent = (int *) malloc (sv.wl_cycles * sizeof (int)); sv.h1_dbg_num_set = (int *) malloc (sv.wl_cycles * sizeof (int)); assert ((sv.h1_dbg_num_ent != NULL) && (sv.h1_dbg_num_set != NULL)); int i; for (i = 0; i < sv.wl_cycles; i++) { sv.h1_dbg_num_ent [i] = 0; sv.h1_dbg_num_set [i] = 0; } } //burceam: for heuristic 2, hopefully temporary //note that this may need to be resized at some point: new players may join, //and existing players can drop out. //change_grain_to_entity_for_h3 is obviously meant to be used by heuristic h3. { sv.change_grain_to_entity = (unsigned char *) malloc (sv.wl_client_count * sizeof (unsigned char)); sv.change_grain_to_entity_for_h3 = (unsigned char *) malloc (sv.wl_client_count * sizeof (unsigned char)); int i; for (i = 0; i < sv.wl_client_count; i ++) { sv.change_grain_to_entity [i] = 0; sv.change_grain_to_entity_for_h3 [i] = 0; } } //burceam: this field is used for debugging sv.num_invocations_collision_detection [0] = 0; sv.num_invocations_collision_detection [1] = 0; sv.num_invocations_collision_detection [2] = 0; sv.num_invocations_collision_detection [3] = 0; //burceam: create and initialize the list of area node h_meta pointers. //this MUST be done after tm_worldmap_init(), where I think the area node tree is created //and initialized. We need the depth here. { int i, num_area_nodes = 1; //IMPORTANT: the _actual_ depth of the tree is tdepth+1 !! //root is level "depth", and they keep building until level reaches 0, including for 0! //(nodes at level 0 are the leaves). So for depth=8 entered on cmd line, we really have 9 levels. num_area_nodes = 1 << (tm_wm.depth + 1); sv.hmeta_list = (ptr_t *) malloc (num_area_nodes * sizeof (ptr_t)); for (i = 0; i < num_area_nodes; i++) sv.hmeta_list [i] = NULL; } */ /* initialize synthetic workload */ server_generate_workload(); tm_worldmap_is_valid(); loadb_init( balname ); /* initialize syncronization & server threads */ barrier_init( &sv.barrier, sv.num_threads ); server_stats_init(); sv.done = 0; svts = (server_thread_t*) malloc( sv.num_threads * sizeof(server_thread_t) ); for( i = 0; i < sv.num_threads; ++i ) server_thread_init( &svts[i], i ); log_info( "[I] Server init done.\n" ); }
void conf_load(nfc_context *context) { conf_parse_file(LIBNFC_CONFFILE, conf_keyvalue_context, context); conf_devices_load(LIBNFC_DEVICECONFDIR, context); }