Example #1
0
static int load_config_defaults(struct sys_config *cfg) {
  /* TODO(rojer): Figure out what to do about merging two different defaults. */
  if (!load_config_file(CONF_SYS_DEFAULTS_FILE, "*", 0, cfg)) return 0;
  if (!load_config_file(CONF_APP_DEFAULTS_FILE, cfg->conf_acl, 0, cfg))
    return 0;
  /* Vendor config is optional. */
  load_config_file(CONF_VENDOR_FILE, cfg->conf_acl, 0, cfg);
  return 1;
}
Example #2
0
void load_config ()
{
  char path[PATH_MAX];
  size_t n = strlcpy(path, CHKPW_PG_CONFDIR, sizeof(path));
  if (n >= PATH_MAX) {
    syslog(LOG_ERR, "config dir path is too long");
    exit(111);
  }
  load_config_file(path, n, "connect", &conf_pg_connect);
  load_config_file(path, n, "query", &conf_pg_query);
  syslog(LOG_DEBUG, "conf_pg_connect: %s", conf_pg_connect);
  syslog(LOG_DEBUG, "conf_pg_query: %s", conf_pg_query);
}
int set_module_option(wchar_t* option_name, wchar_t const* option_value)
{
	char tmp_option_value[MAX_STRING_SIZE * 2] = {0};
	int error_code =0x0;
	size_t size = 0x0;
	errno_t errno;

	error_code = load_config_file(__config_file_path);
	if(error_code == APP_FAULT){	__last_error_code = get_last_error();	goto GOTO;}

	error_code = check_segd_option(option_name);
	if(error_code == APP_FAULT){	__last_error_code = get_last_error();	goto GOTO;}

	errno = wcstombs_s(&size, tmp_option_value, sizeof(tmp_option_value), option_value, sizeof(tmp_option_value));
	if(errno != 0){	__last_error_code = IDS_STRING5015; 	goto GOTO;}

	tmp_option_value[size] = 0x0;
	error_code = modify_segd_option(option_name, tmp_option_value);
	if(error_code == APP_FAULT){	__last_error_code = get_last_error();	goto GOTO;}

	error_code = save_config_file(__config_file_path);
	if(error_code == APP_FAULT){	__last_error_code = get_last_error();}

GOTO:
	return error_code;
}
Example #4
0
int main(int argc, char **argv)
{
	char datapath_buffer[PATH_BUF_SIZE] = { 0 };
	parse_args(argc, argv, datapath_buffer);
	if( strlen(datapath_buffer) > 0 ) {
		if( chdir(datapath_buffer) == -1 ) {
			throw_error("data path does not exist");
		}
	}
	
	roomBase rooms;
	objectBase objects;
	enemyBase enemies;
	playerType player;
	load_map_file("datafiles/map.data", &rooms);
	//list_room_objects(&(rooms.rooms[0]));
	//list_room_dependency_objects(&(rooms.rooms[1]));
	load_rooms_file("datafiles/rooms.data", &rooms);
	load_objects_file("datafiles/objects.data", &objects);
	load_enemies_file("datafiles/enemies.data", &enemies);
	load_config_file("datafiles/config.data", &player);
	
	if( debug ) {
		list_room_info(&rooms);
		list_object_info(&objects);
		list_enemy_info(&enemies);
	}
	
	start_game(&player, &rooms, &objects, &enemies);
	
	return 0;
}
Example #5
0
int tapioca_init(const char* tconfig, const char* pconfig) {
	struct timeval now;

	tapioca_init_defaults();
	
	tapioca_config = tconfig;
	paxos_config = pconfig;
	
	lp_config = evpaxos_config_read(paxos_config);
	
	signal(SIGINT, sigint);
	signal(SIGSEGV, sigint);
	//signal(SIGKILL, sigint); // bad!! 
	signal(SIGTERM, sigint);
	signal(SIGPIPE, SIG_IGN);

	gettimeofday(&now, NULL);
    srandom(now.tv_usec);
	
	#ifndef linux
	setenv("EVENT_NOPOLL", "1", 1);
	setenv("EVENT_NOKQUEUE", "1", 1);
	#endif
	
	load_config_file(tapioca_config);
    
	base = event_init();
	// Set two possible priorities: 0 and 1.
	// event_base_priority_init(base, 2);
	
	return 0;
}
Example #6
0
static int input_init(void)
{
	GKeyFile *config;

	connection = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
	if (connection == NULL)
		return -EIO;

	config = load_config_file(CONFIGDIR "/input.conf");

	if (input_manager_init(connection, config) < 0) {
		dbus_connection_unref(connection);
		return -EIO;
	}

	if (hog_init() < 0) {
		dbus_connection_unref(connection);
		return -EIO;
	}

	if (config)
		g_key_file_free(config);

	return 0;
}
Example #7
0
static int config_imager(void)
{
	load_config_file();

	#if 0
	if (mw_set_iq_preference(iq_map.ae_preference) < 0) {
		APP_PRINTF("mw_set_iq_preference error\n");
	}
	#endif
	if (mw_set_ae_param(&iq_map.ae) < 0) {
		APP_ERROR("mw_set_ae_param error\n");
		return -1;
	}
	if (mw_set_image_param(&image_map) < 0) {
		APP_ERROR("mw_set_image_param error\n");
		return -1;
	}
	if (mw_set_awb_param(&awb_map) < 0) {
		APP_ERROR("mw_set_awb_param error\n");
		return -1;
	}
	if (set_basic_image_params(&iq_map) < 0) {
		APP_ERROR("set_basic_image_params error\n");
		return -1;
	}
	g_mw_basic_iq = iq_map;
	g_mw_image = image_map;
	g_mw_awb = awb_map;

	return 0;
}
Example #8
0
static int input_init(void)
{
    GKeyFile *config;
    GError *err = NULL;

    config = load_config_file(CONFIGDIR "/input.conf");
    if (config) {
        int idle_timeout;

        idle_timeout = g_key_file_get_integer(config, "General",
                                              "IdleTimeout", &err);
        if (!err) {
            DBG("input.conf: IdleTimeout=%d", idle_timeout);
            input_set_idle_timeout(idle_timeout * 60);
        } else
            g_clear_error(&err);
    }

    btd_profile_register(&input_profile);

    if (config)
        g_key_file_free(config);

    return 0;
}
static int input_init(void)
{
	GKeyFile *config;
	GError *err = NULL;

	config = load_config_file(CONFIGDIR "/input.conf");
	if (config) {
		int idle_timeout;
		gboolean uhid_enabled;

		idle_timeout = g_key_file_get_integer(config, "General",
							"IdleTimeout", &err);
		if (!err) {
			DBG("input.conf: IdleTimeout=%d", idle_timeout);
			input_set_idle_timeout(idle_timeout * 60);
		} else
			g_clear_error(&err);

		uhid_enabled = g_key_file_get_boolean(config, "General",
							"UserspaceHID", &err);
		if (!err) {
			DBG("input.conf: UserspaceHID=%s", uhid_enabled ?
							"true" : "false");
			input_enable_userspace_hid(uhid_enabled);
		} else
			g_clear_error(&err);
	}

	btd_profile_register(&input_profile);

	if (config)
		g_key_file_free(config);

	return 0;
}
static int config_handler(TSCont cont, TSEvent event, void *edata) {
	config_holder_t *config_holder;

	TSDebug(PLUGIN_TAG, "In config Handler");
	config_holder = (config_holder_t *) TSContDataGet(cont);
	load_config_file(config_holder);
	return 0;
}
/**
 * search for first valid configuration file
 */
