1088b5ad3SKyle Evans.\" 2088b5ad3SKyle Evans.\" SPDX-License-Identifier: BSD-2-Clause-FreeBSD 3088b5ad3SKyle Evans.\" 4088b5ad3SKyle Evans.\" Copyright (c) 2018 Kyle Evans <kevans@FreeBSD.org> 5088b5ad3SKyle Evans.\" 6088b5ad3SKyle Evans.\" Redistribution and use in source and binary forms, with or without 7088b5ad3SKyle Evans.\" modification, are permitted provided that the following conditions 8088b5ad3SKyle Evans.\" are met: 9088b5ad3SKyle Evans.\" 1. Redistributions of source code must retain the above copyright 10088b5ad3SKyle Evans.\" notice, this list of conditions and the following disclaimer. 11088b5ad3SKyle Evans.\" 2. Redistributions in binary form must reproduce the above copyright 12088b5ad3SKyle Evans.\" notice, this list of conditions and the following disclaimer in the 13088b5ad3SKyle Evans.\" documentation and/or other materials provided with the distribution. 14088b5ad3SKyle Evans.\" 15088b5ad3SKyle Evans.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16088b5ad3SKyle Evans.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17088b5ad3SKyle Evans.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18088b5ad3SKyle Evans.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19088b5ad3SKyle Evans.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20088b5ad3SKyle Evans.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21088b5ad3SKyle Evans.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22088b5ad3SKyle Evans.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23088b5ad3SKyle Evans.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24088b5ad3SKyle Evans.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25088b5ad3SKyle Evans.\" SUCH DAMAGE. 26088b5ad3SKyle Evans.\" 27088b5ad3SKyle Evans.\" $FreeBSD$ 28088b5ad3SKyle Evans.\" 29*4634bb1fSKyle Evans.Dd December 12, 2020 30088b5ad3SKyle Evans.Dt CONFIG.LUA 8 31088b5ad3SKyle Evans.Os 32088b5ad3SKyle Evans.Sh NAME 33088b5ad3SKyle Evans.Nm config.lua 34088b5ad3SKyle Evans.Nd FreeBSD config module 35088b5ad3SKyle Evans.Sh DESCRIPTION 36088b5ad3SKyle Evans.Nm 37088b5ad3SKyle Evanscontains configuration and module loading functionality. 38088b5ad3SKyle Evans.Pp 39088b5ad3SKyle EvansBefore hooking into or using the functionality provided by 40088b5ad3SKyle Evans.Nm , 41088b5ad3SKyle Evansit must be included with a statement such as the following: 42088b5ad3SKyle Evans.Pp 43088b5ad3SKyle Evans.Dl local config = require("config") 44088b5ad3SKyle Evans.Ss Exported functions 45088b5ad3SKyle EvansThe following functions are exported from 46088b5ad3SKyle Evans.Nm : 47088b5ad3SKyle Evans.Bl -tag -width "config.setCarouselIndex(id, idx)" -offset indent 48088b5ad3SKyle Evans.It Fn config.getCarouselIndex id 49088b5ad3SKyle EvansReturns the currently chosen index in the carousel menu entry described by 50088b5ad3SKyle Evans.Ev id . 51088b5ad3SKyle EvansSee the definition of 52088b5ad3SKyle Evans.Xr menu.lua 8 53088b5ad3SKyle Evansfor a more in-depth explanation of carousels. 54088b5ad3SKyle Evans.It Fn config.setCarouselIndex id idx 55088b5ad3SKyle EvansSet the chosen index for the carousel menu entry described by 56088b5ad3SKyle Evans.Ev id 57088b5ad3SKyle Evansto 58088b5ad3SKyle Evans.Ev idx . 59088b5ad3SKyle EvansA lookup will be done as needed to determine what value 60088b5ad3SKyle Evans.Ev idx 61088b5ad3SKyle Evansactually corresponds to. 623fe0ac6aSKyle Evans.It Fn config.readConf file loaded_files 637a5c6c8bSKyle EvansProcess 643fe0ac6aSKyle Evans.Pa file 653fe0ac6aSKyle Evansas a configuration file 663fe0ac6aSKyle Evans.Po e.g., as 673fe0ac6aSKyle Evans.Pa loader.conf 683fe0ac6aSKyle Evans.Pc 693fe0ac6aSKyle Evansand then processing files listed in 703fe0ac6aSKyle Evans.Ev loader_conf_files 713fe0ac6aSKyle Evansvariable 723fe0ac6aSKyle Evans.Po see 733fe0ac6aSKyle Evans.Xr loader.conf 5 743fe0ac6aSKyle Evans.Pc . 753fe0ac6aSKyle EvansThe caller may optionally pass in a table as the 767a5c6c8bSKyle Evans.Ev loaded_files 773fe0ac6aSKyle Evansargument, which uses filenames as keys and any non-nil value to 783fe0ac6aSKyle Evansindicate that the file named by the key has already been loaded and 793fe0ac6aSKyle Evansshould not be loaded again. 80088b5ad3SKyle Evans.It Fn config.processFile name silent 81088b5ad3SKyle EvansProcess and parse 82088b5ad3SKyle Evans.Ev name 83088b5ad3SKyle Evansas a configuration file. 84088b5ad3SKyle EvansReturns true if 85088b5ad3SKyle Evans.Ev name 86088b5ad3SKyle Evansexists and parses without error, false otherwise. 87088b5ad3SKyle EvansIf 88088b5ad3SKyle Evans.Ev silent 89088b5ad3SKyle Evansis true, 90088b5ad3SKyle Evans.Fn config.processFile 91088b5ad3SKyle Evanswill not consider a failure to read the file as a failure. 92088b5ad3SKyle Evans.It Fn config.parse text 93088b5ad3SKyle EvansParse 94088b5ad3SKyle Evans.Ev text 95088b5ad3SKyle Evansas a configuration file. 96088b5ad3SKyle EvansThis is used internally by 97088b5ad3SKyle Evans.Fn config.processFile 98088b5ad3SKyle Evansto parse the contents of a configuration file. 99088b5ad3SKyle EvansReturns true if parsing succeeds without error, false if an error occurred. 100088b5ad3SKyle EvansA message is also printed to the console if an error is encountered. 101088b5ad3SKyle Evans.It Fn config.loadKernel other_kernel 102088b5ad3SKyle EvansAttempts to load 103088b5ad3SKyle Evans.Ev other_kernel 104088b5ad3SKyle Evansas a kernel. 105088b5ad3SKyle EvansIf 106088b5ad3SKyle Evans.Ev other_kernel 107088b5ad3SKyle Evansis unset 108088b5ad3SKyle Evans.Fn config.loadKernel 109088b5ad3SKyle Evanswill attempt to load 110088b5ad3SKyle Evans.Dq kernel . 111088b5ad3SKyle EvansOtherwise, it will try to load 112088b5ad3SKyle Evans.Dq kernel 113088b5ad3SKyle Evansfirst from 114088b5ad3SKyle Evans.Pa /boot/{other_kernel} , 115088b5ad3SKyle Evansthen from 116088b5ad3SKyle Evans.Pa {other_kernel} . 117088b5ad3SKyle Evans.Pp 118088b5ad3SKyle EvansThe latter is tried in case an absolute path has been specified to the kernel 119088b5ad3SKyle Evansto use. 120088b5ad3SKyle Evans.Ev module_path 121088b5ad3SKyle Evansis amended to include the directory the kernel was found in if either of these 122088b5ad3SKyle Evanspaths result in a loaded kernel. 123088b5ad3SKyle Evans.Pp 124088b5ad3SKyle EvansIf no kernel was loaded from either of these paths, 125088b5ad3SKyle Evans.Fn config.loadKernel 126088b5ad3SKyle Evanswill attempt to load a kernel named 127088b5ad3SKyle Evans.Dq {other_kernel} 128088b5ad3SKyle Evansfrom 129088b5ad3SKyle Evans.Ev module_path 130088b5ad3SKyle Evansinstead of attempting to load a kernel named 131088b5ad3SKyle Evans.Dq kernel . 132088b5ad3SKyle Evans.Pp 133088b5ad3SKyle EvansReturns true if a kernel was loaded, false if no kernel was loaded. 134088b5ad3SKyle Evans.It Fn config.selectKernel kernel 135088b5ad3SKyle EvansSet 136088b5ad3SKyle Evans.Ev kernel 137088b5ad3SKyle Evansto the kernel that will be loaded when either 138088b5ad3SKyle Evans.Ic autoboot 139088b5ad3SKyle Evansor 140088b5ad3SKyle Evans.Ic boot 141088b5ad3SKyle Evansare invoked. 142088b5ad3SKyle EvansThis is usually called by the menu system as the kernel selector carousel is 143088b5ad3SKyle Evanstoggled through. 144088b5ad3SKyle Evans.It Fn config.load file reload 145088b5ad3SKyle EvansLoads 146088b5ad3SKyle Evans.Ev file 147088b5ad3SKyle Evansas a configuration file. 148088b5ad3SKyle EvansIf 149088b5ad3SKyle Evans.Ev file 150088b5ad3SKyle Evansis not specified, 151088b5ad3SKyle Evans.Pa /boot/defaults/loader.conf 152088b5ad3SKyle Evansis used. 153088b5ad3SKyle Evans.Fn config.load 154088b5ad3SKyle Evanswill then silently attempt to process any files specified in 155088b5ad3SKyle Evans.Ev loader_conf_files 156088b5ad3SKyle Evansafter 157088b5ad3SKyle Evans.Ev file 158088b5ad3SKyle Evanshas been processed. 159088b5ad3SKyle Evans.Xr nextboot 8 160088b5ad3SKyle Evansconfiguration will also be checked as part of 161088b5ad3SKyle Evans.Fn config.load . 162088b5ad3SKyle EvansBefore returning, all 163088b5ad3SKyle Evans.Dq config.loaded 164088b5ad3SKyle Evanshooks will be run if 165088b5ad3SKyle Evans.Ev reload 166088b5ad3SKyle Evansis not set to true. 167088b5ad3SKyle Evans.It Fn config.reload file 168088b5ad3SKyle EvansReloads 169088b5ad3SKyle Evans.Ev file 170088b5ad3SKyle Evansas a configuration file. 171088b5ad3SKyle Evans.Fn config.reload 172088b5ad3SKyle Evanswill restore the environment to how it existed before the last config was 173088b5ad3SKyle Evansloaded, then it will invoke 174088b5ad3SKyle Evans.Fn config.load file . 175088b5ad3SKyle EvansBefore returning, all 176088b5ad3SKyle Evans.Dq config.reloaded 177088b5ad3SKyle Evanshooks will be run. 178088b5ad3SKyle Evans.It Fn config.loadelf 179088b5ad3SKyle EvansLoads all ELF objects, the selected kernel as well as any modules configured to 180088b5ad3SKyle Evansbe preloaded in 181088b5ad3SKyle Evans.Xr loader.conf 5 . 182088b5ad3SKyle EvansThis will be called by the Lua intercepted 183088b5ad3SKyle Evans.Ic autoboot 184088b5ad3SKyle Evansand 185088b5ad3SKyle Evans.Ic boot 186088b5ad3SKyle Evanscommands. 187*4634bb1fSKyle Evans.It Fn config.enableModule modname 188*4634bb1fSKyle EvansMarks a module named 189*4634bb1fSKyle Evans.Fa modname 190*4634bb1fSKyle Evansto be loaded during 191*4634bb1fSKyle Evans.Fn config.loadelf . 192*4634bb1fSKyle EvansIf the module was previously blacklisted, then it will be forcefully allowed to 193*4634bb1fSKyle Evansload. 194*4634bb1fSKyle Evans.It Fn config.disableModule modname 195*4634bb1fSKyle EvansMarks a module named 196*4634bb1fSKyle Evans.Fa modname 197*4634bb1fSKyle Evansto not be loaded during 198*4634bb1fSKyle Evans.Fn config.loadelf . 199*4634bb1fSKyle Evans.It Fn config.isModuleEnabled modname 200*4634bb1fSKyle EvansChecks if the module named 201*4634bb1fSKyle Evans.Fa modname 202*4634bb1fSKyle Evanswill be loaded during 203*4634bb1fSKyle Evans.Fn config.loadelf . 204*4634bb1fSKyle EvansIt checks both that the module is marked for loading and that it is either 205*4634bb1fSKyle Evansforced or not blacklisted. 206088b5ad3SKyle Evans.El 207088b5ad3SKyle Evans.Ss Defined Hooks 208088b5ad3SKyle EvansThe following hooks are defined in 209088b5ad3SKyle Evans.Nm : 210088b5ad3SKyle Evans.Bl -tag -width "config.reloaded" -offset indent 21160a2823cSKyle Evans.It Fn config.loaded 21260a2823cSKyle Evans.It Fn config.reloaded 21360a2823cSKyle Evans.It Fn kernel.loaded 21460a2823cSKyle Evans.It Fn modules.loaded 215088b5ad3SKyle Evans.El 216088b5ad3SKyle Evans.Sh SEE ALSO 217088b5ad3SKyle Evans.Xr loader.conf 5 , 218088b5ad3SKyle Evans.Xr loader 8 , 219088b5ad3SKyle Evans.Xr menu.lua 8 , 220088b5ad3SKyle Evans.Xr nextboot 8 221088b5ad3SKyle Evans.Sh AUTHORS 222088b5ad3SKyle EvansThe 223088b5ad3SKyle Evans.Nm 224088b5ad3SKyle Evansfile was originally written by 225088b5ad3SKyle Evans.An Pedro Souza Aq Mt pedrosouza@FreeBSD.org . 226088b5ad3SKyle EvansLater work and this manual page was done by 227088b5ad3SKyle Evans.An Kyle Evans Aq Mt kevans@FreeBSD.org . 228