示例#1
0
static void
read_config_from_file (const char *filename)
{
  FILE *fp;

  fp = fopen (filename, "r");
  if (fp != NULL) {
    config_t conf;

    config_init (&conf);

    /*
    if (verbose)
      fprintf (stderr, "%s: reading configuration from %s\n",
               guestfs_int_program_name, filename);
    */

    if (config_read (&conf, fp) == CONFIG_FALSE) {
      fprintf (stderr,
               _("%s: %s: line %d: error parsing configuration file: %s\n"),
               guestfs_int_program_name, filename, config_error_line (&conf),
               config_error_text (&conf));
      exit (EXIT_FAILURE);
    }

    if (fclose (fp) == -1) {
      perror (filename);
      exit (EXIT_FAILURE);
    }

    config_lookup_bool (&conf, "read_only", &read_only);

    config_destroy (&conf);
  }
}
void net_beginService() {
  // initializes the W5100 and the TCP server for the user interface

  config_read(&cfg);
  uint8_t sn[4]={0};
  //Init and config ethernet device w5100
  W5100.init();
  W5100.setMACAddress(cfg.mac);
  W5100.setIPAddress(cfg.ip);
  W5100.setGatewayIp(cfg.gw);
  toSubnetMask(cfg.subnet, sn);
  W5100.setSubnetMask(sn);

	printf_P(PSTR("ip: %u.%u.%u.%u/%u:%u\n\r"), cfg.ip[0], cfg.ip[1], cfg.ip[2], cfg.ip[3], cfg.subnet, cfg.port);
  printf_P(PSTR("subnet %u.%u.%u.%u\n\r"), sn[0], sn[1], sn[2], sn[3]);
	printf_P(PSTR("mac: %x:%x:%x:%x:%x:%x\n\r"), cfg.mac[0], cfg.mac[1], cfg.mac[2], cfg.mac[3], cfg.mac[4], cfg.mac[5]);
	printf_P(PSTR("gw: %u.%u.%u.%u\n\r"), cfg.gw[0], cfg.gw[1], cfg.gw[2], cfg.gw[3]);
	printf_P(PSTR("db: %u.%u.%u.%u:%u/%s\n\r"), cfg.ip_db[0], cfg.ip_db[1], cfg.ip_db[2], cfg.ip_db[3], cfg.port_db, cfg.name_db);
	printf_P(PSTR("cookie: %s\n\r"), cfg.cookie_db);
	printf_P(PSTR("function for inserting into DB: %s/%s\n\r"), cfg.doc_db, cfg.func_db);



  // Create the first server socket
  socket(FIRST_SERVER_SOCK, SnMR::TCP, cfg.port, 0);
  while(!listen(FIRST_SERVER_SOCK)){
    // wait 100ms and try again
    wdt_delay_ms(100);
  }
  // connect to db, if do send to db 
  // Create client to db
  // Port of the client can be arbitary, but it should be different then the port of ui server
  // connect_db(cfg.port+1);
}
示例#3
0
void FAST_FUNC read_config(const char *file)
{
	parser_t *parser;
	const struct config_keyword *k;
	unsigned i;
	char *token[2];

	for (i = 0; i < KWS_WITH_DEFAULTS; i++)
		keywords[i].handler(keywords[i].def, keywords[i].var);

	parser = config_open(file);
	while (config_read(parser, token, 2, 2, "# \t", PARSE_NORMAL)) {
		for (k = keywords, i = 0; i < ARRAY_SIZE(keywords); k++, i++) {
			if (strcasecmp(token[0], k->keyword) == 0) {
				if (!k->handler(token[1], k->var)) {
					bb_error_msg("can't parse line %u in %s",
							parser->lineno, file);
					/* reset back to the default value */
					k->handler(k->def, k->var);
				}
				break;
			}
		}
	}
	config_close(parser);

	server_config.start_ip = ntohl(server_config.start_ip);
	server_config.end_ip = ntohl(server_config.end_ip);
}
示例#4
0
文件: tcl_cmd.c 项目: koodaamo/yadifa
static int
tcl_loaddb(ClientData clientData, Tcl_Interp *interp, int argc, char *argv[])
{
    if(argc != 1)
    {
	sprintf(interp->result, WRONG_NUMBER_OF_ARGUMENTS, argv[0]);
	return TCL_OK;
    }
    else
    {
	ya_result return_code;

	config_data *config = NULL;
	/* Initialise configuration file */
	if(FAIL(config_init(S_CONFIGDIR, &config)))
	{
	    return EXIT_FAILURE;
	}

	/* Read configuration file */
	if(FAIL(config_read("main", &config)))
	{
	    return EXIT_FAILURE;
	}

	/* Read configuration file */
	if(FAIL(config_read("zone", &config)))
	{
	    return EXIT_FAILURE;
	}

	if(FAIL(return_code = database_load(&server_context->db_zdb, config->data_path, config->zones)))
	{
	    OSDEBUG(termout, "error: %r\n", return_code);
	    
	    return return_code;
	}

	sprintf(interp->result, "done");

	return TCL_OK;
    }


    return TCL_OK;
}
示例#5
0
void setup(void)
{
	config_get_file();
	config_read(configFile);
	configure_debug(NULL,255,0);
	GetDBParams();
	db_connect();
}
示例#6
0
文件: config.c 项目: Hummer12007/nav
void config_load(const char *file)
{
  FILE *f = config_open(file, config_paths, "r");
  if (!f)
    return;
  config_read(f);
  fclose(f);
}
示例#7
0
void setup(void)
{
	configure_debug(255,0);
	config_read(configFile);
	GetDBParams();
	db_connect();
	g_mime_init(0);
}
示例#8
0
void setup(void)
{
    config_get_file();
    config_read(configFile);
    configure_debug(NULL,255,31);
    pool = mempool_open();
    A = Capa_new(pool);
}
void setup(void)
{
	configure_debug(255,0);
	config_read(configFile);
	GetDBParams();
	db_connect();
	auth_connect();
}
示例#10
0
/**
 * Run the daemon. 
 * @param cfgfile: the config file name.
 * @param cmdline_verbose: verbosity resulting from commandline -v.
 *    These increase verbosity as specified in the config file.
 * @param debug_mode: if set, do not daemonize.
 */
