From owner-svn-src-all@freebsd.org Tue Apr 28 02:03:04 2020 Return-Path: Delivered-To: svn-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 6B6272CF445; Tue, 28 Apr 2020 02:03:04 +0000 (UTC) (envelope-from kevans@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) server-signature RSA-PSS (4096 bits) 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 49B4fw28dYz44SZ; Tue, 28 Apr 2020 02:03:04 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 452971C9E6; Tue, 28 Apr 2020 02:03:04 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 03S234DI063540; Tue, 28 Apr 2020 02:03:04 GMT (envelope-from kevans@FreeBSD.org) Received: (from kevans@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 03S233NJ063538; Tue, 28 Apr 2020 02:03:03 GMT (envelope-from kevans@FreeBSD.org) Message-Id: <202004280203.03S233NJ063538@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kevans set sender to kevans@FreeBSD.org using -f From: Kyle Evans Date: Tue, 28 Apr 2020 02:03:03 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r360421 - head/stand/lua X-SVN-Group: head X-SVN-Commit-Author: kevans X-SVN-Commit-Paths: head/stand/lua X-SVN-Commit-Revision: 360421 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 28 Apr 2020 02:03:04 -0000 Author: kevans Date: Tue Apr 28 02:03:03 2020 New Revision: 360421 URL: https://svnweb.freebsd.org/changeset/base/360421 Log: lualoader: config: start exporting readConfFiles In the process, change it slightly: readConfFiles will take a string like loader_conf_files in addition to the loaded_files table that it normally takes. This is to facilitate the addition of a read-conf CLI command, which will just pass in the single file to read and an empty table. MFC after: 3 days Modified: head/stand/lua/config.lua head/stand/lua/config.lua.8 Modified: head/stand/lua/config.lua ============================================================================== --- head/stand/lua/config.lua Tue Apr 28 01:39:34 2020 (r360420) +++ head/stand/lua/config.lua Tue Apr 28 02:03:03 2020 (r360421) @@ -340,38 +340,6 @@ local function loadModule(mod, silent) return status end -local function readConfFiles(loaded_files) - local f = loader.getenv("loader_conf_files") - if f ~= nil then - local prefiles = f - for name in f:gmatch("([%w%p]+)%s*") do - if loaded_files[name] ~= nil then - goto continue - end - - print("Loading " .. name) - -- These may or may not exist, and that's ok. Do a - -- silent parse so that we complain on parse errors but - -- not for them simply not existing. - if not config.processFile(name, true) then - print(MSG_FAILPARSECFG:format(name)) - end - - loaded_files[name] = true - local newfiles = loader.getenv("loader_conf_files") - if prefiles ~= newfiles then - -- Recurse; process the new files immediately. - -- If we come back and it turns out we've - -- already loaded the rest of what was in the - -- original loader_conf_files, no big deal. - readConfFiles(loaded_files) - prefiles = newfiles - end - ::continue:: - end - end -end - local function readFile(name, silent) local f = io.open(name) if f == nil then @@ -492,6 +460,40 @@ function config.parse(text) return status end +function config.readConfFiles(files, loaded_files) + if files ~= nil then + -- The caller may not have passed in loader_conf_files; we could + -- have instead gotten some other string of files. We don't + -- want to trigger any redundant re-read/loads based on this. + local prefiles = loader.getenv("loader_conf_files") + for name in files:gmatch("([%w%p]+)%s*") do + if loaded_files[name] ~= nil then + goto continue + end + + print("Loading " .. name) + -- These may or may not exist, and that's ok. Do a + -- silent parse so that we complain on parse errors but + -- not for them simply not existing. + if not config.processFile(name, true) then + print(MSG_FAILPARSECFG:format(name)) + end + + loaded_files[name] = true + local newfiles = loader.getenv("loader_conf_files") + if prefiles ~= newfiles then + -- Recurse; process the new files immediately. + -- If we come back and it turns out we've + -- already loaded the rest of what was in the + -- original loader_conf_files, no big deal. + config.readConfFiles(newfiles, loaded_files) + prefiles = newfiles + end + ::continue:: + end + end +end + -- other_kernel is optionally the name of a kernel to load, if not the default -- or autoloaded default from the module_path function config.loadKernel(other_kernel) @@ -605,7 +607,7 @@ function config.load(file, reloading) end local loaded_files = {file = true} - readConfFiles(loaded_files) + config.readConfFiles(loader.getenv("loader_conf_files"), loaded_files) checkNextboot() Modified: head/stand/lua/config.lua.8 ============================================================================== --- head/stand/lua/config.lua.8 Tue Apr 28 01:39:34 2020 (r360420) +++ head/stand/lua/config.lua.8 Tue Apr 28 02:03:03 2020 (r360421) @@ -26,7 +26,7 @@ .\" .\" $FreeBSD$ .\" -.Dd June 9, 2018 +.Dd April 27, 2020 .Dt CONFIG.LUA 8 .Os .Sh NAME @@ -59,6 +59,15 @@ to A lookup will be done as needed to determine what value .Ev idx actually corresponds to. +.It Fn config.readConfFiles files loaded_files +Process +.Ev files +as if it were +.Ev loader_conf_files . +The caller may should pass in a table as the +.Ev loaded_files +argument, which uses filenames as keys and any non-nil value to indicate that +the file named by the key has been loaded. .It Fn config.processFile name silent Process and parse .Ev name