From patchwork Fri Dec 2 03:58:29 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: NeilBrown X-Patchwork-Id: 9457761 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 769066074E for ; Fri, 2 Dec 2016 03:59:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6A81C28489 for ; Fri, 2 Dec 2016 03:59:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5DE8328505; Fri, 2 Dec 2016 03:59:38 +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 08A8B28489 for ; Fri, 2 Dec 2016 03:59:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752118AbcLBD7h (ORCPT ); Thu, 1 Dec 2016 22:59:37 -0500 Received: from mx2.suse.de ([195.135.220.15]:36481 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751164AbcLBD7g (ORCPT ); Thu, 1 Dec 2016 22:59:36 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id B7840AAA3; Fri, 2 Dec 2016 03:59:35 +0000 (UTC) From: NeilBrown To: "J. Bruce Fields" , Steve Dickson Date: Fri, 02 Dec 2016 14:58:29 +1100 Subject: [PATCH 08/15] conffile: split loading of file into a separate function. Cc: linux-nfs@vger.kernel.org Message-ID: <148065110933.28046.17029087040756427181.stgit@noble> In-Reply-To: <148065078775.28046.5506130555300891075.stgit@noble> References: <148065078775.28046.5506130555300891075.stgit@noble> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 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 This will make support of include files easier. Signed-off-by: NeilBrown --- support/nfs/conffile.c | 47 ++++++++++++++++++++++++++--------------------- 1 file changed, 26 insertions(+), 21 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/support/nfs/conffile.c b/support/nfs/conffile.c index e4597507b922..965726c74f6b 100644 --- a/support/nfs/conffile.c +++ b/support/nfs/conffile.c @@ -366,23 +366,18 @@ conf_init (void) conf_reinit(); } -/* Open the config file and map it into our address space, then parse it. */ -void -conf_reinit(void) +static int +conf_load(int trans, char *path) { - struct conf_binding *cb = 0; - int fd, trans; - unsigned int i; - size_t sz; - char *new_conf_addr = 0; struct stat sb; + if ((stat (path, &sb) == 0) || (errno != ENOENT)) { + char *new_conf_addr; + size_t sz = sb.st_size; + int fd = open (path, O_RDONLY, 0); - if ((stat (conf_path, &sb) == 0) || (errno != ENOENT)) { - sz = sb.st_size; - fd = open (conf_path, O_RDONLY, 0); if (fd == -1) { - xlog_warn("conf_reinit: open (\"%s\", O_RDONLY) failed", conf_path); - return; + xlog_warn("conf_reinit: open (\"%s\", O_RDONLY) failed", path); + return -1; } new_conf_addr = malloc(sz); @@ -399,13 +394,28 @@ conf_reinit(void) } close(fd); - trans = conf_begin(); /* XXX Should we not care about errors and rollback? */ conf_parse(trans, new_conf_addr, sz); free(new_conf_addr); + return 0; + fail: + close(fd); + free(new_conf_addr); } - else - trans = conf_begin(); + return -1; +} + +/* Open the config file and map it into our address space, then parse it. */ +void +conf_reinit(void) +{ + struct conf_binding *cb = 0; + int trans; + unsigned int i; + + trans = conf_begin(); + if (conf_load(trans, conf_path) < 0) + return; /* Load default configuration values. */ conf_load_defaults(); @@ -419,11 +429,6 @@ conf_reinit(void) conf_end(trans, 1); return; - -fail: - if (new_conf_addr) - free(new_conf_addr); - close (fd); } /*