View | Details | Raw Unified | Return to bug 244640 | Differences between
and this patch

Collapse All | Expand All

(-)stand/defaults/loader.conf.5 (-1 / +5 lines)
Lines 23-29 Link Here
23
.\" SUCH DAMAGE.
23
.\" SUCH DAMAGE.
24
.\"
24
.\"
25
.\" $FreeBSD$
25
.\" $FreeBSD$
26
.Dd October 6, 2018
26
.Dd April 29, 2020
27
.Dt LOADER.CONF 5
27
.Dt LOADER.CONF 5
28
.Os
28
.Os
29
.Sh NAME
29
.Sh NAME
Lines 91-96 Link Here
91
.It Ar loader_conf_files
91
.It Ar loader_conf_files
92
Defines additional configuration files to be processed right after the
92
Defines additional configuration files to be processed right after the
93
present file.
93
present file.
94
.Ar loader_conf_files
95
should be treated as write-only.
96
One cannot depend on any value remaining in the loader environment or carried
97
over into the kernel environment.
94
.It Ar kernel
98
.It Ar kernel
95
Name of the kernel to be loaded.
99
Name of the kernel to be loaded.
96
If no kernel name is set, no additional
100
If no kernel name is set, no additional
(-)stand/lua/cli.lua (+5 lines)
Lines 125-130 Link Here
125
	core.autoboot(argstr)
125
	core.autoboot(argstr)
126
end
126
end
127
127
128
cli['read-conf'] = function(...)
129
	local _, argv = cli.arguments(...)
130
	config.readConf(assert(core.popFrontTable(argv)))
131
end
132
128
cli['reload-conf'] = function(...)
133
cli['reload-conf'] = function(...)
129
	config.reload()
134
	config.reload()
130
end
135
end
(-)stand/lua/config.lua (-36 / +65 lines)
Lines 61-66 Link Here
61
local WORDEXPR = "([%w]+)"
61
local WORDEXPR = "([%w]+)"
62
local WORDREPL = WORDEXPR:gsub('%%', '%%%%')
62
local WORDREPL = WORDEXPR:gsub('%%', '%%%%')
63
63
64
-- Entries that should never make it into the environment; each one should have
65
-- a documented reason for its existence, and these should all be implementation
66
-- details of the config module.
67
local loader_env_restricted_table = {
68
	-- loader_conf_files should be considered write-only, and consumers
69
	-- should not rely on any particular value; it's a loader implementation
70
	-- detail.  Moreover, it's not a particularly useful variable to have in
71
	-- the kenv.  Save the overhead, let it get fetched other ways.
72
	loader_conf_files = true,
73
}
74
64
local function restoreEnv()
75
local function restoreEnv()
65
	-- Examine changed environment variables
76
	-- Examine changed environment variables
66
	for k, v in pairs(env_changed) do
77
	for k, v in pairs(env_changed) do
Lines 88-101 Link Here
88
	env_restore = {}
99
	env_restore = {}
89
end
100
end
90
101
102
-- XXX This getEnv/setEnv should likely be exported at some point.  We can save
103
-- the call back into loader.getenv for any variable that's been set or
104
-- overridden by any loader.conf using this implementation with little overhead
105
-- since we're already tracking the values.
106
local function getEnv(key)
107
	if loader_env_restricted_table[key] ~= nil or
108
	    env_changed[key] ~= nil then
109
		return env_changed[key]
110
	end
111
112
	return loader.getenv(key)
113
end
114
91
local function setEnv(key, value)
115
local function setEnv(key, value)
116
	env_changed[key] = value
117
118
	if loader_env_restricted_table[key] ~= nil then
119
		return 0
120
	end
121
92
	-- Track the original value for this if we haven't already
122
	-- Track the original value for this if we haven't already
93
	if env_restore[key] == nil then
123
	if env_restore[key] == nil then
94
		env_restore[key] = {value = loader.getenv(key)}
124
		env_restore[key] = {value = loader.getenv(key)}
95
	end
125
	end
96
126
97
	env_changed[key] = value
98
99
	return loader.setenv(key, value)
127
	return loader.setenv(key, value)
100
end
128
end
101
129
Lines 340-373 Link Here
340
	return status
368
	return status
341
end
369
end
342
370
343
local function readConfFiles(loaded_files)
344
	local f = loader.getenv("loader_conf_files")
345
	if f ~= nil then
346
		for name in f:gmatch("([%w%p]+)%s*") do
347
			if loaded_files[name] ~= nil then
348
				goto continue
349
			end
350
351
			local prefiles = loader.getenv("loader_conf_files")
352
353
			print("Loading " .. name)
354
			-- These may or may not exist, and that's ok. Do a
355
			-- silent parse so that we complain on parse errors but
356
			-- not for them simply not existing.
