From patchwork Wed Aug 30 11:54:00 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Justin Mitchell X-Patchwork-Id: 9929377 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id CCB156022E for ; Wed, 30 Aug 2017 11:54:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B9ED6284B5 for ; Wed, 30 Aug 2017 11:54:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AEC7F284C4; Wed, 30 Aug 2017 11:54:04 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 45FCA284B5 for ; Wed, 30 Aug 2017 11:54:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751318AbdH3LyD (ORCPT ); Wed, 30 Aug 2017 07:54:03 -0400 Received: from mx1.redhat.com ([209.132.183.28]:41350 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751300AbdH3LyD (ORCPT ); Wed, 30 Aug 2017 07:54:03 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1547734C0 for ; Wed, 30 Aug 2017 11:54:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 1547734C0 Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=jumitche@redhat.com Received: from jumitche.remote.csb (unknown [10.33.36.51]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6BA6C708F7; Wed, 30 Aug 2017 11:54:02 +0000 (UTC) Message-ID: <1504094040.10850.4.camel@redhat.com> Subject: [PATCH 2/7] nfs-utils: Merge conf_get_str and conf_get_section From: Justin Mitchell To: Steve Dickson Cc: linux-nfs@vger.kernel.org Date: Wed, 30 Aug 2017 12:54:00 +0100 In-Reply-To: <1504093866.10850.1.camel@redhat.com> References: <1504093866.10850.1.camel@redhat.com> Mime-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Wed, 30 Aug 2017 11:54:03 +0000 (UTC) Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP conf_get_section() started as conf_get_str() with one extra search parameter, subsequent patches have not maintained feature parity, combine the code to make a single more generic function and just call that differently where required. Signed-off-by: Justin Mitchell --- support/nfs/conffile.c | 36 ++++++++++++++---------------------- 1 file changed, 14 insertions(+), 22 deletions(-) diff --git a/support/nfs/conffile.c b/support/nfs/conffile.c index 527a63e..d8c4374 100644 --- a/support/nfs/conffile.c +++ b/support/nfs/conffile.c @@ -634,28 +634,9 @@ conf_match_num(const char *section, const char *tag, int x) char * conf_get_str(const char *section, const char *tag) { - struct conf_binding *cb; -retry: - cb = LIST_FIRST (&conf_bindings[conf_hash (section)]); - for (; cb; cb = LIST_NEXT (cb, link)) { - if (strcasecmp (section, cb->section) == 0 - && strcasecmp (tag, cb->tag) == 0) { - if (cb->value[0] == '$') { - /* expand $name from [environment] section, - * or from environment - */ - char *env = getenv(cb->value+1); - if (env && *env) - return env; - section = "environment"; - tag = cb->value + 1; - goto retry; - } - return cb->value; - } - } - return 0; + return conf_get_section(section, NULL, tag); } + /* * Find a section that may or may not have an argument */ @@ -663,7 +644,7 @@ char * conf_get_section(const char *section, const char *arg, const char *tag) { struct conf_binding *cb; - +retry: cb = LIST_FIRST (&conf_bindings[conf_hash (section)]); for (; cb; cb = LIST_NEXT (cb, link)) { if (strcasecmp(section, cb->section) != 0) @@ -672,6 +653,17 @@ conf_get_section(const char *section, const char *arg, const char *tag) continue; if (strcasecmp(tag, cb->tag) != 0) continue; + if (cb->value[0] == '$') { + /* expand $name from [environment] section, + * or from environment + */ + char *env = getenv(cb->value+1); + if (env && *env) + return env; + section = "environment"; + tag = cb->value + 1; + goto retry; + } return cb->value; } return 0;