From owner-dev-commits-src-all@freebsd.org Thu Dec 31 16:37:13 2020 Return-Path: Delivered-To: dev-commits-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 5A7944C714D; Thu, 31 Dec 2020 16:37:13 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4D6DMY2695z3FlR; Thu, 31 Dec 2020 16:37:13 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 3AAB313A97; Thu, 31 Dec 2020 16:37:13 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 0BVGbDcq043612; Thu, 31 Dec 2020 16:37:13 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 0BVGbDYN043611; Thu, 31 Dec 2020 16:37:13 GMT (envelope-from git) Date: Thu, 31 Dec 2020 16:37:13 GMT Message-Id: <202012311637.0BVGbDYN043611@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Kyle Evans Subject: git: 72cf7db3aaf1 - main - lualoader: add loader_conf_dirs support (loader.conf.d) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kevans X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 72cf7db3aaf17db412183886f19320e5074dc8b7 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-all@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for all branches of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 31 Dec 2020 16:37:13 -0000 The branch main has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=72cf7db3aaf17db412183886f19320e5074dc8b7 commit 72cf7db3aaf17db412183886f19320e5074dc8b7 Author: Kyle Evans AuthorDate: 2020-07-10 01:50:15 +0000 Commit: Kyle Evans CommitDate: 2020-12-31 16:37:05 +0000 lualoader: add loader_conf_dirs support (loader.conf.d) loader_conf_dirs is the supporting mechanism for the included /boot/loader.conf.d directory. When lualoader finishes processing all of the loader_conf_files it finds after walking /boot/defaults/loader.conf, it will now check any and all loader_conf_dirs and process files ending in ".conf" as if they were a loader.conf. Note that loader_conf_files may be specified in a loader.conf.d config file, but loader_conf_dirs may *not*. It will only be processed as specified in /boot/defaults/loader.conf and any loader_conf_files that were loaded from there. Reviewed by: allanjude, freqlabs, rpokala, tsoome Includes suggestion from: imp Relnotes: yes Differential Revision: https://reviews.freebsd.org/D25608 --- etc/mtree/BSD.root.dist | 2 ++ stand/defaults/loader.conf | 1 + stand/defaults/loader.conf.5 | 9 ++++++++- stand/lua/config.lua | 24 ++++++++++++++++++++++++ 4 files changed, 35 insertions(+), 1 deletion(-) diff --git a/etc/mtree/BSD.root.dist b/etc/mtree/BSD.root.dist index f93d36a9128d..7e5917c049b9 100644 --- a/etc/mtree/BSD.root.dist +++ b/etc/mtree/BSD.root.dist @@ -22,6 +22,8 @@ .. firmware .. + loader.conf.d tags=package=bootloader + .. lua .. kernel diff --git a/stand/defaults/loader.conf b/stand/defaults/loader.conf index 55f9983dfc8b..7bca621e6703 100644 --- a/stand/defaults/loader.conf +++ b/stand/defaults/loader.conf @@ -15,6 +15,7 @@ kernel="kernel" # /boot sub-directory containing kernel and modules bootfile="kernel" # Kernel name (possibly absolute path) kernel_options="" # Flags to be passed to the kernel loader_conf_files="/boot/device.hints /boot/loader.conf /boot/loader.conf.local" +loader_conf_dirs="/boot/loader.conf.d" nextboot_conf="/boot/nextboot.conf" verbose_loading="NO" # Set to YES for verbose loader output diff --git a/stand/defaults/loader.conf.5 b/stand/defaults/loader.conf.5 index 35e59bc920c6..1053191ec181 100644 --- a/stand/defaults/loader.conf.5 +++ b/stand/defaults/loader.conf.5 @@ -23,7 +23,7 @@ .\" SUCH DAMAGE. .\" .\" $FreeBSD$ -.Dd April 29, 2020 +.Dd December 31, 2020 .Dt LOADER.CONF 5 .Os .Sh NAME @@ -87,6 +87,11 @@ than so its use should be avoided. Multiple instances of it will be processed independently. +.It Ar loader_conf_dirs +Space separated list of directories to process for configuration files. +The lua-based loader will process files with a +.Dq .conf +suffix that are placed in these directories. .It Ar loader_conf_files Defines additional configuration files to be processed right after the present file. @@ -252,6 +257,8 @@ The following values are accepted: Space or comma separated list of kernels to present in the boot menu. .It Va loader_conf_files .Pq Dq Pa /boot/loader.conf /boot/loader.conf.local +.It Va loader_conf_dirs +.Pq Dq Pa /boot/loader.conf.d .It Va splash_bmp_load .Pq Dq NO If set to diff --git a/stand/lua/config.lua b/stand/lua/config.lua index 2eb10f7c7727..095d354c637b 100644 --- a/stand/lua/config.lua +++ b/stand/lua/config.lua @@ -39,6 +39,7 @@ local env_changed = {} -- Values to restore env to (nil to unset) local env_restore = {} +local MSG_FAILDIR = "Failed to load conf dir '%s': not a directory" local MSG_FAILEXEC = "Failed to exec '%s'" local MSG_FAILSETENV = "Failed to '%s' with value: %s" local MSG_FAILOPENCFG = "Failed to open config: '%s'" @@ -506,6 +507,8 @@ function config.readConf(file, loaded_files) return end + -- We'll process loader_conf_dirs at the top-level readConf + local load_conf_dirs = next(loaded_files) == nil print("Loading " .. file) -- The final value of loader_conf_files is not important, so just @@ -529,6 +532,27 @@ function config.readConf(file, loaded_files) config.readConf(name, loaded_files) end end + + if load_conf_dirs then + local loader_conf_dirs = getEnv("loader_conf_dirs") + if loader_conf_dirs ~= nil then + for name in loader_conf_dirs:gmatch("[%w%p]+") do + if lfs.attributes(name, "mode") ~= "directory" then + print(MSG_FAILDIR:format(name)) + goto nextdir + end + for cfile in lfs.dir(name) do + if cfile:match(".conf$") then + local fpath = name .. "/" .. cfile + if lfs.attributes(fpath, "mode") == "file" then + config.readConf(fpath, loaded_files) + end + end + end + ::nextdir:: + end + end + end end -- other_kernel is optionally the name of a kernel to load, if not the default