-
-/**
- * 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;
-}
-