git: 09267cc15284 - main - /etc/rc.subr: add support for kld sysctl variables
Date: Fri, 14 Jul 2023 09:57:33 UTC
The branch main has been updated by dfr: URL: https://cgit.FreeBSD.org/src/commit/?id=09267cc15284795fef958fb9ed786bb2382d6763 commit 09267cc15284795fef958fb9ed786bb2382d6763 Author: Doug Rabson <dfr@FreeBSD.org> AuthorDate: 2023-06-21 12:26:17 +0000 Commit: Doug Rabson <dfr@FreeBSD.org> CommitDate: 2023-07-14 09:49:47 +0000 /etc/rc.subr: add support for kld sysctl variables For kernel modules loaded by scripts in /etc/rc.d and /usr/local/etc/rc.d, if there is a file in /etc/sysctl.conf.d named <kld name>.conf, then this will be loaded using the sysctl(8) utility. For instance, sysctl variable changes for the pf kernel module would be placed in the file /etc/sysctl.conf.d/pf.conf. PR: 272129 Reviewed by: imp freebsd_igalic.co MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D40886 --- etc/mtree/BSD.root.dist | 2 ++ libexec/rc/rc.subr | 3 +++ share/man/man5/sysctl.conf.5 | 10 ++++++++++ 3 files changed, 15 insertions(+) diff --git a/etc/mtree/BSD.root.dist b/etc/mtree/BSD.root.dist index 3a3a3a78d995..2ec079b0abd1 100644 --- a/etc/mtree/BSD.root.dist +++ b/etc/mtree/BSD.root.dist @@ -96,6 +96,8 @@ .. ssl .. + sysctl.conf.d + .. syslog.d .. zfs diff --git a/libexec/rc/rc.subr b/libexec/rc/rc.subr index 6a7f070f7f5b..ef3da46b3206 100644 --- a/libexec/rc/rc.subr +++ b/libexec/rc/rc.subr @@ -1970,6 +1970,9 @@ load_kld() return 1 else info "$1 kernel module loaded." + if [ -f "/etc/sysctl.conf.d/$1.conf" ]; then + sysctl -f "/etc/sysctl.conf.d/$1.conf" + fi fi else debug "load_kld: $1 kernel module already loaded." diff --git a/share/man/man5/sysctl.conf.5 b/share/man/man5/sysctl.conf.5 index 5df168661d85..26ecf763ca12 100644 --- a/share/man/man5/sysctl.conf.5 +++ b/share/man/man5/sysctl.conf.5 @@ -51,6 +51,13 @@ Comments can also exist at the end of a line, as seen in the .Sx EXAMPLES section, below. +.Pp +For kernel modules loaded via +.Xr rc.subr 8 +system , +additional module-specific settings can be applied +by adding a file in the same format named +.Pf /etc/sysctl.d/<module name>.conf . .Sh FILES .Bl -tag -width /etc/rc.d/sysctl_lastload -compact .It Pa /etc/rc.d/sysctl @@ -69,6 +76,9 @@ Initial settings for .It Pa /etc/sysctl.conf.local Machine-specific settings for sites with a common .Pa /etc/sysctl.conf . +.It Pa /etc/sysctl.conf.d +Module specific settings for kernel modules loaded via +.Xr rc.subr 8 . .El .Sh EXAMPLES To turn off logging of programs that exit due to fatal signals you may use