From patchwork Mon Jul 9 21:21:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geoff Levand X-Patchwork-Id: 941682 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41PdZl5WJ5z9rxs for ; Tue, 10 Jul 2018 07:22:23 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="qkh3ZKoY"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 41PdZl2FTtzDrbK for ; Tue, 10 Jul 2018 07:22:23 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="qkh3ZKoY"; dkim-atps=neutral X-Original-To: Petitboot@lists.ozlabs.org Delivered-To: Petitboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=none (mailfrom) smtp.mailfrom=infradead.org (client-ip=2001:8b0:10b:1231::1; helo=merlin.infradead.org; envelope-from=geoff@infradead.org; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=infradead.org Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 41PdZJ3DWmzDr55 for ; Tue, 10 Jul 2018 07:22:00 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=Date:Cc:To:Subject:From:References: In-Reply-To:Message-Id:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=uYkUuZ7m8/ikVdGjJLG0Cl5rfYljmeTx0brb414iv0M=; b=qkh3ZKoY08wbkgkMea7HW/w9d k0tPLbaEH3P2QUX6NqSHusogBumG0GEZ4IXVCzhPA6Bf6o/7qw7uKlZ3imuxlzuCaOJMXq6uAmKRA BDjx/+ikIn9/ar36RPPLjvNundX+WGHQL5AUUAr6gjl23m3JCejzYc4ooo8GYdHIkTwyTVbCScof7 eY7B36U1X8kewWRgzyUo50kFEC5staEIcebeW2qWoPO4uEh+jevwu6iPdNadUpco0HPmLL6yUdX2t TaQY5b5YY5ShqyR4mG3Ueqwd8WmmbKie4cykbFuLQx3UXoCE1cvgYT705/MclUQdG2DNlPG6+nJnF D6fBIxjRg==; Received: from geoff by merlin.infradead.org with local (Exim 4.90_1 #2 (Red Hat Linux)) id 1fcdbY-0001SU-DP; Mon, 09 Jul 2018 21:21:56 +0000 Message-Id: In-Reply-To: References: From: Geoff Levand Patch-Date: Mon, 9 Jul 2018 13:57:53 -0700 Subject: [PATCH v1 10/10] discover/parser: Hookup parser_is_unique To: Samuel Mendoza-Jonas Date: Mon, 09 Jul 2018 21:21:56 +0000 X-BeenThere: petitboot@lists.ozlabs.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: Petitboot bootloader development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Petitboot@lists.ozlabs.org MIME-Version: 1.0 Errors-To: petitboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Petitboot" Signed-off-by: Geoff Levand --- discover/kboot-parser.c | 15 ++++++++++++--- discover/syslinux-parser.c | 47 +++++++++++----------------------------------- 2 files changed, 23 insertions(+), 39 deletions(-) diff --git a/discover/kboot-parser.c b/discover/kboot-parser.c index 62512cf..4830d5a 100644 --- a/discover/kboot-parser.c +++ b/discover/kboot-parser.c @@ -167,19 +167,22 @@ static const char *const kboot_ignored_names[] = { static int kboot_parse(struct discover_context *dc) { struct conf_context *conf; + struct list *found_list; const char * const *filename; - char *buf; - int len, rc; /* Support block device boot only at present */ if (dc->event) return -1; conf = talloc_zero(dc, struct conf_context); - if (!conf) return -1; + found_list = talloc(conf, struct list); + if (!found_list) + return -1; + list_init(found_list); + conf->dc = dc; conf->global_options = kboot_global_options, conf_init_global_options(conf); @@ -188,6 +191,12 @@ static int kboot_parse(struct discover_context *dc) conf->parser_info = (void *)kboot_ignored_names; for (filename = kboot_conf_files; *filename; filename++) { + int len, rc; + char *buf; + + if (!parser_is_unique(dc->device, *filename, found_list)) + continue; + rc = parser_request_file(dc, dc->device, *filename, &buf, &len); if (rc) continue; diff --git a/discover/syslinux-parser.c b/discover/syslinux-parser.c index 288048c..68e62ab 100644 --- a/discover/syslinux-parser.c +++ b/discover/syslinux-parser.c @@ -36,12 +36,6 @@ struct syslinux_options { char *cfg_dir; }; -struct conf_file_stat { - char *name; - struct stat stat; - struct list_item list; -}; - static const char *const syslinux_conf_files[] = { "/boot/syslinux/syslinux.cfg", "/syslinux/syslinux.cfg", @@ -424,25 +418,24 @@ fail: static int syslinux_parse(struct discover_context *dc) { - struct conf_file_stat *confcmp, *confdat; - struct list processed_conf_files; struct syslinux_options *state; const char * const *filename; struct conf_context *conf; - struct stat statbuf; - char *cfg_dir; - int len, rc; - char *buf; + struct list *found_list; /* Support block device boot only at present */ if (dc->event) return -1; conf = talloc_zero(dc, struct conf_context); - if (!conf) return -1; + found_list = talloc(conf, struct list); + if (!found_list) + return -1; + list_init(found_list); + conf->dc = dc; conf->global_options = syslinux_global_options, conf_init_global_options(conf); @@ -452,8 +445,6 @@ static int syslinux_parse(struct discover_context *dc) conf->parser_info = state = talloc_zero(conf, struct syslinux_options); list_init(&state->processed_options); - list_init(&processed_conf_files); - /* * set the global defaults * by spec 'default' defaults to 'linux' and @@ -463,37 +454,21 @@ static int syslinux_parse(struct discover_context *dc) conf_set_global_option(conf, "implicit", "1"); for (filename = syslinux_conf_files; *filename; filename++) { + char *cfg_dir; + int len, rc; + char *buf; + /* * guard against duplicate entries in case-insensitive * filesystems, mainly vfat boot partitions */ - rc = parser_stat_path(dc->device, *filename, &statbuf); - if (rc) - continue; - - rc = 0; - - list_for_each_entry(&processed_conf_files, confcmp, list) { - if (confcmp->stat.st_ino == statbuf.st_ino) { - pb_log("conf file %s is a path duplicate of %s..skipping\n", - *filename, confcmp->name); - rc = 1; - break; - } - } - - if (rc) + if (!parser_is_unique(dc->device, *filename, found_list)) continue; rc = parser_request_file(dc, dc->device, *filename, &buf, &len); if (rc) continue; - confdat = talloc_zero(conf, struct conf_file_stat); - confdat->stat = statbuf; - confdat->name = talloc_strdup(confdat, *filename); - list_add(&processed_conf_files, &confdat->list); - /* * save location of root config file for possible * INCLUDE directives later