Deleted Added
full compact
config.lua (359400) config.lua (360596)
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

--- 12 unchanged lines hidden (view full) ---

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--
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

--- 12 unchanged lines hidden (view full) ---

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: stable/11/stand/lua/config.lua 359400 2020-03-28 17:11:54Z kevans $
29-- $FreeBSD: stable/11/stand/lua/config.lua 360596 2020-05-03 03:53:38Z kevans $
30--
31
32local hook = require("hook")
33
34local config = {}
35local modules = {}
36local carousel_choices = {}
37-- Which variables we changed

--- 18 unchanged lines hidden (view full) ---

56local MSG_MODBLACKLIST = "Not loading blacklisted module '%s'"
57
58local MODULEEXPR = '([%w-_]+)'
59local QVALEXPR = "\"([%w%s%p]-)\""
60local QVALREPL = QVALEXPR:gsub('%%', '%%%%')
61local WORDEXPR = "([%w]+)"
62local WORDREPL = WORDEXPR:gsub('%%', '%%%%')
63
30--
31
32local hook = require("hook")
33
34local config = {}
35local modules = {}
36local carousel_choices = {}
37-- Which variables we changed

--- 18 unchanged lines hidden (view full) ---

56local MSG_MODBLACKLIST = "Not loading blacklisted module '%s'"
57
58local MODULEEXPR = '([%w-_]+)'
59local QVALEXPR = "\"([%w%s%p]-)\""
60local QVALREPL = QVALEXPR:gsub('%%', '%%%%')
61local WORDEXPR = "([%w]+)"
62local WORDREPL = WORDEXPR:gsub('%%', '%%%%')
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.
67local 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
64local function restoreEnv()
65 -- Examine changed environment variables
66 for k, v in pairs(env_changed) do
67 local restore_value = env_restore[k]
68 if restore_value == nil then
69 -- This one doesn't need restored for some reason
70 goto continue
71 end

--- 11 unchanged lines hidden (view full) ---

83 end
84 ::continue::
85 end
86
87 env_changed = {}
88 env_restore = {}
89end
90
75local function restoreEnv()
76 -- Examine changed environment variables
77 for k, v in pairs(env_changed) do
78 local restore_value = env_restore[k]
79 if restore_value == nil then
80 -- This one doesn't need restored for some reason
81 goto continue
82 end

--- 11 unchanged lines hidden (view full) ---

94 end
95 ::continue::
96 end
97
98 env_changed = {}
99 env_restore = {}
100end
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.
106local 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)
113end
114
91local function setEnv(key, value)
115local 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
93 if env_restore[key] == nil then
94 env_restore[key] = {value = loader.getenv(key)}
95 end
96
122 -- Track the original value for this if we haven't already
123 if env_restore[key] == nil then
124 env_restore[key] = {value = loader.getenv(key)}
125 end
126
97 env_changed[key] = value
98
99 return loader.setenv(key, value)
100end
101
102-- name here is one of 'name', 'type', flags', 'before', 'after', or 'error.'
103-- These are set from lines in loader.conf(5): ${key}_${name}="${value}" where
104-- ${key} is a module name.
105local function setKey(key, name, value)
106 if modules[key] == nil then

--- 228 unchanged lines hidden (view full) ---

335 end
336 end
337 ::continue::
338 end
339
340 return status
341end
342
127 return loader.setenv(key, value)
128end
129
130-- name here is one of 'name', 'type', flags', 'before', 'after', or 'error.'
131-- These are set from lines in loader.conf(5): ${key}_${name}="${value}" where
132-- ${key} is a module name.
133local function setKey(key, name, value)
134 if modules[key] == nil then

--- 228 unchanged lines hidden (view full) ---

363 end
364 end
365 ::continue::
366 end
367
368 return status
369end
370
343local 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
369end
370
371local function readFile(name, silent)
372 local f = io.open(name)
373 if f == nil then
374 if not silent then
375 print(MSG_FAILOPENCFG:format(name))
376 end
377 return nil
378 end

--- 104 unchanged lines hidden (view full) ---

483 end
484 ::nextline::
485 n = n + 1
486 end
487
488 return status
489end
490
371local function readFile(name, silent)
372 local f = io.open(name)
373 if f == nil then
374 if not silent then
375 print(MSG_FAILOPENCFG:format(name))
376 end
377 return nil
378 end

--- 104 unchanged lines hidden (view full) ---

483 end
484 ::nextline::
485 n = n + 1
486 end
487
488 return status
489end
490
491function 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
523end
524
491-- other_kernel is optionally the name of a kernel to load, if not the default
492-- or autoloaded default from the module_path
493function config.loadKernel(other_kernel)
494 local flags = loader.getenv("kernel_options") or ""
495 local kernel = other_kernel or loader.getenv("kernel")
496
497 local function tryLoad(names)
498 for name in names:gmatch("([^;]+)%s*;?") do

--- 92 unchanged lines hidden (view full) ---

591 config.kernel_selected = kernel
592end
593
594function config.load(file, reloading)
595 if not file then
596 file = "/boot/defaults/loader.conf"
597 end
598
525-- other_kernel is optionally the name of a kernel to load, if not the default
526-- or autoloaded default from the module_path
527function config.loadKernel(other_kernel)
528 local flags = loader.getenv("kernel_options") or ""
529 local kernel = other_kernel or loader.getenv("kernel")
530
531 local function tryLoad(names)
532 for name in names:gmatch("([^;]+)%s*;?") do

--- 92 unchanged lines hidden (view full) ---

625 config.kernel_selected = kernel
626end
627
628function config.load(file, reloading)
629 if not file then
630 file = "/boot/defaults/loader.conf"
631 end
632
599 if not config.processFile(file) then
600 print(MSG_FAILPARSECFG:format(file))
601 end
633 config.readConf(file)
602
634
603 local loaded_files = {file = true}
604 readConfFiles(loaded_files)
605
606 checkNextboot()
607
608 local verbose = loader.getenv("verbose_loading") or "no"
609 config.verbose = verbose:lower() == "yes"
610 if not reloading then
611 hook.runAll("config.loaded")
612 end
613end

--- 38 unchanged lines hidden ---
635 checkNextboot()
636
637 local verbose = loader.getenv("verbose_loading") or "no"
638 config.verbose = verbose:lower() == "yes"
639 if not reloading then
640 hook.runAll("config.loaded")
641 end
642end

--- 38 unchanged lines hidden ---