X-Git-Url: https://git.ozlabs.org/?a=blobdiff_plain;f=discover%2Fkboot-parser.c;h=f2fac3e869ff6816701dcf03a6478a8bce4e19b5;hb=95fdf2bd9857b21ce5079938ee6d701f6a876641;hp=f227ee35f910e604c6c4623ff9166d3d64a01f63;hpb=ce5eab024583af5a4725503bad6ed2aee452b1aa;p=petitboot diff --git a/discover/kboot-parser.c b/discover/kboot-parser.c index f227ee3..f2fac3e 100644 --- a/discover/kboot-parser.c +++ b/discover/kboot-parser.c @@ -1,5 +1,6 @@ #define _GNU_SOURCE +#include #include #include #include @@ -11,8 +12,8 @@ #include #include +#include -#include "log.h" #include "pb-protocol/pb-protocol.h" #include "paths.h" #include "params.h" @@ -117,7 +118,9 @@ static int check_for_global_option(struct kboot_context *ctx, return 0; } -static char *get_global_option(struct kboot_context *ctx, const char *name) +static char *get_global_option( + struct kboot_context *ctx __attribute__((unused)), + const char *name) { int i; @@ -246,11 +249,15 @@ static void parse_buf(struct kboot_context *kboot_ctx) } -static int parse(struct discover_context *ctx) +static int kboot_parse(struct discover_context *ctx) { + static const char *const conf_names[] = { + "/etc/kboot.conf", + "/etc/kboot.cnf", + }; struct kboot_context *kboot_ctx; - char *filepath; int fd, len, rc; + unsigned int i; struct stat stat; rc = 0; @@ -259,21 +266,39 @@ static int parse(struct discover_context *ctx) kboot_ctx = talloc_zero(ctx, struct kboot_context); kboot_ctx->discover = ctx; - filepath = resolve_path(kboot_ctx, "/etc/kboot.conf", ctx->device_path); + for (i = 0, len = 0; i < sizeof(conf_names) / sizeof(conf_names[0]); + i++) { + char *filepath = resolve_path(kboot_ctx, conf_names[i], + ctx->device_path); - fd = open(filepath, O_RDONLY); - if (fd < 0) - goto out; + pb_log("%s: try: %s\n", __func__, filepath); - if (fstat(fd, &stat)) - goto out; + fd = open(filepath, O_RDONLY); + if (fd < 0) { + pb_log("%s: open failed: %s : %s\n", __func__, filepath, + strerror(errno)); + continue; + } + if (fstat(fd, &stat)) { + pb_log("%s: fstat failed: %s : %s\n", __func__, + filepath, strerror(errno)); + continue; + } - kboot_ctx->buf = talloc_array(kboot_ctx, char, stat.st_size + 1); + kboot_ctx->buf = talloc_array(kboot_ctx, char, + stat.st_size + 1); - len = read(fd, kboot_ctx->buf, stat.st_size); - if (len < 0) + len = read(fd, kboot_ctx->buf, stat.st_size); + if (len < 0) { + pb_log("%s: read failed: %s : %s\n", __func__, filepath, + strerror(errno)); + continue; + } + kboot_ctx->buf[len] = 0; + } + + if (len <= 0) goto out; - kboot_ctx->buf[len] = 0; if (!ctx->device->icon_file) ctx->device->icon_file = talloc_strdup(ctx, @@ -284,14 +309,12 @@ static int parse(struct discover_context *ctx) rc = 1; out: + pb_log("%s: %s\n", __func__, (rc ? "ok" : "failed")); + if (fd >= 0) close(fd); talloc_free(kboot_ctx); return rc; } -struct parser kboot_parser = { - .name = "kboot.conf parser", - .priority = 98, - .parse = parse -}; +define_parser(kboot, 98, kboot_parse);