From owner-svn-src-stable-11@freebsd.org Sat Aug 4 22:12:13 2018 Return-Path: Delivered-To: svn-src-stable-11@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 1C1581054EC6; Sat, 4 Aug 2018 22:12:13 +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 C6A4A8AEC9; Sat, 4 Aug 2018 22:12:12 +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 A7D4A1572E; Sat, 4 Aug 2018 22:12:12 +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 w74MCCe7061697; Sat, 4 Aug 2018 22:12:12 GMT (envelope-from kevans@FreeBSD.org) Received: (from kevans@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w74MCC5W061696; Sat, 4 Aug 2018 22:12:12 GMT (envelope-from kevans@FreeBSD.org) Message-Id: <201808042212.w74MCC5W061696@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kevans set sender to kevans@FreeBSD.org using -f From: Kyle Evans Date: Sat, 4 Aug 2018 22:12:12 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r337335 - stable/11/usr.sbin/config X-SVN-Group: stable-11 X-SVN-Commit-Author: kevans X-SVN-Commit-Paths: stable/11/usr.sbin/config X-SVN-Commit-Revision: 337335 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-11@freebsd.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: SVN commit messages for only the 11-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 04 Aug 2018 22:12:13 -0000 Author: kevans Date: Sat Aug 4 22:12:12 2018 New Revision: 337335 URL: https://svnweb.freebsd.org/changeset/base/337335 Log: MFC r336973-r336975 r336973: 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. r336974: Re-insert variable disappeared during mis-application of r336973 r336975: Remove variable re-inserted during mis-application of r336973 Modified: stable/11/usr.sbin/config/mkmakefile.c Directory Properties: stable/11/ (props changed) Modified: stable/11/usr.sbin/config/mkmakefile.c ============================================================================== --- stable/11/usr.sbin/config/mkmakefile.c Sat Aug 4 22:08:24 2018 (r337334) +++ stable/11/usr.sbin/config/mkmakefile.c Sat Aug 4 22:12:12 2018 (r337335) @@ -63,6 +63,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); @@ -241,16 +242,29 @@ 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 *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 @@ -258,15 +272,13 @@ process_into_nvlist(char *line, nvlist_t *nvl) { char result[BUFSIZ], *s; - 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