--- stand/lua/cli.lua (révision 360454) +++ stand/lua/cli.lua (copie de travail) @@ -127,10 +127,7 @@ 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(...) --- stand/lua/config.lua (révision 360454) +++ stand/lua/config.lua (copie de travail) @@ -460,37 +460,49 @@ 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 = loader.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 = loader.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) + + -- Make sure that we can detect if "loader_conf_files" is set by + -- file by ensuring that 'env_changed' for this variable is not + -- set before processing the file. We do this to be able to + -- distinguish the case where "loader_conf_files" is overriden in + -- the to-read file with the same value that it currently has (in + -- which case files must be loaded) from the case where it is not + -- specified (in which case no file is to be loaded). We'll have + -- to restore the state if not overwritten (see below). + local saved_lcf_env_changed = env_changed["loader_conf_files"] + if saved_lcf_env_changed ~= nil then + env_changed["loader_conf_files"] = nil + end + + -- 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 = env_changed["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 + else + -- Restore back the original "loader_conf_files" value in + -- "env_changed" if it was not overriden in the meantime. + env_changed["loader_conf_files"] = saved_lcf_env_changed end end @@ -602,13 +614,8 @@ file = "/boot/defaults/loader.conf" end - if not config.processFile(file) then - print(MSG_FAILPARSECFG:format(file)) - end + config.readConf(file) - local loaded_files = {file = true} - config.readConfFiles(loader.getenv("loader_conf_files"), loaded_files) - checkNextboot() local verbose = loader.getenv("verbose_loading") or "no" --- stand/lua/config.lua.8 (révision 360454) +++ stand/lua/config.lua.8 (copie de travail) @@ -59,15 +59,24 @@ 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