xref: /freebsd/stand/lua/config.lua (revision 9768746b)
1--
2-- SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3--
4-- Copyright (c) 2015 Pedro Souza <pedrosouza@freebsd.org>
5-- Copyright (c) 2018 Kyle Evans <kevans@FreeBSD.org>
6-- All rights reserved.
7--
8-- Redistribution and use in source and binary forms, with or without
9-- modification, are permitted provided that the following conditions
10-- are met:
11-- 1. Redistributions of source code must retain the above copyright
12--    notice, this list of conditions and the following disclaimer.
13-- 2. Redistributions in binary form must reproduce the above copyright
14--    notice, this list of conditions and the following disclaimer in the
15--    documentation and/or other materials provided with the distribution.
16--
17-- THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18-- ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19-- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20-- ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21-- FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22-- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23-- OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24-- HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25-- LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26-- OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27-- SUCH DAMAGE.
28--
29-- $FreeBSD$
30--
31
32local hook = require("hook")
33
34local config = {}
35local modules = {}
36local carousel_choices = {}
37-- Which variables we changed
38local env_changed = {}
39-- Values to restore env to (nil to unset)
40local env_restore = {}
41
42local MSG_FAILDIR = "Failed to load conf dir '%s': not a directory"
43local MSG_FAILEXEC = "Failed to exec '%s'"
44local MSG_FAILSETENV = "Failed to '%s' with value: %s"
45local MSG_FAILOPENCFG = "Failed to open config: '%s'"
46local MSG_FAILREADCFG = "Failed to read config: '%s'"
47local MSG_FAILPARSECFG = "Failed to parse config: '%s'"
48local MSG_FAILPARSEVAR = "Failed to parse variable '%s': %s"
49local MSG_FAILEXBEF = "Failed to execute '%s' before loading '%s'"
50local MSG_FAILEXAF = "Failed to execute '%s' after loading '%s'"
51local MSG_MALFORMED = "Malformed line (%d):\n\t'%s'"
52local MSG_DEFAULTKERNFAIL = "No kernel set, failed to load from module_path"
53local MSG_KERNFAIL = "Failed to load kernel '%s'"
54local MSG_XENKERNFAIL = "Failed to load Xen kernel '%s'"
55local MSG_XENKERNLOADING = "Loading Xen kernel..."
56local MSG_KERNLOADING = "Loading kernel..."
57local MSG_MODLOADING = "Loading configured modules..."
58local MSG_MODBLACKLIST = "Not loading blacklisted module '%s'"
59
60local MSG_FAILSYN_QUOTE = "Stray quote at position '%d'"
61local MSG_FAILSYN_EOLESC = "Stray escape at end of line"
62local MSG_FAILSYN_EOLVAR = "Unescaped $ at end of line"
63local MSG_FAILSYN_BADVAR = "Malformed variable expression at position '%d'"
64
65local MODULEEXPR = '([-%w_]+)'
66local QVALEXPR = '"(.*)"'
67local QVALREPL = QVALEXPR:gsub('%%', '%%%%')
68local WORDEXPR = "([-%w%d][-%w%d_.]*)"
69local WORDREPL = WORDEXPR:gsub('%%', '%%%%')
70
71-- Entries that should never make it into the environment; each one should have
72-- a documented reason for its existence, and these should all be implementation
73-- details of the config module.
74local loader_env_restricted_table = {
75	-- loader_conf_files should be considered write-only, and consumers
76	-- should not rely on any particular value; it's a loader implementation
77	-- detail.  Moreover, it's not a particularly useful variable to have in
78	-- the kenv.  Save the overhead, let it get fetched other ways.
79	loader_conf_files = true,
80}
81
82local function restoreEnv()
83	-- Examine changed environment variables
84	for k, v in pairs(env_changed) do
85		local restore_value = env_restore[k]
86		if restore_value == nil then
87			-- This one doesn't need restored for some reason
88			goto continue
89		end
90		local current_value = loader.getenv(k)
91		if current_value ~= v then
92			-- This was overwritten by some action taken on the menu
93			-- most likely; we'll leave it be.
94			goto continue
95		end
96		restore_value = restore_value.value
97		if restore_value ~= nil then
98			loader.setenv(k, restore_value)
99		else
100			loader.unsetenv(k)
101		end
102		::continue::
103	end
104
105	env_changed = {}
106	env_restore = {}
107end
108
109-- XXX This getEnv/setEnv should likely be exported at some point.  We can save
110-- the call back into loader.getenv for any variable that's been set or
111-- overridden by any loader.conf using this implementation with little overhead
112-- since we're already tracking the values.
113local function getEnv(key)
114	if loader_env_restricted_table[key] ~= nil or
115	    env_changed[key] ~= nil then
116		return env_changed[key]
117	end
118
119	return loader.getenv(key)
120end
121
122local function setEnv(key, value)
123	env_changed[key] = value
124
125	if loader_env_restricted_table[key] ~= nil then
126		return 0
127	end
128
129	-- Track the original value for this if we haven't already
130	if env_restore[key] == nil then
131		env_restore[key] = {value = loader.getenv(key)}
132	end
133
134	return loader.setenv(key, value)
135end
136
137-- name here is one of 'name', 'type', flags', 'before', 'after', or 'error.'
138-- These are set from lines in loader.conf(5): ${key}_${name}="${value}" where
139-- ${key} is a module name.
140local function setKey(key, name, value)
141	if modules[key] == nil then
142		modules[key] = {}
143	end
144	modules[key][name] = value
145end
146
147-- Escapes the named value for use as a literal in a replacement pattern.
148-- e.g. dhcp.host-name gets turned into dhcp%.host%-name to remove the special
149-- meaning.
150local function escapeName(name)
151	return name:gsub("([%p])", "%%%1")
152end
153
154local function processEnvVar(value)
155	local pval, vlen = '', #value
156	local nextpos, vdelim, vinit = 1
157	local vpat
158	for i = 1, vlen do
159		if i < nextpos then
160			goto nextc
161		end
162
163		local c = value:sub(i, i)
164		if c == '\\' then
165			if i == vlen then
166				return nil, MSG_FAILSYN_EOLESC
167			end
168			nextpos = i + 2
169			pval = pval .. value:sub(i + 1, i + 1)
170		elseif c == '"' then
171			return nil, MSG_FAILSYN_QUOTE:format(i)
172		elseif c == "$" then
173			if i == vlen then
174				return nil, MSG_FAILSYN_EOLVAR
175			else
176				if value:sub(i + 1, i + 1) == "{" then
177					-- Skip ${
178					vinit = i + 2
179					vdelim = '}'
180					vpat = "^([^}]+)}"
181				else
182					-- Skip the $
183					vinit = i + 1
184					vdelim = nil
185					vpat = "^([%w][-%w%d_.]*)"
186				end
187
188				local name = value:match(vpat, vinit)
189				if not name then
190					return nil, MSG_FAILSYN_BADVAR:format(i)
191				else
192					nextpos = vinit + #name
193					if vdelim then
194						nextpos = nextpos + 1
195					end
196
197					local repl = loader.getenv(name) or ""
198					pval = pval .. repl
199				end
200			end
201		else
202			pval = pval .. c
203		end
204		::nextc::
205	end
206
207	return pval
208end
209
210local function checkPattern(line, pattern)
211	local function _realCheck(_line, _pattern)
212		return _line:match(_pattern)
213	end
214
215	if pattern:find('$VALUE') then
216		local k, v, c
217		k, v, c = _realCheck(line, pattern:gsub('$VALUE', QVALREPL))
218		if k ~= nil then
219			return k,v, c
220		end
221		return _realCheck(line, pattern:gsub('$VALUE', WORDREPL))
222	else
223		return _realCheck(line, pattern)
224	end
225end
226
227-- str in this table is a regex pattern.  It will automatically be anchored to
228-- the beginning of a line and any preceding whitespace will be skipped.  The
229-- pattern should have no more than two captures patterns, which correspond to
230-- the two parameters (usually 'key' and 'value') that are passed to the
231-- process function.  All trailing characters will be validated.  Any $VALUE
232-- token included in a pattern will be tried first with a quoted value capture
233-- group, then a single-word value capture group.  This is our kludge for Lua
234-- regex not supporting branching.
235--
236-- We have two special entries in this table: the first is the first entry,
237-- a full-line comment.  The second is for 'exec' handling.  Both have a single
238-- capture group, but the difference is that the full-line comment pattern will
239-- match the entire line.  This does not run afoul of the later end of line
240-- validation that we'll do after a match.  However, the 'exec' pattern will.
241-- We document the exceptions with a special 'groups' index that indicates
242-- the number of capture groups, if not two.  We'll use this later to do
243-- validation on the proper entry.
244--
245local pattern_table = {
246	{
247		str = "(#.*)",
248		process = function(_, _)  end,
249		groups = 1,
250	},
251	--  module_load="value"
252	{
253		str = MODULEEXPR .. "_load%s*=%s*$VALUE",
254		process = function(k, v)
255			if modules[k] == nil then
256				modules[k] = {}
257			end
258			modules[k].load = v:upper()
259			setEnv(k .. "_load", v:upper())
260		end,
261	},
262	--  module_name="value"
263	{
264		str = MODULEEXPR .. "_name%s*=%s*$VALUE",
265		process = function(k, v)
266			setKey(k, "name", v)
267			setEnv(k .. "_name", v)
268		end,
269	},
270	--  module_type="value"
271	{
272		str = MODULEEXPR .. "_type%s*=%s*$VALUE",
273		process = function(k, v)
274			setKey(k, "type", v)
275			setEnv(k .. "_type", v)
276		end,
277	},
278	--  module_flags="value"
279	{
280		str = MODULEEXPR .. "_flags%s*=%s*$VALUE",
281		process = function(k, v)
282			setKey(k, "flags", v)
283			setEnv(k .. "_flags", v)
284		end,
285	},
286	--  module_before="value"
287	{
288		str = MODULEEXPR .. "_before%s*=%s*$VALUE",
289		process = function(k, v)
290			setKey(k, "before", v)
291			setEnv(k .. "_before", v)
292		end,
293	},
294	--  module_after="value"
295	{
296		str = MODULEEXPR .. "_after%s*=%s*$VALUE",
297		process = function(k, v)
298			setKey(k, "after", v)
299			setEnv(k .. "_after", v)
300		end,
301	},
302	--  module_error="value"
303	{
304		str = MODULEEXPR .. "_error%s*=%s*$VALUE",
305		process = function(k, v)
306			setKey(k, "error", v)
307			setEnv(k .. "_error", v)
308		end,
309	},
310	--  exec="command"
311	{
312		str = "exec%s*=%s*" .. QVALEXPR,
313		process = function(k, _)
314			if cli_execute_unparsed(k) ~= 0 then
315				print(MSG_FAILEXEC:format(k))
316			end
317		end,
318		groups = 1,
319	},
320	--  env_var="value" or env_var=[word|num]
321	{
322		str = "([%w][%w%d-_.]*)%s*=%s*$VALUE",
323		process = function(k, v)
324			local pv, msg = processEnvVar(v)
325			if not pv then
326				print(MSG_FAILPARSEVAR:format(k, msg))
327				return
328			end
329			if setEnv(k, pv) ~= 0 then
330				print(MSG_FAILSETENV:format(k, v))
331			end
332		end,
333	},
334}
335
336local function isValidComment(line)
337	if line ~= nil then
338		local s = line:match("^%s*#.*")
339		if s == nil then
340			s = line:match("^%s*$")
341		end
342		if s == nil then
343			return false
344		end
345	end
346	return true
347end
348
349local function getBlacklist()
350	local blacklist = {}
351	local blacklist_str = loader.getenv('module_blacklist')
352	if blacklist_str == nil then
353		return blacklist
354	end
355
356	for mod in blacklist_str:gmatch("[;, ]?([-%w_]+)[;, ]?") do
357		blacklist[mod] = true
358	end
359	return blacklist
360end
361
362local function loadModule(mod, silent)
363	local status = true
364	local blacklist = getBlacklist()
365	local pstatus
366	for k, v in pairs(mod) do
367		if v.load ~= nil and v.load:lower() == "yes" then
368			local module_name = v.name or k
369			if not v.force and blacklist[module_name] ~= nil then
370				if not silent then
371					print(MSG_MODBLACKLIST:format(module_name))
372				end
373				goto continue
374			end
375			if not silent then
376				loader.printc(module_name .. "...")
377			end
378			local str = "load "
379			if v.type ~= nil then
380				str = str .. "-t " .. v.type .. " "
381			end
382			str = str .. module_name
383			if v.flags ~= nil then
384				str = str .. " " .. v.flags
385			end
386			if v.before ~= nil then
387				pstatus = cli_execute_unparsed(v.before) == 0
388				if not pstatus and not silent then
389					print(MSG_FAILEXBEF:format(v.before, k))
390				end
391				status = status and pstatus
392			end
393
394			if cli_execute_unparsed(str) ~= 0 then
395				-- XXX Temporary shim: don't break the boot if
396				-- loader hadn't been recompiled with this
397				-- function exposed.
398				if loader.command_error then
399					print(loader.command_error())
400				end
401				if not silent then
402					print("failed!")
403				end
404				if v.error ~= nil then
405					cli_execute_unparsed(v.error)
406				end
407				status = false
408			elseif v.after ~= nil then
409				pstatus = cli_execute_unparsed(v.after) == 0
410				if not pstatus and not silent then
411					print(MSG_FAILEXAF:format(v.after, k))
412				end
413				if not silent then
414					print("ok")
415				end
416				status = status and pstatus
417			end
418		end
419		::continue::
420	end
421
422	return status
423end
424
425local function readFile(name, silent)
426	local f = io.open(name)
427	if f == nil then
428		if not silent then
429			print(MSG_FAILOPENCFG:format(name))
430		end
431		return nil
432	end
433
434	local text, _ = io.read(f)
435	-- We might have read in the whole file, this won't be needed any more.
436	io.close(f)
437
438	if text == nil and not silent then
439		print(MSG_FAILREADCFG:format(name))
440	end
441	return text
442end
443
444local function checkNextboot()
445	local nextboot_file = loader.getenv("nextboot_conf")
446	local nextboot_enable = loader.getenv("nextboot_enable")
447
448	if nextboot_file == nil then
449		return
450	end
451
452	-- is nextboot_enable set in nvstore?
453	if nextboot_enable == "NO" then
454		return
455	end
456
457	local text = readFile(nextboot_file, true)
458	if text == nil then
459		return
460	end
461
462	if nextboot_enable == nil and
463	    text:match("^nextboot_enable=\"NO\"") ~= nil then
464		-- We're done; nextboot is not enabled
465		return
466	end
467
468	if not config.parse(text) then
469		print(MSG_FAILPARSECFG:format(nextboot_file))
470	end
471
472	-- Attempt to rewrite the first line and only the first line of the
473	-- nextboot_file. We overwrite it with nextboot_enable="NO", then
474	-- check for that on load.
475	-- It's worth noting that this won't work on every filesystem, so we
476	-- won't do anything notable if we have any errors in this process.
477	local nfile = io.open(nextboot_file, 'w')
478	if nfile ~= nil then
479		-- We need the trailing space here to account for the extra
480		-- character taken up by the string nextboot_enable="YES"
481		-- Or new end quotation mark lands on the S, and we want to
482		-- rewrite the entirety of the first line.
483		io.write(nfile, "nextboot_enable=\"NO\" ")
484		io.close(nfile)
485	end
486	loader.setenv("nextboot_enable", "NO")
487end
488
489-- Module exports
490config.verbose = false
491
492-- The first item in every carousel is always the default item.
493function config.getCarouselIndex(id)
494	return carousel_choices[id] or 1
495end
496
497function config.setCarouselIndex(id, idx)
498	carousel_choices[id] = idx
499end
500
501-- Returns true if we processed the file successfully, false if we did not.
502-- If 'silent' is true, being unable to read the file is not considered a
503-- failure.
504function config.processFile(name, silent)
505	if silent == nil then
506		silent = false
507	end
508
509	local text = readFile(name, silent)
510	if text == nil then
511		return silent
512	end
513
514	return config.parse(text)
515end
516
517-- silent runs will not return false if we fail to open the file
518function config.parse(text)
519	local n = 1
520	local status = true
521
522	for line in text:gmatch("([^\n]+)") do
523		if line:match("^%s*$") == nil then
524			for _, val in ipairs(pattern_table) do
525				local pattern = '^%s*' .. val.str .. '%s*(.*)';
526				local cgroups = val.groups or 2
527				local k, v, c = checkPattern(line, pattern)
528				if k ~= nil then
529					-- Offset by one, drats
530					if cgroups == 1 then
531						c = v
532						v = nil
533					end
534
535					if isValidComment(c) then
536						val.process(k, v)
537						goto nextline
538					end
539
540					break
541				end
542			end
543
544			print(MSG_MALFORMED:format(n, line))
545			status = false
546		end
547		::nextline::
548		n = n + 1
549	end
550
551	return status
552end
553
554function config.readConf(file, loaded_files)
555	if loaded_files == nil then
556		loaded_files = {}
557	end
558
559	if loaded_files[file] ~= nil then
560		return
561	end
562
563	-- We'll process loader_conf_dirs at the top-level readConf
564	local load_conf_dirs = next(loaded_files) == nil
565	print("Loading " .. file)
566
567	-- The final value of loader_conf_files is not important, so just
568	-- clobber it here.  We'll later check if it's no longer nil and process
569	-- the new value for files to read.
570	setEnv("loader_conf_files", nil)
571
572	-- These may or may not exist, and that's ok. Do a
573	-- silent parse so that we complain on parse errors but
574	-- not for them simply not existing.
575	if not config.processFile(file, true) then
576		print(MSG_FAILPARSECFG:format(file))
577	end
578
579	loaded_files[file] = true
580
581	-- Going to process "loader_conf_files" extra-files
582	local loader_conf_files = getEnv("loader_conf_files")
583	if loader_conf_files ~= nil then
584		for name in loader_conf_files:gmatch("[%w%p]+") do
585			config.readConf(name, loaded_files)
586		end
587	end
588
589	if load_conf_dirs then
590		local loader_conf_dirs = getEnv("loader_conf_dirs")
591		if loader_conf_dirs ~= nil then
592			for name in loader_conf_dirs:gmatch("[%w%p]+") do
593				if lfs.attributes(name, "mode") ~= "directory" then
594					print(MSG_FAILDIR:format(name))
595					goto nextdir
596				end
597				for cfile in lfs.dir(name) do
598					if cfile:match(".conf$") then
599						local fpath = name .. "/" .. cfile
600						if lfs.attributes(fpath, "mode") == "file" then
601							config.readConf(fpath, loaded_files)
602						end
603					end
604				end
605				::nextdir::
606			end
607		end
608	end
609end
610
611-- other_kernel is optionally the name of a kernel to load, if not the default
612-- or autoloaded default from the module_path
613function config.loadKernel(other_kernel)
614	local flags = loader.getenv("kernel_options") or ""
615	local kernel = other_kernel or loader.getenv("kernel")
616
617	local function tryLoad(names)
618		for name in names:gmatch("([^;]+)%s*;?") do
619			local r = loader.perform("load " .. name ..
620			     " " .. flags)
621			if r == 0 then
622				return name
623			end
624		end
625		return nil
626	end
627
628	local function getModulePath()
629		local module_path = loader.getenv("module_path")
630		local kernel_path = loader.getenv("kernel_path")
631
632		if kernel_path == nil then
633			return module_path
634		end
635
636		-- Strip the loaded kernel path from module_path. This currently assumes
637		-- that the kernel path will be prepended to the module_path when it's
638		-- found.
639		kernel_path = escapeName(kernel_path .. ';')
640		return module_path:gsub(kernel_path, '')
641	end
642
643	local function loadBootfile()
644		local bootfile = loader.getenv("bootfile")
645
646		-- append default kernel name
647		if bootfile == nil then
648			bootfile = "kernel"
649		else
650			bootfile = bootfile .. ";kernel"
651		end
652
653		return tryLoad(bootfile)
654	end
655
656	-- kernel not set, try load from default module_path
657	if kernel == nil then
658		local res = loadBootfile()
659
660		if res ~= nil then
661			-- Default kernel is loaded
662			config.kernel_loaded = nil
663			return true
664		else
665			print(MSG_DEFAULTKERNFAIL)
666			return false
667		end
668	else
669		-- Use our cached module_path, so we don't end up with multiple
670		-- automatically added kernel paths to our final module_path
671		local module_path = getModulePath()
672		local res
673
674		if other_kernel ~= nil then
675			kernel = other_kernel
676		end
677		-- first try load kernel with module_path = /boot/${kernel}
678		-- then try load with module_path=${kernel}
679		local paths = {"/boot/" .. kernel, kernel}
680
681		for _, v in pairs(paths) do
682			loader.setenv("module_path", v)
683			res = loadBootfile()
684
685			-- succeeded, add path to module_path
686			if res ~= nil then
687				config.kernel_loaded = kernel
688				if module_path ~= nil then
689					loader.setenv("module_path", v .. ";" ..
690					    module_path)
691					loader.setenv("kernel_path", v)
692				end
693				return true
694			end
695		end
696
697		-- failed to load with ${kernel} as a directory
698		-- try as a file
699		res = tryLoad(kernel)
700		if res ~= nil then
701			config.kernel_loaded = kernel
702			return true
703		else
704			print(MSG_KERNFAIL:format(kernel))
705			return false
706		end
707	end
708end
709
710function config.selectKernel(kernel)
711	config.kernel_selected = kernel
712end
713
714function config.load(file, reloading)
715	if not file then
716		file = "/boot/defaults/loader.conf"
717	end
718
719	config.readConf(file)
720
721	checkNextboot()
722
723	local verbose = loader.getenv("verbose_loading") or "no"
724	config.verbose = verbose:lower() == "yes"
725	if not reloading then
726		hook.runAll("config.loaded")
727	end
728end
729
730-- Reload configuration
731function config.reload(file)
732	modules = {}
733	restoreEnv()
734	config.load(file, true)
735	hook.runAll("config.reloaded")
736end
737
738function config.loadelf()
739	local xen_kernel = loader.getenv('xen_kernel')
740	local kernel = config.kernel_selected or config.kernel_loaded
741	local status
742
743	if xen_kernel ~= nil then
744		print(MSG_XENKERNLOADING)
745		if cli_execute_unparsed('load ' .. xen_kernel) ~= 0 then
746			print(MSG_XENKERNFAIL:format(xen_kernel))
747			return false
748		end
749	end
750	print(MSG_KERNLOADING)
751	if not config.loadKernel(kernel) then
752		return false
753	end
754	hook.runAll("kernel.loaded")
755
756	print(MSG_MODLOADING)
757	status = loadModule(modules, not config.verbose)
758	hook.runAll("modules.loaded")
759	return status
760end
761
762function config.enableModule(modname)
763	if modules[modname] == nil then
764		modules[modname] = {}
765	elseif modules[modname].load == "YES" then
766		modules[modname].force = true
767		return true
768	end
769
770	modules[modname].load = "YES"
771	modules[modname].force = true
772	return true
773end
774
775function config.disableModule(modname)
776	if modules[modname] == nil then
777		return false
778	elseif modules[modname].load ~= "YES" then
779		return true
780	end
781
782	modules[modname].load = "NO"
783	modules[modname].force = nil
784	return true
785end
786
787function config.isModuleEnabled(modname)
788	local mod = modules[modname]
789	if not mod or mod.load ~= "YES" then
790		return false
791	end
792
793	if mod.force then
794		return true
795	end
796
797	local blacklist = getBlacklist()
798	return not blacklist[modname]
799end
800
801function config.getModuleInfo()
802	return {
803		modules = modules,
804		blacklist = getBlacklist()
805	}
806end
807
808hook.registerType("config.loaded")
809hook.registerType("config.reloaded")
810hook.registerType("kernel.loaded")
811hook.registerType("modules.loaded")
812return config
813