summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKyle Evans <kevans@FreeBSD.org>2020-04-30 21:04:39 +0000
committerKyle Evans <kevans@FreeBSD.org>2020-04-30 21:04:39 +0000
commit3fe0ac6aa589dcac10a75b54d1a3cb10e86a4798 (patch)
tree0580a621785e406fb4be9cbaedcc35be207a7b44
parentbf832717cf8d95ace9314053886cba332fea2a89 (diff)
Notes
-rw-r--r--stand/lua/cli.lua5
-rw-r--r--stand/lua/config.lua63
-rw-r--r--stand/lua/config.lua.825
3 files changed, 47 insertions, 46 deletions
diff --git a/stand/lua/cli.lua b/stand/lua/cli.lua
index 4b2a879d87e2..188292191448 100644
--- a/stand/lua/cli.lua
+++ b/stand/lua/cli.lua
@@ -127,10 +127,7 @@ end
cli['read-conf'] = function(...)
local _, argv = cli.arguments(...)
- -- Don't trigger a reload of previously loaded loader_conf_files, in
- -- case this config file doesn't set it.
- loader.setenv("loader_conf_files", "")
- config.readConfFiles(assert(core.popFrontTable(argv)), {})
+ config.readConf(assert(core.popFrontTable(argv)))
end
cli['reload-conf'] = function(...)
diff --git a/stand/lua/config.lua b/stand/lua/config.lua
index bfa7e3edff85..1934fe795f06 100644
--- a/stand/lua/config.lua
+++ b/stand/lua/config.lua
@@ -488,36 +488,36 @@ 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 = getEnv("loader_conf_files")
- for name in files:gmatch("([%w%p]+)%s*") do
- if loaded_files[name] ~= nil then
- goto continue
- end
+function config.readConf(file, loaded_files)
+ if loaded_files == nil then
+ loaded_files = {}
+ 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
+ if loaded_files[file] ~= nil then
+ return
+ end
- loaded_files[name] = true
- local newfiles = 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::
+ print("Loading " .. file)
+
+ -- The final value of loader_conf_files is not important, so just
+ -- clobber it here. We'll later check if it's no longer nil and process
+ -- the new value for files to read.
+ setEnv("loader_conf_files", nil)
+
+ -- 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(file, true) then
+ print(MSG_FAILPARSECFG:format(file))
+ end
+
+ loaded_files[file] = true
+
+ -- Going to process "loader_conf_files" extra-files
+ local loader_conf_files = getEnv("loader_conf_files")
+ if loader_conf_files ~= nil then
+ for name in loader_conf_files:gmatch("[%w%p]+") do
+ config.readConf(name, loaded_files)
end
end
end
@@ -630,12 +630,7 @@ function config.load(file, reloading)
file = "/boot/defaults/loader.conf"
end
- if not config.processFile(file) then
- print(MSG_FAILPARSECFG:format(file))
- end
-
- local loaded_files = {file = true}
- config.readConfFiles(getEnv("loader_conf_files"), loaded_files)
+ config.readConf(file)
checkNextboot()
diff --git a/stand/lua/config.lua.8 b/stand/lua/config.lua.8
index bdf74451ea6e..098b607271f7 100644
--- a/stand/lua/config.lua.8
+++ b/stand/lua/config.lua.8
@@ -26,7 +26,7 @@
.\"
.\" $FreeBSD$
.\"
-.Dd April 27, 2020
+.Dd April 30, 2020
.Dt CONFIG.LUA 8
.Os
.Sh NAME
@@ -59,15 +59,24 @@ to
A lookup will be done as needed to determine what value
.Ev idx
actually corresponds to.
-.It Fn config.readConfFiles files loaded_files
+.It Fn config.readConf file loaded_files
Process
-.Ev files
-as if it were
-.Ev loader_conf_files .
-The caller should pass in a table as the
+.Pa file
+as a configuration file
+.Po e.g., as
+.Pa loader.conf
+.Pc
+and then processing files listed in
+.Ev loader_conf_files
+variable
+.Po see
+.Xr loader.conf 5
+.Pc .
+The caller may optionally 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.
+argument, which uses filenames as keys and any non-nil value to
+indicate that the file named by the key has already been loaded and
+should not be loaded again.
.It Fn config.processFile name silent
Process and parse
.Ev name