Date: Thu, 30 Apr 2020 21:04:39 +0000 (UTC) From: Kyle Evans <kevans@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r360506 - head/stand/lua Message-ID: <202004302104.03UL4dVW087358@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: kevans Date: Thu Apr 30 21:04:39 2020 New Revision: 360506 URL: https://svnweb.freebsd.org/changeset/base/360506 Log: lualoader: config: improve readConfFiles, rename to readConf The previous interface was pretty bad, and required the caller to get some implementation details correct that it really shouldn't need to (e.g. loader_conf_files handling) and pass in an empty table for it to use. The new and much improved interface, readConf, is much less of a hack; hiding these implementation details and just doing the right thing. config.lua will now use it to process /boot/defaults/loader.conf and the subsequent loader_conf_files from there, and read-conf will also use it. This improvement submitted by Olivier (cited below), loader_conf_files handling from the original patch was changed to just clobber it before processing and not bother restoring it after the fact following r360505 where it's now guaranteed to evade the loader environment. PR: 244640 Submitted by: Olivier Certner (olivier freebsd free fr> Modified: head/stand/lua/cli.lua head/stand/lua/config.lua head/stand/lua/config.lua.8 Modified: head/stand/lua/cli.lua ============================================================================== --- head/stand/lua/cli.lua Thu Apr 30 20:58:58 2020 (r360505) +++ head/stand/lua/cli.lua Thu Apr 30 21:04:39 2020 (r360506) @@ -127,10 +127,7 @@ end 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(...) Modified: head/stand/lua/config.lua ============================================================================== --- head/stand/lua/config.lua Thu Apr 30 20:58:58 2020 (r360505) +++ head/stand/lua/config.lua Thu Apr 30 21:04:39 2020 (r360506) @@ -488,36 +488,36 @@ function config.parse(text) 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 = 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 = 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) + + -- The final value of loader_conf_files is not important, so just + -- clobber it here. We'll later check if it's no longer nil and process + -- the new value for files to read. + setEnv("loader_conf_files", nil) + + -- 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 = getEnv("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 end end @@ -630,12 +630,7 @@ function config.load(file, reloading) file = "/boot/defaults/loader.conf" end - if not config.processFile(file) then - print(MSG_FAILPARSECFG:format(file)) - end - - local loaded_files = {file = true} - config.readConfFiles(getEnv("loader_conf_files"), loaded_files) + config.readConf(file) checkNextboot() Modified: head/stand/lua/config.lua.8 ============================================================================== --- head/stand/lua/config.lua.8 Thu Apr 30 20:58:58 2020 (r360505) +++ head/stand/lua/config.lua.8 Thu Apr 30 21:04:39 2020 (r360506) @@ -26,7 +26,7 @@ .\" .\" $FreeBSD$ .\" -.Dd April 27, 2020 +.Dd April 30, 2020 .Dt CONFIG.LUA 8 .Os .Sh NAME @@ -59,15 +59,24 @@ to 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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202004302104.03UL4dVW087358>