void load_config_files (void) {
	int i;
	for (i = 0; i < 5; i++) {
		if (load_config_file(config_files[i])) {
			/** printf("Configuration file %s has been successfully parsed.\n", config_files[i]); */
			break;
		}
	}
}
Example #12
0
int load_config(int argc, char **argv)
{
    /* initialize the config tree */
    config_tree = NULL;

    /* load from the config file */
    load_config_file(get_config_key_string("config", "file", "armemu.conf"));

    return 0;
}
Example #13
0
void configuration::parse_option(const int ac, const char* argv[])
{
    load_config_file();
    for (int i = 1; i < ac; ++i)
    {
        size_t  len = strlen(argv[i]) - 2;
        if (0 == memcmp(&argv[i][2], "io_pool_size", len))
        {
            m_ev_loop_size = strtoul(&argv[i][2], NULL, 0);
        }
    }
}
Example #14
0
int
qsc_load_config_file(char const *filename)
{
	int rc = load_config_file(filename);

	if (rc == -2) {
		perror(filename);
		fprintf(stderr, "Could not open config file \"%s\"\n",
		    filename);
		return (-1);
	}
	return (rc);
}
Example #15
0
File: main.c Project: VinceGa/bluez
static int audio_init(void)
{
	GKeyFile *config;

	config = load_config_file(CONFIGDIR "/audio.conf");

	if (audio_manager_init(config) < 0) {
		audio_manager_exit();
		return -EIO;
	}

	return 0;
}
Example #16
0
STATIC int
try_load_config_file(char const *filename, int const show_error)
{
	int rc = load_config_file(filename);

	if ((rc == -2) && show_error) {
		perror(filename);
		fprintf(stderr, "Error: Could not open config file \"%s\"\n",
		    filename);
	} else if (rc == -1) {
		fprintf(stderr, "Error: Could not load config file \"%s\"\n",
		    filename);
	}
	return (rc);
}
Example #17
0
static enum parse_error
parse_include(struct option *opt_tree, struct conf_parsing_state *state,
	      struct string *mirror, int is_system_conf)
{
	unsigned char *fname;
	struct string dumbstring;
	struct conf_parsing_pos before_error;

