From nobody Tue Apr 16 20:12:29 2024 X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4VJwFB20v7z5H0DY; Tue, 16 Apr 2024 20:12:30 +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 4VJwF95Xzxz4sTP; Tue, 16 Apr 2024 20:12:29 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1713298349; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Qf3umVbnN9Q6daPHGdVUaVVN2QuNBQSqAttSyQKqblg=; b=Qkh/XvrbIMxlZyLsitaE/urBcQxGbIGpVMxGM+qeSm9oXr/uPMmtFUy/2TqDrhf3fmg7DZ UZ2KNKmjD7B1YgaK5XMVL0nTsPv39agVvs8RAtYFBcJV/P8KZLWhCzW8nVTs7FiYpobp2j w+puetduVSRDM/SuMvrgt/wbUZIf2BWtq4TtM04+GwFB4IUIAFL/XyTgUVNsDItTpEZIiR PDk2A3lqKNEz9vQbcyVIeYHsrHaKb3y+XagecRRuXkqo//rXgSdhMbNpPLDLgWrSe4TfuI QGJrZJ4OCxWtZZTK4Y0Ud95t+c4QCAoEHe72xaXQ+lQj+dXOM4qeB+7k6MIK/A== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1713298349; a=rsa-sha256; cv=none; b=uRD2YJGCQIiD5ac0lcCA2SFT/Q9bH8x9X4ipEBzY8ehHCvUW+IWcxWrjUVndFf9ZGfyF7P i5u3Zu2X3V0BCpmBQN49TREooCu4w1C6y4woVZrsxVHJp2Vo8P42I2I8sqKoR/YUxoCqMf ETngi1bk/uqvcD5m+lGT7Z2nwLN8mg9gVPolQs4DbvgGqrCUizjLxDBOgXbVDH76OM+FlD wsNc5sSfx6+CrnsOzmI4McyWpgdOf2iwSMjvZoQ9l2lZCt+gDnSP68jFFwoLLYyBXlGgNr pUFAB6Zzy2O/T0kQvD9qTt2EnSxQ4VIEjKQMn7A+AWdpMhaR/VihWN0q2Lm7yw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1713298349; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Qf3umVbnN9Q6daPHGdVUaVVN2QuNBQSqAttSyQKqblg=; b=VSbLNbDus/TiivKjq9YlXhqNRj3WwnqKh1OCNeRqjGQPrD/KEjqZXj/eMewYW51rHEPGCB ao2lY4CRYvQNYHdK9kFf2UyCqZLnvXMUOEAKBjDvkp25kzAKoSE9ha0IkrbluFZB76nb9U qPgujAX7ujmXWHVvAtq88HR2QBvGZCHdWAUtEd4pZEgT70RCyEquFng68OUDumORMC7dFJ LlGcHCyoMAh23qgFMNemG1OSvQ3yUXam9nZ9lU/q8ml1N6cjkCYkyrAMuHWqzufVf0QyqV 6sFxBHU8Q2hSLCffsEt+ZDSylZ7j4tYwiKbvfcCrH/YDFG1mPepTv8JJFdO4hg== 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 4VJwF959DdzxXw; Tue, 16 Apr 2024 20:12:29 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 43GKCTwN037081; Tue, 16 Apr 2024 20:12:29 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 43GKCTlP037078; Tue, 16 Apr 2024 20:12:29 GMT (envelope-from git) Date: Tue, 16 Apr 2024 20:12:29 GMT Message-Id: <202404162012.43GKCTlP037078@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Warner Losh Subject: git: 3eb3a802a31b - stable/14 - stand/lua: per-product conf if requested via product_vars List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-branches@freebsd.org Sender: owner-dev-commits-src-branches@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: imp X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: 3eb3a802a31ba84d70e1be50c793ec34bec3614f Auto-Submitted: auto-generated The branch stable/14 has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=3eb3a802a31ba84d70e1be50c793ec34bec3614f commit 3eb3a802a31ba84d70e1be50c793ec34bec3614f Author: Stéphane Rochoy AuthorDate: 2023-05-04 07:23:47 +0000 Commit: Warner Losh CommitDate: 2024-04-16 19:54:21 +0000 stand/lua: per-product conf if requested via product_vars If product_vars is set, it must be a space separated list of environment variable names to walk through to guess the product. Each time a product can be guessed (i.e., the corresponding variable is defined), prepend /boot/loader.conf.d/PRODUCT/ to loader_conf_dirs. It can be typically used as follow: smbios.system.planar.maker="PLANAR_MAKER" smbios.system.planar.product="PLANAR_PRODUCT" smbios.system.product="PRODUCT" uboot.m_product="M_PRODUCT" product_vars="smbios.system.planar.maker smbios.system.planar.product smbios.system.product uboot.m_product" to read files found in the following directories, in that order: /boot/loader.conf.d/PLANAR_MAKER /boot/loader.conf.d/PLANAR_PRODUCT /boot/loader.conf.d/PRODUCT /boot/loader.conf.d/M_PRODUCT Reviewed by: imp, kevans Pull Request: https://github.com/freebsd/freebsd-src/pull/759 [[ The commit, revert, commit has been squashed dpwn ]] (cherry picked from commit c343eedc6db381ac76e489f8ae0304898b71c5db) (cherry picked from commit 994865caf250ea2a59b7b842e44680931e8b19f6) (cherry picked from commit 754cac4b283eb024a3a6a194130199c860e32ebf) --- stand/defaults/loader.conf.5 | 34 +++++++++++++++++++++++++++++++++- stand/lua/config.lua | 25 +++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 1 deletion(-) diff --git a/stand/defaults/loader.conf.5 b/stand/defaults/loader.conf.5 index 42e5712d93b8..0d82a3dac9b3 100644 --- a/stand/defaults/loader.conf.5 +++ b/stand/defaults/loader.conf.5 @@ -21,7 +21,7 @@ .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. -.Dd January 10, 2024 +.Dd February 2, 2024 .Dt LOADER.CONF 5 .Os .Sh NAME @@ -138,6 +138,38 @@ present file. should be treated as write-only. One cannot depend on any value remaining in the loader environment or carried over into the kernel environment. +.It Ar product_vars +When set, must be a space separated list of environment variable names to walk +through to guess product information. +The order matters as reading a config file override the previously defined +values. +Undefined variables are silently ignored. +.Pp +When product information can be guessed, for each product information found, +append +.Pa /boot/loader.conf.d/PRODUCT +to +.Ar loader_conf_dirs . +It can be typically used as follow: +.Bd -literal +smbios.system.planar.maker="PLANAR_MAKER" +smbios.system.planar.product="PLANAR_PRODUCT" +smbios.system.product="PRODUCT" +uboot.m_product="M_PRODUCT" +product_vars="smbios.system.planar.maker smbios.system.planar.product smbios.system.product uboot.m_product" +.Ed +.Pp +to read files found in the following directories, in that order: +.Bl -bullet -compact +.It +.Pa /boot/loader.conf.d/PLANAR_MAKER +.It +.Pa /boot/loader.conf.d/PLANAR_PRODUCT +.It +.Pa /boot/loader.conf.d/PRODUCT +.It +.Pa /boot/loader.conf.d/M_PRODUCT +.El .It Ar kernel Name of the kernel to be loaded. If no kernel name is set, no additional diff --git a/stand/lua/config.lua b/stand/lua/config.lua index 8fdc805ee983..210bb9338783 100644 --- a/stand/lua/config.lua +++ b/stand/lua/config.lua @@ -658,12 +658,37 @@ function config.readConf(file, loaded_files) if load_conf_dirs then local loader_conf_dirs = getEnv("loader_conf_dirs") + + -- If product_vars is set, it must be a list of environment variable names + -- to walk through to guess product information. The order matters as + -- reading a config files override the previously defined values. + -- + -- If product information can be guessed, for each product information + -- found, also read config files found in /boot/loader.conf.d/PRODUCT/. + local product_vars = getEnv("product_vars") + if product_vars then + local product_conf_dirs = "" + for var in product_vars:gmatch("%S+") do + local product = getEnv(var) + if product then + product_conf_dirs = product_conf_dirs .. " /boot/loader.conf.d/" .. product + end + end + + if loader_conf_dirs then + loader_conf_dirs = loader_conf_dirs .. product_conf_dirs + else + loader_conf_dirs = product_conf_dirs + end + end + 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