Пример #1
0
int grok_common_var(struct cfg_comp *config, struct cfg_var *v)
{
	const char *expires;

	if (!strcmp(v->key, "pulse_interval")) {
		pulse_interval = (unsigned)strtoul(v->value, NULL, 10);
		if (!pulse_interval) {
			cfg_warn(config, v, "Illegal pulse_interval. Using default.");
			pulse_interval = 10;
		}
		return 1;
	}

	expires = config_key_expires(v->key);
	if (expires) {
		cfg_warn(config, v, "'%s' is a deprecated variable, scheduled for "
			 "removal at the first release after %s", v->key, expires);
		/* it's understood, in a way */
		return 1;
	}

	if (!prefixcmp(v->key, "ipc_")) {
		if (!ipc_grok_var(v->key, v->value))
			cfg_error(config, v, "Failed to grok IPC option");

		return 1;
	}

	if (!prefixcmp(v->key, "log_") || !strcmp(v->key, "use_syslog")) {
		if (!log_grok_var(v->key, v->value))
			cfg_error(config, v, "Failed to grok logging option");

		return 1;
	}

	if (!prefixcmp(v->key, "binlog_")) {
		if (!grok_binlog_var(v->key, v->value))
			cfg_error(config, v, "Failed to grok binlog option");

		return 1;
	}

	if (!prefixcmp(v->key, "oconfsplit_")) {
#ifdef MERLIN_MODULE_BUILD
		if (!split_grok_var(v->key, v->value))
			cfg_error(config, v, "Failed to grok oconfsplit option");
#endif

		return 1;
	}
	return 0;
}
Пример #2
0
static int grok_config(char *path)
{
	uint i;
	struct cfg_comp *config;

	if (!path)
		return 0;

	config = cfg_parse_file(path);
	if (!config)
		return 0;

	for (i = 0; i < config->vars; i++) {
		struct cfg_var *v = config->vlist[i];

		if (!v->value)
			cfg_error(config, v, "No value for option '%s'", v->key);

		if (grok_common_var(config, v))
			continue;

		if (!strcmp(v->key, "port")) {
			default_port = (unsigned short)strtoul(v->value, NULL, 0);
			continue;
		}

		cfg_warn(config, v, "Unrecognized variable\n");
	}

	for (i = 0; i < config->nested; i++) {
		struct cfg_comp *c = config->nest[i];

		if (!prefixcmp(c->name, "daemon")) {
			grok_daemon_compound(c);
			continue;
		}
	}

	/*
	 * if we're supposed to kill a running daemon, ignore
	 * parsing and post-processing nodes. We avoid memory
	 * fragmentation by releasing the config memory before
	 * allocating memory for the nodes.
	 */
	if (!killing) {
		node_grok_config(config);
	}
	cfg_destroy_compound(config);
	if (!killing) {
		post_process_nodes();
	}

	return 1;
}
Пример #3
0
Файл: cfg.c Проект: arnew/yaboot
static int cfg_set (char *item, char *value)
{
     CONFIG *walk;

     if (!strncasecmp (item, "image", 5)) {
	  struct IMAGES **p = &images;
	  int ignore = 0;

	  if (item[5] == '[' && item[strlen(item) - 1] == ']') {
		char *s, *q = item;

		/* Get rid of braces */
		item[strlen(item) - 1] = 0;
		item[5] = 0;

		for (s = item + 6; q; s = q) {
			q = strchr(s, '|');
			if (q)
				*q++ = 0;

			if (match_arch(s))
				goto cfg_set_cont;
                }
		/* This just creates an unused table. It will get ignored */
		ignore = 1;
	  } else if (item[5])
                goto cfg_set_redo;

cfg_set_cont:
	  while (*p)
	       p = &((*p)->next);
	  *p = (struct IMAGES *)malloc (sizeof (struct IMAGES));
	  if (*p == NULL) {
	       prom_printf("malloc error in cfg_set\n");
	       return -1;
	  }
	  (*p)->next = 0;
	  (*p)->obsolete = ignore;
	  curr_table = ((*p)->table);
	  memcpy (curr_table, cf_image, sizeof (cf_image));
     }

cfg_set_redo:
     for (walk = curr_table; walk->type != cft_end; walk++) {
	  if (walk->name && !strcasecmp (walk->name, item)) {
	       if (value && walk->type != cft_strg)
		    cfg_warn ("'%s' doesn't have a value", walk->name);
	       else if (!value && walk->type == cft_strg)
		    cfg_warn ("Value expected for '%s'", walk->name);
	       else {
		    if (!strcasecmp (item, "label"))
			 check_for_obsolete(value);
		    if (walk->data)
			 cfg_warn ("Duplicate entry '%s'", walk->name);
		    if (walk->type == cft_flag)
			 walk->data = &flag_set;
		    else if (walk->type == cft_strg)
			 walk->data = value;
	       }
	       break;
	  }
     }

     if (walk->type != cft_end)
	  return 1;

     //cfg_return (item, value);

     return 0;
}