	if (!init_string(&dumbstring))
		return show_parse_error(state, ERROR_NOMEM);

	skip_white(&state->pos);
	if (!*state->pos.look) {
		done_string(&dumbstring);
		return show_parse_error(state, ERROR_PARSE);
	}

	/* File name */
	before_error = state->pos;
	fname = option_types[OPT_STRING].read(NULL, &state->pos.look,
					      &state->pos.line);
	if (!fname) {
		done_string(&dumbstring);
		state->pos = before_error;
		return show_parse_error(state, ERROR_PARSE);
	}

	/* We want load_config_file() to watermark stuff, but not to load
	 * anything, polluting our beloved options tree - thus, we will feed it
	 * with some dummy string which we will destroy later; still better
	 * than cloning whole options tree or polluting interface with another
	 * rarely-used option ;). */
	/* XXX: We should try CONFDIR/<file> when proceeding
	 * CONFDIR/<otherfile> ;). --pasky */
	if (load_config_file(fname[0] == '/' ? (unsigned char *) ""
					     : elinks_home,
			     fname, opt_tree, 
			     mirror ? &dumbstring : NULL, 1)) {
		done_string(&dumbstring);
		mem_free(fname);
		return show_parse_error(state, ERROR_VALUE);
	}

	done_string(&dumbstring);
	mem_free(fname);
	return ERROR_NONE;
}
int
mb_kbd_config_load(MBKeyboard *kbd, char *variant)
{
  char                  *data;
  XML_Parser             p;
  MBKeyboardConfigState *state;

  if (!(data = load_config_file ("keyboard", variant, 1, &kbd->config_file)))
    util_fatal_error("Couldn't find a keyboard config file\n");

  p = XML_ParserCreate(NULL);

  if (!p)
    util_fatal_error("Couldn't allocate memory for XML parser\n");

  if (variant && !strstr(kbd->config_file, variant))
    fprintf(stderr,
	    "matchbox-keyboard: *Warning* Unable to locate variant: %s\n"
	    "                   falling back to %s\n",
	    variant, kbd->config_file);

  state = util_malloc0(sizeof(MBKeyboardConfigState));

  state->keyboard = kbd;
  state->parser = p;

  XML_SetElementHandler(p, config_xml_start_cb, NULL);

  /* XML_SetCharacterDataHandler(p, chars); */

  XML_SetUserData(p, (void *)state);

  if (! XML_Parse(p, data, strlen(data), 1)) {
    fprintf(stderr,
	    "matchbox-keyboard:%s:%d: XML Parse error:%s\n",
	    kbd->config_file,
	    (int)XML_GetCurrentLineNumber(p),
	    XML_ErrorString(XML_GetErrorCode(p)));
    util_fatal_error("XML Parse failed.\n");
  }

  XML_ParserFree (p);

  return 1;
}
/**
 * Load the configuration.
 */
int reload_config_file (const char *config_fname, struct config_s *conf,
                        struct config_s *defaults)
{
        int ret;

        log_message (LOG_INFO, "Reloading config file");

        free_config (conf);

        initialize_with_defaults (conf, defaults);

        ret = load_config_file (config_fname, conf);
        if (ret != 0) {
                goto done;
        }