static void 
run_daemon(const char* cfgfile, int cmdline_verbose, int debug_mode)
{
	struct config_file* cfg = NULL;
	struct daemon* daemon = NULL;
	int done_setup = 0;

	if(!(daemon = daemon_init()))
		fatal_exit("alloc failure");
	while(!daemon->need_to_exit) {
		if(done_setup)
			verbose(VERB_OPS, "Restart of %s.", PACKAGE_STRING);
		else	verbose(VERB_OPS, "Start of %s.", PACKAGE_STRING);

		/* config stuff */
		if(!(cfg = config_create()))
			fatal_exit("Could not alloc config defaults");
		if(!config_read(cfg, cfgfile, daemon->chroot)) {
			if(errno != ENOENT)
				fatal_exit("Could not read config file: %s",
					cfgfile);
			log_warn("Continuing with default config settings");
		}
		apply_settings(daemon, cfg, cmdline_verbose);
	
		/* prepare */
		if(!daemon_open_shared_ports(daemon))
			fatal_exit("could not open ports");
		if(!done_setup) { 
			perform_setup(daemon, cfg, debug_mode, &cfgfile); 
			done_setup = 1; 
		} else {
			/* reopen log after HUP to facilitate log rotation */
			if(!cfg->use_syslog)
				log_init(cfg->logfile, 0, cfg->chrootdir);
		}
		/* work */
		daemon_fork(daemon);

		/* clean up for restart */
		verbose(VERB_ALGO, "cleanup.");
		daemon_cleanup(daemon);
		config_delete(cfg);
	}
	verbose(VERB_ALGO, "Exit cleanup.");
	/* this unlink may not work if the pidfile is located outside
	 * of the chroot/workdir or we no longer have permissions */
	if(daemon->pidfile) {
		int fd;
		/* truncate pidfile */
		fd = open(daemon->pidfile, O_WRONLY | O_TRUNC, 0644);
		if(fd != -1)
			close(fd);
		/* delete pidfile */
		unlink(daemon->pidfile);
	}
	daemon_delete(daemon);
}
示例#11
0
/** Reads the configuration file and then starts the main loop */
int main(int argc, char **argv) {

	s_config *config = config_get_config();
	config_init();

	parse_commandline(argc, argv);

	/* Initialize the config */
	config_read(config->configfile);
	config_validate();

	/* Initializes the linked list of connected clients */
	client_list_init();

	/* Init the signals to catch chld/quit/etc */
	init_signals();


	if (restart_orig_pid) {
		/*
		 * We were restarted and our parent is waiting for us to talk to it over the socket
		 */
		get_clients_from_parent();

		/*
		 * At this point the parent will start destroying itself and the firewall. Let it finish it's job before we continue
		 */
		while (kill(restart_orig_pid, 0) != -1) {
			debug(LOG_INFO, "Waiting for parent PID %d to die before continuing loading", restart_orig_pid);
			sleep(1);
		}

		debug(LOG_INFO, "Parent PID %d seems to be dead. Continuing loading.");
	}

	if (config->daemon) {

		debug(LOG_INFO, "Forking into background");

		switch(safe_fork()) {
			case 0: /* child */
				setsid();
				append_x_restartargv();
				main_loop();
				break;

			default: /* parent */
				exit(0);
				break;
		}
	}
	else {
		append_x_restartargv();
		main_loop();
	}

	return(0); /* never reached */
}
示例#12
0
文件: sig.c 项目: 340211173/xrdp
void DEFAULT_CC
sig_sesman_reload_cfg(int sig)
{
    int error;
    struct config_sesman *cfg;
    char cfg_file[256];

    log_message(LOG_LEVEL_WARNING, "receiving SIGHUP %d", 1);

    if (g_getpid() != g_pid)
    {
        LOG_DBG("g_getpid() [%d] differs from g_pid [%d]", g_getpid(), g_pid);
        return;
    }

    cfg = g_malloc(sizeof(struct config_sesman), 1);

    if (0 == cfg)
    {
        log_message(LOG_LEVEL_ERROR, "error creating new config:  - keeping old cfg");
        return;
    }

    if (config_read(cfg) != 0)
    {
        log_message(LOG_LEVEL_ERROR, "error reading config - keeping old cfg");
        g_free(cfg);
        return;
    }

    /* stop logging subsystem */
    log_end();

    /* replace old config with new readed one */
    g_cfg = cfg;

    g_snprintf(cfg_file, 255, "%s/sesman.ini", XRDP_CFG_PATH);

    /* start again logging subsystem */
    error = log_start(cfg_file, "XRDP-sesman");

    if (error != LOG_STARTUP_OK)
    {
        char buf[256];

        switch (error)
        {
            case LOG_ERROR_MALLOC:
                g_printf("error on malloc. cannot restart logging. log stops here, sorry.\n");
                break;
            case LOG_ERROR_FILE_OPEN:
                g_printf("error reopening log file [%s]. log stops here, sorry.\n", getLogFile(buf, 255));
                break;
        }
    }

    log_message(LOG_LEVEL_INFO, "configuration reloaded, log subsystem restarted");
}
示例#13
0
static void read_config(void) {
	char *filename = NULL;
	FILE *file = open_config_file(&filename);

	if (config_read(config, file) != CONFIG_TRUE)
		die("%s:%d %s", filename, config_error_line(config), config_error_text(config));

	if (fclose(file) == EOF) perror_die("fclose");
}
示例#14
0
文件: blursk.cpp 项目: PyroOS/Pyro
/* This is the main entry point.  XMMS calls this function to find anything
 * else that it needs to know about this plugin.
 */
