summaryrefslogtreecommitdiff
path: root/stand/lua/config.lua.8
blob: 4fc51c90045fe09ae66666d1c141a69bef6bcbf8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
.\"
.\" SPDX-License-Identifier: BSD-2-Clause-FreeBSD
.\"
.\" Copyright (c) 2018 Kyle Evans <kevans@FreeBSD.org>
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\"    notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\"    notice, this list of conditions and the following disclaimer in the
.\"    documentation and/or other materials provided with the distribution.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.\" $FreeBSD$
.\"
.Dd December 17, 2020
.Dt CONFIG.LUA 8
.Os
.Sh NAME
.Nm config.lua
.Nd FreeBSD config module
.Sh DESCRIPTION
.Nm
contains configuration and module loading functionality.
.Pp
Before hooking into or using the functionality provided by
.Nm ,
it must be included with a statement such as the following:
.Pp
.Dl local config = require("config")
.Ss Exported functions
The following functions are exported from
.Nm :
.Bl -tag -width "config.setCarouselIndex(id, idx)" -offset indent
.It Fn config.getCarouselIndex id
Returns the currently chosen index in the carousel menu entry described by
.Ev id .
See the definition of
.Xr menu.lua 8
for a more in-depth explanation of carousels.
.It Fn config.setCarouselIndex id idx
Set the chosen index for the carousel menu entry described by
.Ev id
to
.Ev idx .
A lookup will be done as needed to determine what value
.Ev idx
actually corresponds to.
.It Fn config.readConf file loaded_files
Process
.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 already been loaded and
should not be loaded again.
.It Fn config.processFile name silent
Process and parse
.Ev name
as a configuration file.
Returns true if
.Ev name
exists and parses without error, false otherwise.
If
.Ev silent
is true,
.Fn config.processFile
will not consider a failure to read the file as a failure.
.It Fn config.parse text
Parse
.Ev text
as a configuration file.
This is used internally by
.Fn config.processFile
to parse the contents of a configuration file.
Returns true if parsing succeeds without error, false if an error occurred.
A message is also printed to the console if an error is encountered.
.It Fn config.loadKernel other_kernel
Attempts to load
.Ev other_kernel
as a kernel.
If
.Ev other_kernel
is unset
.Fn config.loadKernel
will attempt to load
.Dq kernel .
Otherwise, it will try to load
.Dq kernel
first from
.Pa /boot/{other_kernel} ,
then from
.Pa {other_kernel} .
.Pp
The latter is tried in case an absolute path has been specified to the kernel
to use.
.Ev module_path
is amended to include the directory the kernel was found in if either of these
paths result in a loaded kernel.
.Pp
If no kernel was loaded from either of these paths,
.Fn config.loadKernel
will attempt to load a kernel named
.Dq {other_kernel}
from
.Ev module_path
instead of attempting to load a kernel named
.Dq kernel .
.Pp
Returns true if a kernel was loaded, false if no kernel was loaded.
.It Fn config.selectKernel kernel
Set
.Ev kernel
to the kernel that will be loaded when either
.Ic autoboot
or
.Ic boot
are invoked.
This is usually called by the menu system as the kernel selector carousel is
toggled through.
.It Fn config.load file reload
Loads
.Ev file
as a configuration file.
If
.Ev file
is not specified,
.Pa /boot/defaults/loader.conf
is used.
.Fn config.load
will then silently attempt to process any files specified in
.Ev loader_conf_files
after
.Ev file
has been processed.
.Xr nextboot 8
configuration will also be checked as part of
.Fn config.load .
Before returning, all
.Dq config.loaded
hooks will be run if
.Ev reload
is not set to true.
.It Fn config.reload file
Reloads
.Ev file
as a configuration file.
.Fn config.reload
will restore the environment to how it existed before the last config was
loaded, then it will invoke
.Fn config.load file .
Before returning, all
.Dq config.reloaded
hooks will be run.
.It Fn config.loadelf
Loads all ELF objects, the selected kernel as well as any modules configured to
be preloaded in
.Xr loader.conf 5 .
This will be called by the Lua intercepted
.Ic autoboot
and
.Ic boot
commands.
.It Fn config.enableModule modname
Marks a module named
.Fa modname
to be loaded during
.Fn config.loadelf .
If the module was previously blacklisted, then it will be forcefully allowed to
load.
.It Fn config.disableModule modname
Marks a module named
.Fa modname
to not be loaded during
.Fn config.loadelf .
.It Fn config.isModuleEnabled modname
Checks if the module named
.Fa modname
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
.Nm :
.Bl -tag -width "config.reloaded" -offset indent
.It Fn config.loaded
.It Fn config.reloaded
.It Fn kernel.loaded
.It Fn modules.loaded
.El
.Sh SEE ALSO
.Xr loader.conf 5 ,
.Xr loader 8 ,
.Xr menu.lua 8 ,
.Xr nextboot 8
.Sh AUTHORS
The
.Nm
file was originally written by
.An Pedro Souza Aq Mt pedrosouza@FreeBSD.org .
Later work and this manual page was done by
.An Kyle Evans Aq Mt kevans@FreeBSD.org .