git: 72cf7db3aaf1 - main - lualoader: add loader_conf_dirs support (loader.conf.d)

Kyle Evans kevans at FreeBSD.org
Thu Dec 31 16:37:13 UTC 2020


The branch main has been updated by kevans:

URL: https://cgit.FreeBSD.org/src/commit/?id=72cf7db3aaf17db412183886f19320e5074dc8b7

commit 72cf7db3aaf17db412183886f19320e5074dc8b7
Author:     Kyle Evans <kevans at FreeBSD.org>
AuthorDate: 2020-07-10 01:50:15 +0000
Commit:     Kyle Evans <kevans at FreeBSD.org>
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


More information about the dev-commits-src-all mailing list