From patchwork Fri Dec 2 03:58:28 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: NeilBrown X-Patchwork-Id: 9457749 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 97F1C6074E for ; Fri, 2 Dec 2016 03:59:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8D64128489 for ; Fri, 2 Dec 2016 03:59:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8280628505; Fri, 2 Dec 2016 03:59:03 +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 2A88028489 for ; Fri, 2 Dec 2016 03:59:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751606AbcLBD7C (ORCPT ); Thu, 1 Dec 2016 22:59:02 -0500 Received: from mx2.suse.de ([195.135.220.15]:36374 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751316AbcLBD7C (ORCPT ); Thu, 1 Dec 2016 22:59:02 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id AEB16AAA3; Fri, 2 Dec 2016 03:59:00 +0000 (UTC) From: NeilBrown To: "J. Bruce Fields" , Steve Dickson Date: Fri, 02 Dec 2016 14:58:28 +1100 Subject: [PATCH 02/15] conffile: add bool support Cc: linux-nfs@vger.kernel.org Message-ID: <148065110812.28046.17685846656088587454.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 conf_get_bool() interprets various strings as 'true' or 'false'. If no suitable value is found, the default is returned. Signed-off-by: NeilBrown --- support/include/conffile.h | 2 ++ support/nfs/conffile.c | 32 ++++++++++++++++++++++++++++++++ systemd/nfs.conf.man | 16 ++++++++++++++++ 3 files changed, 50 insertions(+) -- 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/include/conffile.h b/support/include/conffile.h index a6d5846f6720..3fe3a78230f6 100644 --- a/support/include/conffile.h +++ b/support/include/conffile.h @@ -36,6 +36,7 @@ #include #include #include +#include struct conf_list_node { TAILQ_ENTRY(conf_list_node) link; @@ -57,6 +58,7 @@ extern struct sockaddr *conf_get_address(char *, char *); extern struct conf_list *conf_get_list(char *, char *); extern struct conf_list *conf_get_tag_list(char *, char *); extern int conf_get_num(char *, char *, int); +extern _Bool conf_get_bool(char *, char *, _Bool); extern char *conf_get_str(char *, char *); extern char *conf_get_section(char *, char *, char *); extern void conf_init(void); diff --git a/support/nfs/conffile.c b/support/nfs/conffile.c index 6b94ec0b5b53..609d78294f35 100644 --- a/support/nfs/conffile.c +++ b/support/nfs/conffile.c @@ -446,6 +446,38 @@ conf_get_num(char *section, char *tag, int def) return def; } +/* + * Return the Boolean value denoted by TAG in section SECTION, or DEF + * if that tags does not exist. + * FALSE is returned for case-insensitve comparisons with 0, f, false, n, no, off + * TRUE is returned for 1, t, true, y, yes, on + * A failure to match one of these results in DEF + */ +_Bool +conf_get_bool(char *section, char *tag, _Bool def) +{ + char *value = conf_get_str(section, tag); + + if (!value) + return def; + if (strcasecmp(value, "1") == 0 || + strcasecmp(value, "t") == 0 || + strcasecmp(value, "true") == 0 || + strcasecmp(value, "y") == 0 || + strcasecmp(value, "yes") == 0 || + strcasecmp(value, "on") == 0) + return true; + + if (strcasecmp(value, "0") == 0 || + strcasecmp(value, "f") == 0 || + strcasecmp(value, "false") == 0 || + strcasecmp(value, "n") == 0 || + strcasecmp(value, "no") == 0 || + strcasecmp(value, "off") == 0) + return false; + return def; +} + /* Validate X according to the range denoted by TAG in section SECTION. */ int conf_match_num(char *section, char *tag, int x) diff --git a/systemd/nfs.conf.man b/systemd/nfs.conf.man index 3dd56f735de2..1f524d8fe74e 100644 --- a/systemd/nfs.conf.man +++ b/systemd/nfs.conf.man @@ -44,6 +44,22 @@ is ignored, as is any blank line. .PP Lookup of section and value names is case-insensitive. +Where a Boolean value is expected, any of +.BR true , +.BR t , +.BR yes , +.BR y , +.BR on ", or" +.B 1 +can be used for "true", while +.BR false , +.BR f , +.BR no , +.BR n , +.BR off ", or" +.B 0 +can be used for "false". Comparisons are case-insensitive. + .SH SECTIONS The following sections are known to various programs, and can contain the given named values.