From 7ed84fa14b00cdacfe9b43019cba7a14b33af352 Mon Sep 17 00:00:00 2001 From: Kyle Evans Date: Thu, 17 Dec 2020 18:24:36 +0000 Subject: [PATCH] lualoader: cli: provide a show-module-options loader command This effectively dumps everything lualoader knows about to the console using the libsa pager; that particular lua interface was added in r368591. A pager stub implementation has been added that just dumps the output as-is as a compat shim for older loader binaries that do not have lpager. This stub should be moved into a more appropriate .lua file if we add anything else that needs the pager. --- stand/lua/cli.lua | 67 ++++++++++++++++++++++++++++++++++++++++++ stand/lua/cli.lua.8 | 8 ++++- stand/lua/config.lua | 7 +++++ stand/lua/config.lua.8 | 11 ++++++- 4 files changed, 91 insertions(+), 2 deletions(-) diff --git a/stand/lua/cli.lua b/stand/lua/cli.lua index caf7d6476a4..9ed26af4b70 100644 --- a/stand/lua/cli.lua +++ b/stand/lua/cli.lua @@ -32,6 +32,18 @@ local core = require("core") local cli = {} +if not pager then + -- shim for the pager module that just doesn't do it. + -- XXX Remove after 12.2 goes EoL. + pager = { + open = function() end, + close = function() end, + output = function(str) + printc(str) + end, + } +end + -- Internal function -- Parses arguments to boot and returns two values: kernel_name, argstr -- Defaults to nil and "" respectively. @@ -173,6 +185,61 @@ cli["toggle-module"] = function(...) setModule(module, not config.isModuleEnabled(module)) end +cli["show-module-options"] = function() + local module_info = config.getModuleInfo() + local modules = module_info['modules'] + local blacklist = module_info['blacklist'] + local lines = {} + + for module, info in pairs(modules) do + if #lines > 0 then + lines[#lines + 1] = "" + end + + lines[#lines + 1] = "Name: " .. module + if info.name then + lines[#lines + 1] = "Path: " .. info.name + end + + if info.type then + lines[#lines + 1] = "Type: " .. info.type + end + + if info.flags then + lines[#lines + 1] = "Flags: " .. info.flags + end + + if info.before then + lines[#lines + 1] = "Before load: " .. info.before + end + + if info.after then + lines[#lines + 1] = "After load: " .. info.after + end + + if info.error then + lines[#lines + 1] = "Error: " .. info.error + end + + local status + if blacklist[module] and not info.force then + status = "Blacklisted" + elseif info.load == "YES" then + status = "Load" + else + status = "Don't load" + end + + lines[#lines + 1] = "Status: " .. status + end + + pager.open() + for i, v in ipairs(lines) do + pager.output(v .. "\n") + end + pager.close() +end + -- Used for splitting cli varargs into cmd_name and the rest of argv function cli.arguments(...) local argv = {...} diff --git a/stand/lua/cli.lua.8 b/stand/lua/cli.lua.8 index 0fafec9add4..390831d2145 100644 --- a/stand/lua/cli.lua.8 +++ b/stand/lua/cli.lua.8 @@ -26,7 +26,7 @@ .\" .\" $FreeBSD$ .\" -.Dd December 12, 2020 +.Dd December 17, 2020 .Dt CLI.LUA 8 .Os .Sh NAME @@ -96,6 +96,8 @@ module provides the following default commands: .Ic disable-module .It .Ic toggle-module +.It +.Ic show-module-options .El .Pp For @@ -125,6 +127,10 @@ commands manipulate the list of modules to be loaded along with the kernel. Modules blacklisted are considered disabled by .Ic toggle-module . These commands will override any such restriction as needed. +The +.Ic show-module-options +command will dump the list of modules that loader has been made aware of and +any applicable options using paged output. .Ss Exported Functions The following functions are exported from .Nm : diff --git a/stand/lua/config.lua b/stand/lua/config.lua index c7a638dd653..2eb10f7c772 100644 --- a/stand/lua/config.lua +++ b/stand/lua/config.lua @@ -721,6 +721,13 @@ function config.isModuleEnabled(modname) return not blacklist[modname] end +function config.getModuleInfo() + return { + modules = modules, + blacklist = getBlacklist() + } +end + hook.registerType("config.loaded") hook.registerType("config.reloaded") hook.registerType("kernel.loaded") diff --git a/stand/lua/config.lua.8 b/stand/lua/config.lua.8 index 059cc49fe42..4fc51c90045 100644 --- a/stand/lua/config.lua.8 +++ b/stand/lua/config.lua.8 @@ -26,7 +26,7 @@ .\" .\" $FreeBSD$ .\" -.Dd December 12, 2020 +.Dd December 17, 2020 .Dt CONFIG.LUA 8 .Os .Sh NAME @@ -203,6 +203,15 @@ will be loaded during .Fn config.loadelf . It checks both that the module is marked for loading and that it is either forced or not blacklisted. +.It Fn config.getModuleInfo +Returns a table with +.Dq modules +and +.Dq blacklist +tables describing the modules that the config module has been made aware of via +.Xr loader.conf 5 +as well as a representation of +.Ar module_blacklist . .El .Ss Defined Hooks The following hooks are defined in -- 2.45.0