357
			if not config.processFile(name, true) then
358
				print(MSG_FAILPARSECFG:format(name))
359
			end
360
361
			loaded_files[name] = true
362
			local newfiles = loader.getenv("loader_conf_files")
363
			if prefiles ~= newfiles then
364
				readConfFiles(loaded_files)
365
			end
366
			::continue::
367
		end
368
	end
369
end
370
371
local function readFile(name, silent)
371
local function readFile(name, silent)
372
	local f = io.open(name)
372
	local f = io.open(name)
373
	if f == nil then
373
	if f == nil then
Lines 488-493 Link Here
488
	return status
488
	return status
489
end
489
end
490
490
491
function config.readConf(file, loaded_files)
492
	if loaded_files == nil then
493
		loaded_files = {}
494
	end
495
496
	if loaded_files[file] ~= nil then
497
		return
498
	end
499
500
	print("Loading " .. file)
501
502
	-- The final value of loader_conf_files is not important, so just
503
	-- clobber it here.  We'll later check if it's no longer nil and process
504
	-- the new value for files to read.
505
	setEnv("loader_conf_files", nil)
506
507
	-- These may or may not exist, and that's ok. Do a
508
	-- silent parse so that we complain on parse errors but
509
	-- not for them simply not existing.
510
	if not config.processFile(file, true) then
511
		print(MSG_FAILPARSECFG:format(file))
512
	end
513
514
	loaded_files[file] = true
515
516
	-- Going to process "loader_conf_files" extra-files
517
	local loader_conf_files = getEnv("loader_conf_files")
518
	if loader_conf_files ~= nil then
519
		for name in loader_conf_files:gmatch("[%w%p]+") do
520
			config.readConf(name, loaded_files)
521
		end
522
	end
523
end
524
491
-- other_kernel is optionally the name of a kernel to load, if not the default
525
-- other_kernel is optionally the name of a kernel to load, if not the default
492
-- or autoloaded default from the module_path
526
-- or autoloaded default from the module_path
493
function config.loadKernel(other_kernel)
527
function config.loadKernel(other_kernel)
Lines 596-608 Link Here
596
		file = "/boot/defaults/loader.conf"
630
		file = "/boot/defaults/loader.conf"
597
	end
631
	end
598
632
599
	if not config.processFile(file) then
633
	config.readConf(file)
600
		print(MSG_FAILPARSECFG:format(file))
601
	end
602
634
603
	local loaded_files = {file = true}
604
	readConfFiles(loaded_files)
605
606
	checkNextboot()
635
	checkNextboot()
607
636
608
	local verbose = loader.getenv("verbose_loading") or "no"
637
	local verbose = loader.getenv("verbose_loading") or "no"
(-)stand/lua/config.lua.8 (-3 / +23 lines)
Lines 26-32 Link Here
26
.\"
26
.\"
27
.\" $FreeBSD$
27
.\" $FreeBSD$
28
.\"
28
.\"
29
.Dd June 9, 2018
29
.Dd April 30, 2020
30
.Dt CONFIG.LUA 8
30
.Dt CONFIG.LUA 8
31
.Os
31
.Os
32
.Sh NAME
32
.Sh NAME
Lines 59-64 Link Here
59
A lookup will be done as needed to determine what value
59
A lookup will be done as needed to determine what value
60
.Ev idx
60
.Ev idx
61
actually corresponds to.
61
actually corresponds to.
62
.It Fn config.readConf file loaded_files
63
Process
64
.Pa file
65
as a configuration file
66
.Po e.g., as
67
.Pa loader.conf
68
.Pc
69
and then processing files listed in
70
.Ev loader_conf_files
71
variable
72
.Po see
73
.Xr loader.conf 5
74
.Pc .
75
The caller may optionally pass in a table as the
76
.Ev loaded_files
77
argument, which uses filenames as keys and any non-nil value to
78
indicate that the file named by the key has already been loaded and
79
should not be loaded again.
62
.It Fn config.processFile name silent
80
.It Fn config.processFile name silent
63
Process and parse
81
Process and parse
64
.Ev name
82
.Ev name
Lines 171-178 Link Here
171
The following hooks are defined in
189
The following hooks are defined in
172
.Nm :
190
.Nm :
173
.Bl -tag -width "config.reloaded" -offset indent
191
.Bl -tag -width "config.reloaded" -offset indent
174
.It config.loaded
192
.It Fn config.loaded
175
.It config.reloaded
193
.It Fn config.reloaded
194
.It Fn kernel.loaded
195
.It Fn modules.loaded
176
.El
196
.El
177
.Sh SEE ALSO
197
.Sh SEE ALSO
178
.Xr loader.conf 5 ,
198
.Xr loader.conf 5 ,

Return to bug 244640