VisPlugin *get_vplugin_info(void)
{
	/* Depends on whether we're plotting pcm data or freq data */
	config_read(NULL, NULL);
	blursk_genrender();

	/* return the info */
	return &blursk_vp;
}
示例#15
0
void setup(void)
{
	configure_debug(511,0);
	config_read(configFile);
	GetDBParams();
	db_connect();
	auth_connect();
	g_mime_init(0);
	init_testuser1();
}
示例#16
0
/*
 *
 * the test fixtures
 *
 */
void setup(void)
{
	reallyquiet = 1;
	configure_debug(255,0);
	config_read(configFile);
	GetDBParams();
	db_connect();
	auth_connect();
	do_add("testfailuser","testpass","md5-hash",0,0,NULL,NULL);
}
示例#17
0
void setup(void)
{
	configure_debug(255,0);
	config_read(configFile);
	GetDBParams();
	db_connect();
	if (! g_thread_supported () ) g_thread_init (NULL);
	auth_connect();
	init_testuser1();
}
示例#18
0
int
create_file_names_for_track (_main_data * main_data, int track, char **wfp,
			     char **efp)
{
  static char *buffer;
  int rc;
  char *conv_str = NULL;
  GtkWidget *main_window = main_window_handler(MW_REQUEST_MW, NULL, NULL);

  rc = parse_rx_format_string (&buffer,
			       ((char *) config_read (CONF_CDDB_FORMATSTR)),
			       track, main_data->disc_artist,
			       main_data->disc_title, main_data->disc_year,
			       main_data->track[track].title);
  if (rc < 0)
    {
      err_handler (GTK_WINDOW(main_window), RX_PARSING_ERR,
		   _
		   ("Check if the filename format string contains format characters other than %a %# %v %y or %s."));
      return 0;
    }

  if (buffer[0] == 0)
    strcpy (buffer, main_data->track[track].title);

  conv_str = g_locale_from_utf8 (buffer, -1, NULL, NULL, NULL);

  remove_non_unix_chars (conv_str);
  convert_slashes (conv_str, '-');
  if ((int) config_read (CONF_GNRL_CONVSPC))
    {
      convert_spaces (conv_str, '_');
    }

  if (wfp)
    mk_strcat (wfp, wd, conv_str, wfext, NULL);
  if (efp)
    mk_strcat (efp, ed, conv_str, ecfext, NULL);

  g_free (conv_str);

  return 1;
}
示例#19
0
void setup(void)
{
	config_get_file();
	config_read(configFile);
	configure_debug(NULL,255,0);
	GetDBParams();
	db_connect();
	auth_connect();
	init_testuser1();
	queue_pool = mempool_open();
}
示例#20
0
文件: config.c 项目: aqleds/firmware
void config_load()
{
    memset(&AQCONFIG,0,sizeof(AQCONFIG));
    config_read();
    if ((AQCONFIG.magic!=MAGIC) || (AQCONFIG.version!=VERSION))
    {
        config_defaults();
        config_save();
    }
    
}
示例#21
0
文件: preset.cpp 项目: PyroOS/Pyro
/* Read the presets from the "blursk-presets" file */
void preset_read(void)
{
	gchar		*filename;
	static int	did_once = FALSE;
	char		*str;
	preset_t	*item, *scan, *lag;
	FILE		*fp;
	char		linebuf[1024];

	/* if we already did this, then don't do it again */
	if (did_once)
		return;
	did_once = TRUE;

	/* scan the "blursk-presets" file for section names (preset names) */
	filename = g_strconcat(g_get_home_dir(), "/.xmms/blursk-presets", NULL);
	fp = fopen(filename, "r");
	while (fp && fgets(linebuf, sizeof linebuf, fp))
	{
		/* skip if not a section name */
		if (linebuf[0] != '[' || (str = strchr(linebuf, ']')) == NULL)
			continue;
		*str = '\0';

		/* allocate a struct for storing this info */
		item = (preset_t *)malloc(sizeof(preset_t));
		item->title = g_strdup(linebuf + 1);

		/* add this to the list of presets, keeping the
		 * list sorted by title.
		 */
		for (scan = preset_list, lag = NULL;
		     scan && strcasecmp(scan->title, item->title) < 0;
		     lag = scan, scan = scan->next)
		{
		}
		item->next = scan;
		if (lag)
			lag->next = item;
		else
			preset_list = item;

		/* increment the number of presets */
		preset_qty++;
	}
	if (fp)
		fclose(fp);

	/* Read the configuration data for each preset */
	for (item = preset_list; item; item = item->next)
	{
		config_read(item->title, &item->conf);
	}
}
示例#22
0
config_t *cfg_open(const char *path)
{

	FILE *file = NULL;
	config_t *config = (config_t*)malloc(sizeof(config_t));

	if (config == NULL)
	{
		return NULL;
	}

	if (path == NULL || path[0] == 0)
	{
		config_init(config);
		return config;
	}

	file = fopen(path,"r");

	if (file == NULL)
	{
		config_init(config);
		return config;
	}

	// Not initializing produces a crash
	config_init(config);

	if (config_read(config,file) != CONFIG_TRUE)
	{
#ifdef DEBUG
		if (config_error_type(config) == CONFIG_ERR_FILE_IO)
		{
			printf("Error opening configuration file.\n");
		}
		else
		{
			printf("Error parsing configuration file.\n");
			printf("Line: %d\n", config_error_line(config));
			printf("Text: %s\n", config_error_text(config));
		}
#endif
		// Destroy the config and initialize a new one
		config_destroy(config);
		config_init(config);
	}

	fclose(file);

	config_set_tab_width(config,0);

	return config;

}
示例#23
0
void
main(int argc, char **argv)
{
  contiki_argc = argc;
  contiki_argv = argv;

#else /* WITH_ARGS */

void
main(void)
{

#endif /* WITH_ARGS */

  process_init();

#if 1
  ethernet_config = config_read("contiki.cfg");
#else
  {
    static struct ethernet_config config = {0xDE08, "cs8900a.eth"};
    uip_ipaddr_t addr;

    uip_ipaddr(&addr, 192,168,0,128);
    uip_sethostaddr(&addr);

    uip_ipaddr(&addr, 255,255,255,0);
    uip_setnetmask(&addr);

    uip_ipaddr(&addr, 192,168,0,1);
    uip_setdraddr(&addr);

    uip_ipaddr(&addr, 192,168,0,1);
    uip_nameserver_update(&addr, UIP_NAMESERVER_INFINITE_LIFETIME);

    ethernet_config = &config;
  }
#endif

  procinit_init();

  process_start((struct process *)&ethernet_process, (void *)ethernet_config);

  autostart_start(autostart_processes);

  log_message("Contiki up and running ...", "");

  while(1) {

    process_run();

    etimer_request_poll();
  }
}
示例#24
0
/*-----------------------------------------------------------------------------------*/
void
main(void)
{
  struct ethernet_config *ethernet_config;

#if WITH_REBOOT
  rebootafterexit();
#endif /* WITH_REBOOT */

  videomode(VIDEOMODE_80COL);

  process_init();

#if 1
  ethernet_config = config_read("contiki.cfg");
#else
  {
    static struct ethernet_config config = {0xC0B0, "cs8900a.eth"};
    uip_ipaddr_t addr;

    uip_ipaddr(&addr, 192,168,0,128);
    uip_sethostaddr(&addr);

    uip_ipaddr(&addr, 255,255,255,0);
    uip_setnetmask(&addr);

    uip_ipaddr(&addr, 192,168,0,1);
    uip_setdraddr(&addr);

    uip_ipaddr(&addr, 192,168,0,1);
    resolv_conf(&addr);

    ethernet_config = &config;
  }
#endif

  procinit_init();

  process_start((struct process *)&ethernet_process, (char *)ethernet_config);

  autostart_start(autostart_processes);

  log_message("Contiki up and running ...", "");
  
  while(1) {

    process_run();

    etimer_request_poll();

    clock_update();
  }
}
示例#25
0
文件: main.c 项目: avbotz/9dof-razor
/////===========MAIN=====================/////////////////////
int main(void)
{
	init();
	self_test();
	
	while(1)
	{	
		//check to see if autorun is set, if it is don't print the menu
		if(read_from_EEPROM(1) == 48) config_read();
		else config_menu();
	}
}
示例#26
0
int modinfo_main(int argc UNUSED_PARAM, char **argv)
{
	struct modinfo_env env;
	char name[MODULE_NAME_LEN];
	struct utsname uts;
	parser_t *parser;
	char *colon, *tokens[2];
	unsigned opts;
	unsigned i;

	env.field = NULL;
	opt_complementary = "-1"; /* minimum one param */
	opts = getopt32(argv, "fdalvpF:0", &env.field);
	env.tags = opts & OPT_TAGS ? opts & OPT_TAGS : OPT_TAGS;
	argv += optind;

	uname(&uts);
	parser = config_open2(
		xasprintf("%s/%s/%s", CONFIG_DEFAULT_MODULES_DIR, uts.release, CONFIG_DEFAULT_DEPMOD_FILE),
		fopen_for_read
	);
	if (!parser) {
		parser = config_open2(
			xasprintf("%s/%s", CONFIG_DEFAULT_MODULES_DIR, CONFIG_DEFAULT_DEPMOD_FILE),
			xfopen_for_read
		);
	}

	while (config_read(parser, tokens, 2, 1, "# \t", PARSE_NORMAL)) {
		colon = last_char_is(tokens[0], ':');
		if (colon == NULL)
			continue;
		*colon = '\0';
		filename2modname(tokens[0], name);
		for (i = 0; argv[i]; i++) {
			if (fnmatch(argv[i], name, 0) == 0) {
				modinfo(tokens[0], uts.release, &env);
				argv[i] = (char *) "";
			}
		}
	}
	if (ENABLE_FEATURE_CLEAN_UP)
		config_close(parser);

	for (i = 0; argv[i]; i++) {
		if (argv[i][0]) {
			modinfo(argv[i], uts.release, &env);
		}
	}

	return 0;
}
void config_menu(void)
{
	printf_P(wlcm_str);
	printf_P(accel);
	printf_P(mag);
	printf_P(gyro);
	printf_P(raw_out);
	printf_P(test);
	printf_P(autorun);
	printf_P(help_);
	
	config_read();
}
int32_t platform_get_cik(char *cik, size_t len)
{
    int32_t status;
    struct wifi_config_data config;

    status = config_read(&config);
    if (status != ERR_SUCCESS)
        return status;

      strncpy(cik, config.cik, len);
      cik[40] = '\0';
      return ERR_SUCCESS;
}
示例#29
0
static int check_securetty(void)
{
    char *buf = (char*)"/etc/securetty"; /* any non-NULL is ok */
    parser_t *parser = config_open2("/etc/securetty", fopen_for_read);
    while (config_read(parser, &buf, 1, 1, "# \t", PARSE_NORMAL)) {
        if (strcmp(buf, short_tty) == 0)
            break;
        buf = NULL;
    }
    config_close(parser);
    /* buf != NULL here if config file was not found, empty
     * or line was found which equals short_tty */
    return buf != NULL;
}
示例#30
0
int main(int argc, char *argv[]) {
	int c, i, j, len;
	char *config_file = NULL;
	char *base_filter = "(icmp6 or arp) and ";

	/* read in command line options */
	while ((c = getopt(argc, argv, "c:d")) != -1) {
		switch(c) {
			case 'd':
				opt_debug = 1;
				printf("option -d\n");
				break;
			case 'c':
				config_file = optarg;
				if (opt_debug) {
					printf("option -c: %s\n", config_file);
				}
				break;
			default:
				usage();
				break;
		}
	}

	if (!config_read(config_file)) {
		fprintf(stderr, "Failed to read config file\n");
		die();
	}

	if (opt_debug) printf("Number of networks to monitor: %i\n", num_networks);
	for (i = 0; i < num_networks; i++) {
		/* build the filter based on the provided filter and base_filter */
		len = strlen(networks[i].filter) + strlen(base_filter) + 2;
		char *filter_expr = malloc(len + 1);
		snprintf(filter_expr, len + 1, "%s(%s)", base_filter, networks[i].filter);
		
		if (opt_debug) {
			printf("Network: %s (%i)\n", networks[i].name, i);
			printf("\tdevice = %s\n", networks[i].device);
			printf("\tfilter = %s\n", filter_expr);
			printf("\tDatabases:\n");
			for (j = 0; j < networks[i].num_databases; j++) {
				printf("\t\t%i\n", networks[i].databases[j]);
			}
		}
		capture(networks[i].device, filter_expr, i);
	}

	return 0;
}