From owner-svn-src-head@freebsd.org Tue Jul 31 16:03:31 2018 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 15210105D80D; Tue, 31 Jul 2018 16:03:31 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id BF1768FFDE; Tue, 31 Jul 2018 16:03:30 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id A0C6715D34; Tue, 31 Jul 2018 16:03:30 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w6VG3UoK078683; Tue, 31 Jul 2018 16:03:30 GMT (envelope-from kevans@FreeBSD.org) Received: (from kevans@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w6VG3UiA078682; Tue, 31 Jul 2018 16:03:30 GMT (envelope-from kevans@FreeBSD.org) Message-Id: <201807311603.w6VG3UiA078682@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kevans set sender to kevans@FreeBSD.org using -f From: Kyle Evans Date: Tue, 31 Jul 2018 16:03:30 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r336973 - head/usr.sbin/config X-SVN-Group: head X-SVN-Commit-Author: kevans X-SVN-Commit-Paths: head/usr.sbin/config X-SVN-Commit-Revision: 336973 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 31 Jul 2018 16:03:31 -0000 Author: kevans Date: Tue Jul 31 16:03:30 2018 New Revision: 336973 URL: https://svnweb.freebsd.org/changeset/base/336973 Log: config(8): Strip comments from env lines Consolidates the small bits of logic required for preprocessing a line before inclusion into a file or nvlist. Modified: head/usr.sbin/config/mkmakefile.c Modified: head/usr.sbin/config/mkmakefile.c ============================================================================== --- head/usr.sbin/config/mkmakefile.c Tue Jul 31 15:25:03 2018 (r336972) +++ head/usr.sbin/config/mkmakefile.c Tue Jul 31 16:03:30 2018 (r336973) @@ -65,6 +65,7 @@ static void do_before_depend(FILE *); static int opteq(const char *, const char *); static void read_files(void); static void sanitize_envline(char *result, const char *src); +static bool preprocess(char *line, char *result); static void process_into_file(char *line, FILE *ofp); static void process_into_nvlist(char *line, nvlist_t *nvl); static void dump_nvlist(nvlist_t *nvl, FILE *ofp); @@ -243,32 +244,44 @@ sanitize_envline(char *result, const char *src) *dst = 0; } +/* + * Returns true if the caller may use the string. + */ +static bool +preprocess(char *line, char *result) +{ + + char result[BUFSIZ], *s; + + /* Strip any comments */ + if ((s = strchr(line, '#')) != NULL) + *s = '\0'; + sanitize_envline(result, line); + /* Return true if it's non-empty */ + return (*result != '\0'); +} + static void process_into_file(char *line, FILE *ofp) { char result[BUFSIZ]; - sanitize_envline(result, line); - /* anything left? */ - if (*result == '\0') - return; - fprintf(ofp, "\"%s\\0\"\n", result); + if (preprocess(line, result)) + fprintf(ofp, "\"%s\\0\"\n", result); } static void process_into_nvlist(char *line, nvlist_t *nvl) { - char result[BUFSIZ], *s; + char result[BUFSIZ]; - sanitize_envline(result, line); - /* anything left? */ - if (*result == '\0') - return; - s = strchr(result, '='); - *s = 0; - if (nvlist_exists(nvl, result)) - nvlist_free(nvl, result); - nvlist_add_string(nvl, result, s + 1); + if (preprocess(line, result)) { + s = strchr(result, '='); + *s = '\0'; + if (nvlist_exists(nvl, result)) + nvlist_free(nvl, result); + nvlist_add_string(nvl, result, s + 1); + } } static void