From ff9e3f3b9667ec418c7ef27c27328d2f732fb2bb Mon Sep 17 00:00:00 2001 From: Kyle Evans Date: Tue, 28 Jan 2020 02:42:33 +0000 Subject: [PATCH] MFC r357103-r357104: unbreak local.lua, add a modules.loaded hook r357103: loader.lua: re-arrange to load local.lua *after* config loading The major problem with the current ordering is that loader.conf may contain all of the magic we need to actually setup the console, so loading local.lua prior to that can make it excessively difficult and annoying to debug (whoops, sorry Ravi & Warner). The new ordering has some implications, but I suspect they are a non-issue. The first is that it's no longer possible for the local module to inject any logic prior to loading config -- I suspect no one has relied on this. The second implication is that the config.loaded hook is now useless, as the local module will always be included after that hook would have fired. For config.loaded, I will opt to leave it in, just in case we add an early point for local lua to get injected or in case one wants to schedule some deferred logic in a custom loader.lua. The overhead of having it if no hooks will be invoked is relatively minimal. r357104: lua: add modules.loaded hook This may be used for the local module to hook in and load any additional modules that it wants, since it can't modify the modules table internal to config. We may consider adding API to do so at a later time, but I suspect it will be more complicated to use with little return. status is captured but ignored for the purpose of loading the hook. status will be false if *any* module failed to load, but we typically don't let that halt the boot so there's no reason to let it halt hooks. Some vendors or setups may have expected fails that would be actively thwarted by checking it. We may, at a later date, consider adding an API for letting non-config modules check which modules have successfully (or not) loaded in case an unexpected failure *should* halt whatever they are doing. --- stand/lua/config.lua | 7 +++++-- stand/lua/loader.lua | 4 ++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/stand/lua/config.lua b/stand/lua/config.lua index c3f79314b20..42b0959863c 100644 --- a/stand/lua/config.lua +++ b/stand/lua/config.lua @@ -623,7 +623,7 @@ end function config.loadelf() local xen_kernel = loader.getenv('xen_kernel') local kernel = config.kernel_selected or config.kernel_loaded - local loaded + local loaded, status if xen_kernel ~= nil then print(MSG_XENKERNLOADING) @@ -640,9 +640,12 @@ function config.loadelf() end print(MSG_MODLOADING) - return loadModule(modules, not config.verbose) + status = loadModule(modules, not config.verbose) + hook.runAll("modules.loaded") + return status end hook.registerType("config.loaded") hook.registerType("config.reloaded") +hook.registerType("modules.loaded") return config diff --git a/stand/lua/loader.lua b/stand/lua/loader.lua index c875f63a1b4..dacabe96e62 100644 --- a/stand/lua/loader.lua +++ b/stand/lua/loader.lua @@ -42,14 +42,14 @@ local password = require("password") -- need it. local menu -try_include("local") - config.load() + -- Our console may have been setup for a different color scheme before we get -- here, so make sure we set the default. if color.isEnabled() then printc(color.default()) end +try_include("local") if not core.isMenuSkipped() then menu = require("menu") end -- 2.45.0