From owner-svn-src-all@freebsd.org Tue Jun 26 03:56:12 2018 Return-Path: Delivered-To: svn-src-all@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 88C5F10094DE; Tue, 26 Jun 2018 03:56:12 +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 3CBDE7C784; Tue, 26 Jun 2018 03:56: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 1EE6C7008; Tue, 26 Jun 2018 03:56: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 w5Q3uBFP034245; Tue, 26 Jun 2018 03:56:11 GMT (envelope-from kevans@FreeBSD.org) Received: (from kevans@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w5Q3uB64034240; Tue, 26 Jun 2018 03:56:11 GMT (envelope-from kevans@FreeBSD.org) Message-Id: <201806260356.w5Q3uB64034240@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kevans set sender to kevans@FreeBSD.org using -f From: Kyle Evans Date: Tue, 26 Jun 2018 03:56:11 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r335652 - 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: 335652 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 26 Jun 2018 03:56:12 -0000 Author: kevans Date: Tue Jun 26 03:56:10 2018 New Revision: 335652 URL: https://svnweb.freebsd.org/changeset/base/335652 Log: config(8): Make 'env' files consistent with other file-accepting options Previously, only one 'env' file could be specified. Later 'env' directives would overwrite earlier 'env' directives. This is inconsistent with every other file-accepting directives which process files in order, including hints. A caveat applies to both hints and env that isn't mentioned: they're concatenated in the order of appearance, so they're not actually applied in the way one might think by supplying: hints x hints y Hints in x will take precedence over same-name hints in y due to how the kernel processes them, stopping at the first line that matches the hint we're searching for. Future work will flip the order of concatenation so that later files may still properly override earlier files. In practice, this likely doesn't matter at all due to the nature of the beast. Modified: head/usr.sbin/config/config.5 head/usr.sbin/config/config.h head/usr.sbin/config/config.y head/usr.sbin/config/mkmakefile.c Modified: head/usr.sbin/config/config.5 ============================================================================== --- head/usr.sbin/config/config.5 Tue Jun 26 02:05:45 2018 (r335651) +++ head/usr.sbin/config/config.5 Tue Jun 26 03:56:10 2018 (r335652) @@ -23,7 +23,7 @@ .\" .\" $FreeBSD$ .\" -.Dd June 22, 2018 +.Dd June 26, 2018 .Dt CONFIG 5 .Os .Sh NAME @@ -124,6 +124,18 @@ the compiled-in environment instead, unless the boot e This directive is useful for setting kernel tunables in embedded environments that do not start from .Xr loader 8 . +.Pp +All +.Ic env +and +.Ic envvar +directives will be processed and added to the staitc environment in the order of +appearance. +Note that within +.Ar filename , +the first appearance of a given variable will be the first one seen by the +kernel, effectively shadowing any later appearances of the same variable within +.Ar filename . .\" -------- ENVVAR -------- .Pp .It Ic envvar Ar setting @@ -133,11 +145,13 @@ compiled-in environment. must be of the form .Dq Va name=value . Optional quotes are supported in both name and value. -All environment variables specified with -.Ic envvar -will be set after any +.Pp +All .Ic env -files are included. +and +.Ic envvar +directives will be processed and added to the staitc environment in the order of +appearance. .\" -------- FILES -------- .Pp .It Ic files Ar filename Modified: head/usr.sbin/config/config.h ============================================================================== --- head/usr.sbin/config/config.h Tue Jun 26 02:05:45 2018 (r335651) +++ head/usr.sbin/config/config.h Tue Jun 26 03:56:10 2018 (r335652) @@ -37,6 +37,7 @@ */ #include #include +#include #include #include @@ -142,6 +143,7 @@ SLIST_HEAD(, opt_list) otab; struct envvar { char *env_str; + bool env_is_file; STAILQ_ENTRY(envvar) envvar_next; }; @@ -175,7 +177,6 @@ SLIST_HEAD(, includepath) includepath; #define OPT_AUTOGEN "CONFIG_AUTOGENERATED" extern char *ident; -extern char *env; extern char kernconfstr[]; extern int do_trace; extern int envmode; Modified: head/usr.sbin/config/config.y ============================================================================== --- head/usr.sbin/config/config.y Tue Jun 26 02:05:45 2018 (r335651) +++ head/usr.sbin/config/config.y Tue Jun 26 03:56:10 2018 (r335652) @@ -82,7 +82,6 @@ struct device_head dtab; char *ident; -char *env; int envmode; int hintmode; int yyline; @@ -99,6 +98,7 @@ int yywrap(void); static void newdev(char *name); static void newfile(char *name); +static void newenvvar(char *name, bool is_file); static void rmdev_schedule(struct device_head *dh, char *name); static void newopt(struct opt_head *list, char *name, char *value, int append); static void rmopt_schedule(struct opt_head *list, char *name); @@ -191,20 +191,8 @@ Config_spec: | MAXUSERS NUMBER { maxusers = $2; } | PROFILE NUMBER { profiling = $2; } | - ENV ID { - env = $2; - envmode = 1; - } | - ENVVAR ENVLINE { - struct envvar *envvar; - - envvar = (struct envvar *)calloc(1, sizeof (struct envvar)); - if (envvar == NULL) - err(EXIT_FAILURE, "calloc"); - envvar->env_str = $2; - STAILQ_INSERT_TAIL(&envvars, envvar, envvar_next); - envmode = 1; - } | + ENV ID { newenvvar($2, true); } | + ENVVAR ENVLINE { newenvvar($2, false); } | HINTS ID { struct hint *hint; @@ -361,7 +349,21 @@ newfile(char *name) nl->f_name = name; STAILQ_INSERT_TAIL(&fntab, nl, f_next); } - + +static void +newenvvar(char *name, bool is_file) +{ + struct envvar *envvar; + + envvar = (struct envvar *)calloc(1, sizeof (struct envvar)); + if (envvar == NULL) + err(EXIT_FAILURE, "calloc"); + envvar->env_str = name; + envvar->env_is_file = is_file; + STAILQ_INSERT_TAIL(&envvars, envvar, envvar_next); + envmode = 1; +} + /* * Find a device in the list of devices. */ Modified: head/usr.sbin/config/mkmakefile.c ============================================================================== --- head/usr.sbin/config/mkmakefile.c Tue Jun 26 02:05:45 2018 (r335651) +++ head/usr.sbin/config/mkmakefile.c Tue Jun 26 03:56:10 2018 (r335652) @@ -306,13 +306,6 @@ makeenv(void) char line[BUFSIZ], result[BUFSIZ], *linep; struct envvar *envvar; - if (env) { - ifp = fopen(env, "r"); - if (ifp == NULL) - err(1, "%s", env); - } else { - ifp = NULL; - } ofp = fopen(path("env.c.new"), "w"); if (ofp == NULL) err(1, "%s", path("env.c.new")); @@ -321,21 +314,26 @@ makeenv(void) fprintf(ofp, "\n"); fprintf(ofp, "int envmode = %d;\n", envmode); fprintf(ofp, "char static_env[] = {\n"); - if (ifp) { - while (fgets(line, BUFSIZ, ifp) != NULL) { - sanitize_envline(result, line); - /* anything left? */ + STAILQ_FOREACH(envvar, &envvars, envvar_next) { + if (envvar->env_is_file) { + ifp = fopen(envvar->env_str, "r"); + if (ifp == NULL) + err(1, "%s", envvar->env_str); + while (fgets(line, BUFSIZ, ifp) != NULL) { + sanitize_envline(result, line); + /* anything left? */ + if (*result == '\0') + continue; + fprintf(ofp, "\"%s\\0\"\n", result); + } + fclose(ifp); + } else { + linep = envvar->env_str; + sanitize_envline(result, linep); if (*result == '\0') continue; fprintf(ofp, "\"%s\\0\"\n", result); } - } - STAILQ_FOREACH(envvar, &envvars, envvar_next) { - linep = envvar->env_str; - sanitize_envline(result, linep); - if (*result == '\0') - continue; - fprintf(ofp, "\"%s\\0\"\n", result); } fprintf(ofp, "\"\\0\"\n};\n"); if (ifp)