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