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.
This commit is contained in:
Kyle Evans 2020-12-17 18:24:36 +00:00
parent 3326f7e9bb
commit 7ed84fa14b
4 changed files with 91 additions and 2 deletions

View File

@ -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 = {...}

View File

@ -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 :

View File

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

View File

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