X-Git-Url: http://git.ozlabs.org/?p=petitboot;a=blobdiff_plain;f=discover%2Fparser-conf.c;h=5f2b9787303d3102033662f08cf2477c23a78b60;hp=be19932c68c566dac92b9f915d3ec2680613dc4c;hb=0460a745e355158559c01b25f8138404f21b5d92;hpb=24236269ce5126dfa60af60a925da503a7338c4d diff --git a/discover/parser-conf.c b/discover/parser-conf.c index be19932..5f2b978 100644 --- a/discover/parser-conf.c +++ b/discover/parser-conf.c @@ -16,7 +16,9 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#define _GNU_SOURCE +#if defined(HAVE_CONFIG_H) +#include "config.h" +#endif #include #include @@ -46,6 +48,9 @@ char *conf_strip_str(char *s) if (!s) return NULL; + if (!strlen(s)) + return NULL; + while (*s == '"' || *s == '\'' || isspace(*s)) s++; @@ -124,8 +129,6 @@ char *conf_get_pair(struct conf_context __attribute__((unused)) *conf, char *str } exit: - pb_log("%s: @%s@%s@\n", __func__, *name_out, *value_out); - return end ? end + 1 : NULL; } @@ -180,7 +183,7 @@ int conf_set_global_option(struct conf_context *conf, const char *name, if (streq(name, conf->global_options[i].name)) { conf->global_options[i].value = talloc_strdup(conf, value); - pb_log("%s: @%s@%s@\n", __func__, name, value); + pb_debug("%s: %s = '%s'\n", __func__, name, value); return 1; } } @@ -204,11 +207,8 @@ const char *conf_get_global_option(struct conf_context *conf, assert(conf->global_options); for (i = 0; conf->global_options[i].name ;i++) - if (streq(name, conf->global_options[i].name)) { - pb_log("%s: @%s@%s@\n", __func__, name, - conf->global_options[i].value); + if (streq(name, conf->global_options[i].name)) return conf->global_options[i].value; - } assert(0 && "unknown global name"); return NULL; @@ -220,14 +220,15 @@ const char *conf_get_global_option(struct conf_context *conf, * Called from conf_parse() with data read from a conf file. */ -static void conf_parse_buf(struct conf_context *conf) +void conf_parse_buf(struct conf_context *conf, char *buf, + int len __attribute__((unused))) { char *pos, *name, *value; assert(conf->get_pair); assert(conf->process_pair); - for (pos = conf->buf; pos;) { + for (pos = buf; pos;) { pos = conf->get_pair(conf, pos, &name, &value, '\n'); if (!value) @@ -245,80 +246,3 @@ static void conf_parse_buf(struct conf_context *conf) if (conf->finish) conf->finish(conf); } - -/** - * conf_parse - The common parser entry. - * - * Called from the parser specific setup routines. Searches for .conf - * files, reads data into buffers, and calls conf_parse_buf(). - */ - -int conf_parse(struct conf_context *conf) -{ - int fd, rc; - unsigned int i; - struct stat stat; - ssize_t len; - - rc = 0; - fd = -1; - len = 0; - - /* The parser is only run on the first file found. */ - /* FIXME: Could try others on error, etc. */ - - for (i = 0; conf->conf_files[i]; i++) { - char *filepath = resolve_path(conf->dc, - conf->conf_files[i], conf->dc->device_path); - - pb_log("%s: try: %s\n", __func__, filepath); - - fd = open(filepath, O_RDONLY); - - talloc_free(filepath); - - if (fd < 0) { - pb_log("%s: open failed: %s\n", __func__, - strerror(errno)); - continue; - } - - if (fstat(fd, &stat)) { - pb_log("%s: fstat failed: %s\n", __func__, - strerror(errno)); - continue; - } - - conf->buf = talloc_array(conf, char, stat.st_size + 1); - - len = read(fd, conf->buf, stat.st_size); - - if (len < 0) { - pb_log("%s: read failed: %s\n", __func__, - strerror(errno)); - continue; - } - conf->buf[len] = 0; - - break; - } - - if (fd >= 0) - close(fd); - - if (len <= 0) - goto out; - - if (!conf->dc->device->icon_file) - conf->dc->device->icon_file = talloc_strdup(conf->dc, - generic_icon_file(guess_device_type(conf->dc))); - - conf_parse_buf(conf); - - rc = 1; - -out: - pb_log("%s: %s\n", __func__, (rc ? "ok" : "failed")); - return rc; -} -