From patchwork Sat Feb 28 00:53:54 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geoff Levand X-Patchwork-Id: 23849 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from ozlabs.org (localhost [127.0.0.1]) by ozlabs.org (Postfix) with ESMTP id 9E4A6DDF07 for ; Sat, 28 Feb 2009 12:03:11 +1100 (EST) X-Original-To: cbe-oss-dev@ozlabs.org Delivered-To: cbe-oss-dev@ozlabs.org Received: from hera.kernel.org (hera.kernel.org [140.211.167.34]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 10811DDE1A; Sat, 28 Feb 2009 11:59:38 +1100 (EST) Received: from hera.kernel.org (IDENT:U2FsdGVkX1+DPcB/aMEWvtr5fTt4VngGznBh0s0sb20@localhost [127.0.0.1]) by hera.kernel.org (8.14.2/8.14.2) with ESMTP id n1S0xTh2016666 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Sat, 28 Feb 2009 00:59:29 GMT Received: (from geoff@localhost) by hera.kernel.org (8.14.2/8.13.1/Submit) id n1S0xTEv016665; Sat, 28 Feb 2009 00:59:29 GMT Message-Id: <20090228005350.434458322@am.sony.com> References: <20090228005350.203477145@am.sony.com> In-reply-to: <20090228005350.203477145@am.sony.com> User-Agent: quilt/0.46-1 Date: Fri, 27 Feb 2009 16:53:54 -0800 From: Geoff Levand To: Jeremy Kerr Content-Disposition: inline; filename=kboot-conf-file-loop.diff X-Virus-Scanned: ClamAV 0.93.3/9055/Fri Feb 27 20:16:01 2009 on hera.kernel.org X-Virus-Status: Clean X-Spam-Status: No, score=-2.5 required=5.0 tests=AWL,BAYES_00, UNPARSEABLE_RELAY autolearn=ham version=3.2.5 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on hera.kernel.org X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.0 (hera.kernel.org [127.0.0.1]); Sat, 28 Feb 2009 00:59:31 +0000 (UTC) Cc: cbe-oss-dev@ozlabs.org Subject: [Cbe-oss-dev] [patch 04/16] petitboot: Loop through valid kboot conf names X-BeenThere: cbe-oss-dev@ozlabs.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: Discussion about Open Source Software for the Cell Broadband Engine List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: cbe-oss-dev-bounces+patchwork-incoming=ozlabs.org@ozlabs.org Errors-To: cbe-oss-dev-bounces+patchwork-incoming=ozlabs.org@ozlabs.org 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 --- discover/kboot-parser.c | 53 +++++++++++++++++++++++++++++++++++------------- 1 file changed, 39 insertions(+), 14 deletions(-) --- a/discover/kboot-parser.c +++ b/discover/kboot-parser.c @@ -1,5 +1,6 @@ #define _GNU_SOURCE +#include #include #include #include @@ -248,11 +249,15 @@ static void parse_buf(struct kboot_conte } -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 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); + + pb_log("%s: try: %s\n", __func__, filepath); + + 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; + } - fd = open(filepath, O_RDONLY); - if (fd < 0) - goto out; + kboot_ctx->buf = talloc_array(kboot_ctx, char, + stat.st_size + 1); - if (fstat(fd, &stat)) - goto out; - - kboot_ctx->buf = talloc_array(kboot_ctx, char, stat.st_size + 1); + 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; + } - len = read(fd, kboot_ctx->buf, stat.st_size); - if (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 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);