        /* Set the default values if they were not set in the config file. */
        if (conf->port == 0) {
                /*
                 * Don't log here in error path:
                 * logging might not be set up yet!
                 */
                fprintf (stderr, PACKAGE ": You MUST set a Port in the "
                         "config file.\n");
                ret = -1;
                goto done;
        }

        if (!conf->user) {
                log_message (LOG_WARNING, "You SHOULD set a UserName in the "
                             "config file. Using current user instead.");
        }

        if (conf->idletimeout == 0) {
                log_message (LOG_WARNING, "Invalid idle time setting. "
                             "Only values greater than zero are allowed. "
                             "Therefore setting idle timeout to %u seconds.",
                             MAX_IDLE_TIME);
                conf->idletimeout = MAX_IDLE_TIME;
        }

done:
        return ret;
}
Example #20
0
static int audio_init(void)
{
	GKeyFile *config;
	gboolean enable_sco;

	connection = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
	if (connection == NULL)
		return -EIO;

	config = load_config_file(CONFIGDIR "/audio.conf");

	if (unix_init() < 0) {
		error("Unable to setup unix socket");
		goto failed;
	}

	if (audio_manager_init(connection, config, &enable_sco) < 0)
		goto failed;

	if (!enable_sco)
		return 0;

	sco_server = bt_io_listen(BT_IO_SCO, sco_server_cb, NULL, NULL,
					NULL, NULL,
					BT_IO_OPT_INVALID);
	if (!sco_server) {
		error("Unable to start SCO server socket");
		goto failed;
	}

	return 0;

failed:
	audio_manager_exit();
	unix_exit();

	if (connection) {
		dbus_connection_unref(connection);
		connection = NULL;
	}

	return -EIO;
}
static config_holder_t* new_config_holder(const char* path) {
	char default_config_file[1024];
	config_holder_t* config_holder = TSmalloc(sizeof(config_holder_t));
	config_holder->config_path = 0;
	config_holder->config = 0;
	config_holder->last_load = 0;
	//	TSmalloc(32);
	//
	if(path) {
		config_holder->config_path = nstr(path);
	} else {
		/* Default config file of plugins/cacheurl.config */
		//		sprintf(default_config_file, "%s/astats.config", TSPluginDirGet());
		sprintf(default_config_file, "%s/"DEFAULT_CONFIG_NAME, TSConfigDirGet());
		config_holder->config_path = nstr(default_config_file);
	}
	load_config_file(config_holder);
	return config_holder;
}
Example #22
0
static int input_init(void)
{
	GKeyFile *config;
	GError *err = NULL;

	config = load_config_file(CONFIGDIR "/input.conf");
	if (config) {
		idle_timeout = g_key_file_get_integer(config, "General",
						"IdleTimeout", &err);
		if (err) {
			DBG("input.conf: %s", err->message);
			g_error_free(err);
		}
	}

	btd_profile_register(&input_profile);

	if (config)
		g_key_file_free(config);

	return 0;
}
Example #23
0
int proximity_manager_init(GKeyFile *config)
{
	load_config_file(config);

	if (btd_profile_register(&pxp_monitor_linkloss_profile) < 0)
		goto fail;

	if (btd_profile_register(&pxp_monitor_immediate_profile) < 0)
		goto fail;

	if (btd_profile_register(&pxp_monitor_txpower_profile) < 0)
		goto fail;

	if (btd_profile_register(&pxp_reporter_profile) < 0)
		goto fail;

	return 0;

fail:
	proximity_manager_exit();

	return -1;
}
static int
load_include (MBKeyboardConfigState *state,
              const char            *include,
              int                    autolocale)
{
  XML_Parser  p, old_p;
  char        *data;

  if (!(data = load_config_file (include, NULL, autolocale, NULL)))
    util_fatal_error("Couldn't find a keyboard config file\n");

  p = XML_ParserCreate(NULL);

  if (!p)
    util_fatal_error("Couldn't allocate memory for XML subparser\n");

  old_p = state->parser;
  state->parser = p;

  XML_SetElementHandler(p, config_xml_start_cb, NULL);
  XML_SetUserData(p, (void *)state);

  if (! XML_Parse(p, data, strlen(data), 1)) {
    fprintf(stderr,
	    "matchbox-keyboard:%s:%d: XML Parse error:%s\n",
	    include,
	    (int)XML_GetCurrentLineNumber(p),
	    XML_ErrorString(XML_GetErrorCode(p)));
    util_fatal_error("XML Parse failed.\n");
  }

  state->parser = old_p;

  XML_ParserFree (p);

  return 1;
}
Example #25
0
bool test_create_account_with_account_control()
{
	SETUP_TEST_S3SIMULATOR();

	std::auto_ptr<Configuration> config = load_config_file(DEFAULT_BBACKUPD_CONFIG_FILE,
		BackupDaemonConfigVerify);
	S3BackupAccountControl control(*config);
	control.CreateAccount("test", 1000, 2000);

	FileStream fs("testfiles/store/subdir/" S3_INFO_FILE_NAME);
	std::auto_ptr<BackupStoreInfo> info = BackupStoreInfo::Load(fs, fs.GetFileName(),
		true); // ReadOnly
	TEST_EQUAL(0, info->GetAccountID());
	TEST_EQUAL(1, info->GetLastObjectIDUsed());
	TEST_EQUAL(1, info->GetBlocksUsed());
	TEST_EQUAL(0, info->GetBlocksInCurrentFiles());
	TEST_EQUAL(0, info->GetBlocksInOldFiles());
	TEST_EQUAL(0, info->GetBlocksInDeletedFiles());
	TEST_EQUAL(1, info->GetBlocksInDirectories());
	TEST_EQUAL(0, info->GetDeletedDirectories().size());
	TEST_EQUAL(1000, info->GetBlocksSoftLimit());
	TEST_EQUAL(2000, info->GetBlocksHardLimit());
	TEST_EQUAL(0, info->GetNumCurrentFiles());
	TEST_EQUAL(0, info->GetNumOldFiles());
	TEST_EQUAL(0, info->GetNumDeletedFiles());
	TEST_EQUAL(1, info->GetNumDirectories());
	TEST_EQUAL(true, info->IsAccountEnabled());
	TEST_EQUAL(true, info->IsReadOnly());
	TEST_EQUAL(0, info->GetClientStoreMarker());
	TEST_EQUAL("test", info->GetAccountName());

	FileStream root_stream("testfiles/store/subdir/dirs/0x1.dir");
	BackupStoreDirectory root_dir(root_stream);
	TEST_EQUAL(0, root_dir.GetNumberOfEntries());

	TEARDOWN_TEST_S3SIMULATOR();
}
Example #26
0
//=============================================================================
int Kernel::init() 
{
  Logger::init(get_var_path());

  // Install signal handlers for restart and shutdown
  struct sigaction sa;
  memset(&sa, 0, sizeof(sa));
  sa.sa_handler = signal_restart;
  sigaction(SIGHUP,&sa,0);
  memset(&sa, 0, sizeof(sa));
  sa.sa_handler = signal_shutdown;
  sigaction(SIGTERM,&sa,0);

  LOG("Init " + name() + "-" + version().get_string());
  LOG("Built for " + scx::build_type() + " on " + scx::build_time().code());

  if (m_autoload_config) {
    load_config_file(m_conf_path + std::string(name() + ".conf"));
  }
  
  Module::init();
  
  return 0;
}
Example #27
0
int main(int argc, char **argv) {
	network_mysqld_table *table;

	/* read the command-line options */
	GOptionContext *option_ctx;
	GOptionGroup *option_grp;
	GError *gerr = NULL;
	int i;
	int exit_code = 0;
	int print_version = 0;
	int daemon_mode = 0;
	int start_proxy = 1;
	const gchar *check_str = NULL;

	gchar *partition_info_host = NULL;
	gchar *partition_info_db = NULL;
	gchar *db_user = NULL;
	gchar *db_passwd = NULL;
	gchar *config_file = NULL;
	gchar *log_file = NULL;
	gchar *max_conn_pool = NULL;
	int log_all_queries = 0;
	int log_debug_msgs = 0;
	int log_raw_data = 0;

	GOptionEntry admin_entries[] = {
		{ "admin-address", 'a', 0, G_OPTION_ARG_STRING, NULL, "listening address:port of internal admin-server (default: :4041)", "<host:port>"},

		{ NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL}
	};

	GOptionEntry proxy_entries[] = {
		{ "proxy-address", 'p', 0, G_OPTION_ARG_STRING, NULL, "listening address:port of the proxy-server (default: :4040)", "<host:port>"},

		{ "partition-info-host", 'h', 0, G_OPTION_ARG_STRING, NULL, "host name of table partition info (default: not set)", "<host>"},
		{ "partition-info-database", 'd', 0, G_OPTION_ARG_STRING, NULL, "database name of table partition info (default: not set)", "<database>"},
		{ "db-user", 'u', 0, G_OPTION_ARG_STRING, NULL, "db user for connecting to the proxy and database partititons (default: not set)", "<userid>"},
		{ "db-user-password", 'P', 0, G_OPTION_ARG_STRING, NULL, "db user password for connecting to the proxy and database partititons (default: not set)", "password"},

		{ "proxy-skip-profiling", 0, G_OPTION_FLAG_REVERSE, G_OPTION_ARG_NONE, NULL, "disables profiling of queries (default: enabled)", NULL},

		{ "proxy-fix-bug-25371", 0, 0, G_OPTION_ARG_NONE, NULL, "fix bug #25371 (mysqld > 5.1.12) for older libmysql versions", NULL},
		{ "proxy-lua-script", 0, 0, G_OPTION_ARG_STRING, NULL, "filename of the lua script (default: not set)", "<file>"},


		{ NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL}
	};

	GOptionEntry main_entries[] = {
		{ "version", 'V', 0, G_OPTION_ARG_NONE, NULL, "Show version", NULL},
		{ "daemon", 'D', 0, G_OPTION_ARG_NONE, NULL, "Start in daemon-mode", NULL},
		{ "pid-file", 0, 0, G_OPTION_ARG_STRING, NULL, "PID file in case we are started as daemon", "<file>"},
		{ "config-file", 'c', 0, G_OPTION_ARG_STRING, NULL, "configuration file (default is ./xxfs_dbproxy.conf)", "<file>"},
		{ "log-file", 'l', 0, G_OPTION_ARG_STRING, NULL, "log file (default is not set, using syslog)", "<file>"},
		{ "max-conn-pool-size", 'm', 0, G_OPTION_ARG_STRING, NULL, "max backend connections for each shard(default: 50)", "<number>"},
		{ "log-all-queries", 'L', 0, G_OPTION_ARG_NONE, NULL, "Log all queries(default: disabled)", NULL},
		{ "log-debug-messages", 'g', 0, G_OPTION_ARG_NONE, NULL, "Log debug messages(default: disabled)", NULL},
		{ "log-raw-data", 'r', 0, G_OPTION_ARG_NONE, NULL, "Log raw data sent/recved(default: disabled)", NULL},

		{ NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL}
	};


	if (!GLIB_CHECK_VERSION(2, 6, 0)) {
		log_error("the glib header are too old, need at least 2.6.0, got: %d.%d.%d",
				GLIB_MAJOR_VERSION, GLIB_MINOR_VERSION, GLIB_MICRO_VERSION);
	}

	check_str = glib_check_version(GLIB_MAJOR_VERSION, GLIB_MINOR_VERSION, GLIB_MICRO_VERSION);

	if (check_str) {
		log_error("%s, got: lib=%d.%d.%d, headers=%d.%d.%d",
				check_str,
				glib_major_version, glib_minor_version, glib_micro_version,
				GLIB_MAJOR_VERSION, GLIB_MINOR_VERSION, GLIB_MICRO_VERSION);
	}

	srv = network_mysqld_init();
	srv->config.network_type = NETWORK_TYPE_PROXY; /* doesn't matter anymore */
	srv->config.proxy.fix_bug_25371 = 0; /** double ERR packet on AUTH failures */
	srv->config.proxy.profiling = 1;
	srv->config.proxy.log_debug_messages = 1;
	set_debug_msg_logging(true);


	i = 0;
	admin_entries[i++].arg_data = &(srv->config.admin.address);

	i = 0;
	proxy_entries[i++].arg_data = &(srv->config.proxy.address);
	proxy_entries[i++].arg_data = &partition_info_host;
	proxy_entries[i++].arg_data = &partition_info_db;
	proxy_entries[i++].arg_data = &db_user;
	proxy_entries[i++].arg_data = &db_passwd;

	proxy_entries[i++].arg_data = &(srv->config.proxy.profiling);

	proxy_entries[i++].arg_data = &(srv->config.proxy.fix_bug_25371);
	proxy_entries[i++].arg_data = &(srv->config.proxy.lua_script);

	i = 0;
	main_entries[i++].arg_data = &(print_version);
	main_entries[i++].arg_data = &(daemon_mode);
	main_entries[i++].arg_data = &(srv->config.pid_file);
	main_entries[i++].arg_data = &config_file;
	main_entries[i++].arg_data = &log_file;
	main_entries[i++].arg_data = &max_conn_pool;
	main_entries[i++].arg_data = &log_all_queries;
	main_entries[i++].arg_data = &log_debug_msgs;
	main_entries[i++].arg_data = &log_raw_data;

	option_ctx = g_option_context_new("- SpockProxy");
	g_option_context_add_main_entries(option_ctx, main_entries, GETTEXT_PACKAGE);

	option_grp = g_option_group_new("admin", "admin module", "Show options for the admin-module", NULL, NULL);
	g_option_group_add_entries(option_grp, admin_entries);
	g_option_context_add_group(option_ctx, option_grp);

	option_grp = g_option_group_new("proxy", "proxy-module", "Show options for the proxy-module", NULL, NULL);
	g_option_group_add_entries(option_grp, proxy_entries);
	g_option_context_add_group(option_ctx, option_grp);

	if (FALSE == g_option_context_parse(option_ctx, &argc, &argv, &gerr)) {
		log_error("%s", gerr->message);

		g_error_free(gerr);

		return -1;
	}

	g_option_context_free(option_ctx);

	if (config_file && config_file[0] != '\0')
		load_config_file(config_file);
	else
		load_config_file("xxfs_dbproxy.conf");

	add_config_string("PARTITION_INFO_HOST", partition_info_host);
	add_config_string("PARTITION_INFO_DB", partition_info_db);
	add_config_string("DB_USER", db_user);
	add_config_string("DB_PASSWD", db_passwd);
	add_config_string("LOGFILE", log_file);
	add_config_string("MAX_CONN_POOL_SIZE", max_conn_pool);

	add_config_string("LOG_ALL_QUERIES", log_all_queries ? "1" : "0");
	add_config_string("LOG_DEBUG_MSG", log_debug_msgs ? "1" : "0");
	add_config_string("LOG_RAW_DATA", log_raw_data ? "1" : "0");

	if (srv->config.admin.address == NULL)
		srv->config.admin.address = g_strdup(get_config_string("ADMIN_ADDRESS"));
	if (srv->config.proxy.address == NULL)
		srv->config.proxy.address = g_strdup(get_config_string("PROXY_ADDRESS"));

	srv->config.proxy.profiling = get_config_int("SKIP_PROFILING", srv->config.proxy.profiling);
	srv->config.proxy.fix_bug_25371 = get_config_int("FIX_BUG_25371", srv->config.proxy.fix_bug_25371);
	if (srv->config.proxy.lua_script == NULL)
		srv->config.proxy.lua_script = get_config_string("LUA_SCRIPT");
	srv->config.proxy.log_debug_messages = get_config_int("LOG_DEBUG_MSG", srv->config.proxy.log_debug_messages);
	set_debug_msg_logging(srv->config.proxy.log_debug_messages);

	print_version = get_config_int("PRINT_PROXY_VERSION", print_version);
	daemon_mode = get_config_int("DAEMON_MODE", daemon_mode);
	if (srv->config.pid_file == NULL)
		srv->config.pid_file = get_config_string("PID_FILE");

#if defined(HAVE_LUA_H) && defined(LIBDIR)
	/**
	 * if the LUA_PATH is not set, set a good default 
	 */
	if (!g_getenv("LUA_PATH")) {
		g_setenv("LUA_PATH", LUA_PATHSEP LUA_PATHSEP LIBDIR "/?.lua", 1);
	}
#endif

	if (print_version) {
		printf("%s, build time: %s %s\r\n", PACKAGE_STRING, __DATE__, __TIME__);
		return 0;
	}

	log_info("%s, build time: %s %s\r\n", PACKAGE_STRING, __DATE__, __TIME__);

	if(database_lookup_load() <0) exit(0);

	if (start_proxy) {
		if (!srv->config.proxy.address) srv->config.proxy.address = g_strdup(":4040");
		if (!srv->config.proxy.backend_addresses) {
			srv->config.proxy.backend_addresses = g_new0(char *, 2);
			srv->config.proxy.backend_addresses[0] = g_strdup("127.0.0.1:3306");
		}
	}
Example #28
0
/*
 * The main flow shall never be stopped, and the sand of time will be
 * revealed.
 */
int
main(int argc, char **argv)
{
	struct udp_daemon_argv ud_argv;
	u_short *port;
	pthread_t daemon_tcp_thread, daemon_udp_thread, andna_thread;
	pthread_t ping_igw_thread;
	pthread_attr_t t_attr;

	log_init(argv[0], 0, 1);

	/* Options loading... */
	fill_default_options();
	parse_options(argc, argv);

	/* reinit the logs using the new `dbg_lvl' value */
	log_init(argv[0], server_opt.dbg_lvl, 1);
	log_to_file(0);

	/* Load the option from the config file */
	load_config_file(server_opt.config_file);
	fill_loaded_cfg_options();

	/* If a same option was specified in the config file and in the
	 * command line, give priority to the latter */
	parse_options(argc, argv);

	check_conflicting_options();

	/* Initialize the whole netsukuku source code */
	init_netsukuku(argv);

	signal(SIGALRM, sigalrm_handler);
	signal(SIGHUP, sighup_handler);
	signal(SIGINT, sigterm_handler);
	signal(SIGTERM, sigterm_handler);
	signal(SIGQUIT, sigterm_handler);

	/* Angelic foreground or Daemonic background ? */
	if (server_opt.daemon) {
		loginfo("Forking to background");
		log_init(argv[0], server_opt.dbg_lvl, 0);
		if (daemon(0, 0) == -1)
			error("Impossible to daemonize: %s.", strerror(errno));

	}

	pthread_attr_init(&t_attr);
	pthread_attr_setdetachstate(&t_attr, PTHREAD_CREATE_DETACHED);
	setzero(&ud_argv, sizeof(struct udp_daemon_argv));
	port = xmalloc(sizeof(u_short));

	/*
	 * These are the daemons, the main threads that keeps NetsukukuD
	 * up & running.
	 */
	debug(DBG_NORMAL, "Activating all daemons");

	pthread_mutex_init(&udp_daemon_lock, 0);
	pthread_mutex_init(&tcp_daemon_lock, 0);

	debug(DBG_SOFT, "Evoking the netsukuku udp radar daemon.");
	ud_argv.port = ntk_udp_radar_port;
	pthread_mutex_lock(&udp_daemon_lock);
	pthread_create(&daemon_udp_thread, &t_attr, udp_daemon,
				   (void *) &ud_argv);
	pthread_mutex_lock(&udp_daemon_lock);
	pthread_mutex_unlock(&udp_daemon_lock);

	debug(DBG_SOFT, "Evoking the netsukuku tcp daemon.");
	*port = ntk_tcp_port;
	pthread_mutex_lock(&tcp_daemon_lock);
	pthread_create(&daemon_tcp_thread, &t_attr, tcp_daemon, (void *) port);
	pthread_mutex_lock(&tcp_daemon_lock);
	pthread_mutex_unlock(&tcp_daemon_lock);


	/* Now we hook in Netsukuku */
	netsukuku_hook(0, 0);

	/*
	 * If not disabled, start the ANDNA daemon
	 */
	if (!server_opt.disable_andna)
		pthread_create(&andna_thread, &t_attr, andna_main, 0);

	xfree(port);

	if (restricted_mode && (server_opt.share_internet ||
							server_opt.use_shared_inet)) {
		debug(DBG_SOFT, "Evoking the Internet Gateway Pinger daemon");
		pthread_create(&ping_igw_thread, &t_attr, igw_monitor_igws_t, 0);
	}

	/* We use this same process for the radar_daemon. */
	debug(DBG_SOFT, "Evoking radar daemon.");
	radar_daemon(0);

	/* Not reached, hahaha */
	loginfo("Cya m8");
	pthread_attr_destroy(&t_attr);
	destroy_netsukuku();

	exit(0);
}
Example #29
0
/* override_config_file:
 *  Sets the file that will override all future configuration operations.
 */
void override_config_file(char *filename)
{
   load_config_file(&config_override, filename, NULL);
}
Example #30
0
/* set_config_file:
 *  Sets the file to be used for all future configuration operations.
 */
void set_config_file(char *filename)
{
   load_config_file(&config[0], filename, filename);
}