summaryrefslogtreecommitdiffstats
path: root/discover/kboot-parser.c
diff options
context:
space:
mode:
authorGeoff Levand <geoffrey.levand@am.sony.com>2009-02-27 14:53:54 +0000
committerJeremy Kerr <jk@ozlabs.org>2009-03-23 21:47:43 +1100
commitc01d445554de972b46f866e1762e76ff1d4d13f5 (patch)
treedf058060efbd84b7b819c1746118fc3c72303b78 /discover/kboot-parser.c
parent04075cdef04e50b80651a27c5a1573eff0658cc4 (diff)
downloadtalos-petitboot-c01d445554de972b46f866e1762e76ff1d4d13f5.zip
talos-petitboot-c01d445554de972b46f866e1762e76ff1d4d13f5.tar.gz
Loop through valid kboot conf names
The PS3 bootloader spec allows several kboot.conf file names. Add a loop in the parser to check for all of them. Also, print some diagnostic messages to the log file and change the parser routine name from 'parser' to 'kboot_parser' to give a better log file output. Signed-off-by: Geoff Levand <geoffrey.levand@am.sony.com>
Diffstat (limited to 'discover/kboot-parser.c')
-rw-r--r--discover/kboot-parser.c51
1 files changed, 38 insertions, 13 deletions
diff --git a/discover/kboot-parser.c b/discover/kboot-parser.c
index 930fbe4..f2fac3e 100644
--- a/discover/kboot-parser.c
+++ b/discover/kboot-parser.c
@@ -1,5 +1,6 @@
#define _GNU_SOURCE
+#include <errno.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
@@ -248,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;
@@ -261,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,
@@ -286,10 +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;
}
-define_parser(kboot, 98, parse);
+define_parser(kboot, 98, kboot_parse);
OpenPOWER on IntegriCloud