Files
freebsd/lib/libbsdconf/bsdconf_format_loader.c
Devin Teske 3fe5961a0b Add sysconf(8) and libbsdconf(3)
Complete the native configuration trinity: sysctl(8) for live kernel
state, sysrc(8) for rc.conf(5), and sysconf(8) for the remaining base
configuration -- loader.conf(5), sysctl.conf(5), and the make.conf(5)
family -- atop libbsdconf(3).

libbsdconf resurrects figpar as a unified reader/writer.  Callbacks own
semantics; statements may span multiple lines via backslash continuation;
non-seekable input is spooled; writes are atomic (mkstemp, fsync, rename)
with mode/owner preservation.  Format descriptors name each target, its
files, and quoting rules without private parsers.  Multi-file targets
follow boot sourcing order; loader chases loader_conf_files as the boot
loader does.

sysconf(8) is the operator-facing tool: name / name=value on a required
target, sysrc-style list edits, make append and list-strike where they
belong, jail/altroot, and a capsicum sandbox for read-only use.

Sysctl writes validate against the running kernel first -- unknown and
read-only OIDs, CTLFLAG_TUN (pointing at the loader target), and CTLTYPE
range checks -- so a typo or overflow does not land in sysctl.conf.

Make and src treat WITH_/WITHOUT_ as presence knobs (as bsd.mkopt.mk /
src.conf(5) do) and warn on the WITH_*=no form that does not disable the
option, so a bad assignment is caught before an /usr/src build surfaces
it.

The rc target passes through to sysrc(8).

Defaults querying (-d/-D/-A) mirrors sysrc for dumps and descriptions on
targets that have a defaults file; named reads already see defaults, and
-A only widens dump scope.

Manuals are split pkg(8)-style (bsdconf/put/format; sysconf plus
per-target pages).  ATF coverage exercises the frontend.

Co-authored-by:	Faraz Vahedi <[email protected]>
Reviewed by:	fuz, kfv
Differential Revision:	https://reviews.freebsd.org/D58066
2026-09-16 14:28:14 -07:00

52 lines
2.0 KiB
C

/*
* Copyright (c) 2013-2026 Devin Teske <[email protected]>
* Copyright (c) 2021-2026 Faraz Vahedi <[email protected]>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include "bsdconf_formats.h"
/*
* BSDCONF_FORMAT_LOADER: loader.conf(5)
*
* Assignments with no whitespace around the `=' -- the Forth reader in
* support.4th rejects anything else, so BSDCONF_STRICT_EQUALS is enforced.
* Quoted or unquoted input values are accepted when parsing but values are
* always written back quoted (BSDCONF_PUT_QUOTE_ALWAYS), the form every
* loader accepts for every value.
*
* The loader itself hardcodes only /boot/defaults/loader.conf and discovers
* every other file from the loader_conf_files, loader_conf_dirs, and
* local_loader_conf_files directives encountered along the way -- any file
* so discovered may revise those lists in turn. The `defaults' member
* quintet below hands that same discovery to bsdconf_format_files(); the
* static source list is only the fallback for systems whose defaults file
* is missing. The defaults file itself is deliberately excluded from the
* resolved list, mirroring how sysrc(8) excludes /etc/defaults/rc.conf.
*/
static const struct bsdconf_source bsdconf_loader_sources[] = {
{ BSDCONF_SOURCE_FILE, "/boot/device.hints" },
{ BSDCONF_SOURCE_FILE, "/boot/loader.conf" },
{ BSDCONF_SOURCE_DIR, "/boot/loader.conf.d" },
{ BSDCONF_SOURCE_FILE, "/boot/loader.conf.local" },
{ BSDCONF_SOURCE_FILE, NULL },
};
const struct bsdconf_format_def bsdconf_format_loader_def = {
.keyword = "loader",
.path = "/boot/loader.conf",
.sources = bsdconf_loader_sources,
.defaults = "/boot/defaults/loader.conf",
.defaults_env = "LOADER_DEFAULTS",
.files_directive = "loader_conf_files",
.dirs_directive = "loader_conf_dirs",
.local_directive = "local_loader_conf_files",
.processing = BSDCONF_BREAK_ON_EQUALS |
BSDCONF_CASE_SENSITIVE |
BSDCONF_REQUIRE_EQUALS |
BSDCONF_STRICT_EQUALS,
.put = BSDCONF_PUT_QUOTE_ALWAYS |
BSDCONF_PUT_ALLOW_EMPTY,
};