From owner-dev-commits-src-branches@freebsd.org Sun Jan 24 03:07:28 2021 Return-Path: Delivered-To: dev-commits-src-branches@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 4214A4E8E01; Sun, 24 Jan 2021 03:07:28 +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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4DNdG81FRhz3rCS; Sun, 24 Jan 2021 03:07:28 +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 1D8CF1C270; Sun, 24 Jan 2021 03:07:28 +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 10O37SRR015163; Sun, 24 Jan 2021 03:07:28 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 10O37Sun015162; Sun, 24 Jan 2021 03:07:28 GMT (envelope-from git) Date: Sun, 24 Jan 2021 03:07:28 GMT Message-Id: <202101240307.10O37Sun015162@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Kyle Evans Subject: git: d9cc55ea82fa - stable/12 - 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/stable/12 X-Git-Reftype: branch X-Git-Commit: d9cc55ea82faf6b7660d9a715b936657c6e6a8af Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 24 Jan 2021 03:07:28 -0000 The branch stable/12 has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=d9cc55ea82faf6b7660d9a715b936657c6e6a8af commit d9cc55ea82faf6b7660d9a715b936657c6e6a8af Author: Kyle Evans AuthorDate: 2020-07-10 01:50:15 +0000 Commit: Kyle Evans 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