Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 24 Jan 2021 03:07:28 GMT
From:      Kyle Evans <kevans@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
Subject:   git: d9cc55ea82fa - stable/12 - lualoader: add loader_conf_dirs support (loader.conf.d)
Message-ID:  <202101240307.10O37Sun015162@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch stable/12 has been updated by kevans:

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

commit d9cc55ea82faf6b7660d9a715b936657c6e6a8af
Author:     Kyle Evans <kevans@FreeBSD.org>
AuthorDate: 2020-07-10 01:50:15 +0000
Commit:     Kyle Evans <kevans@FreeBSD.org>
CommitDate: 2021-01-24 03:07:12 +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.
    
    Relnotes:       yes
    
    (cherry picked from commit 72cf7db3aaf17db412183886f19320e5074dc8b7)
---
 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 41a68c27aa7a..cba3e9e73c79 100644
--- a/etc/mtree/BSD.root.dist
+++ b/etc/mtree/BSD.root.dist
@@ -20,6 +20,8 @@
         ..
         firmware
         ..
+        loader.conf.d             tags=package=bootloader
+        ..
         lua
         ..
         kernel
diff --git a/stand/defaults/loader.conf b/stand/defaults/loader.conf
index 4f84281e9d2e..a1eb189db7ac 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"
 nextboot_enable="NO"
 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 3b31761663e3..3bd83dcc5c30 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
@@ -88,6 +88,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.
@@ -253,6 +258,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 5b554806fc9f..683490cfd23d 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'"
@@ -497,6 +498,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
@@ -520,6 +523,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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202101240307.10O37Sun015162>