Commit Graph
253 Commits
Author SHA1 Message Date
Jose Luis Duran e6f8afd1e8 rc.conf: Fix typo in comment
The correct path is /etc/defaults/rc.conf (defaults in plural).

Reviewed by:	netchild
Fixes:		cc4eb1ea10 ("Add support for a /etc/defaults/vendor.conf override file")
MFC after:	3 days
Differential Revision:	https://reviews.freebsd.org/D56456

(cherry picked from commit 8e08080ee5)
2026-04-20 04:44:12 +00:00
Enji Cooper 5975766234 rc.subr(8): run trailing-whitespace-fixer
This change deletes benign trailing whitespace from rc.subr, making
future non-stylistic changes easier to spot.

MFC after:	1 week

(cherry picked from commit 4e9041a786)
2026-01-31 15:04:46 -08:00
Cy Schubert d077ec7c0f rc.d/ipfilter: ipfilter must be enabled for options to take
ipfilter options are erased and reset to default when ipfilter is
disabled. This results in nullifying options from rc.conf that were
previously set.

8d6feaaaa2, which added this code, was incorrect as it was for a bug in
ipfilter 4.2.28 and no longer applies to ipfilter 5.1.2.

Fixes:		8d6feaaaa2

(cherry picked from commit cc1e4aae5a)
2025-12-10 13:10:47 -08:00
Cy Schubert 07b5eb3b6a rc.d/{ipfilter,ippool}: Fix typo in variable name
(cherry picked from commit f04b23ce35)
2025-12-10 13:10:47 -08:00
Cy Schubert c7cfc16f7c ipfilter: Load optionlist prior to ippool invocation
As a safety precaution df381bec2d limits ippool hash table size to 1K.
This causes any legitimely large hash table to fail to load. The
htable_size_max ipf tuneable adjusts this but the adjustment is made
in the ipfilter rc script, invoked after the ippool script (because it
depends on ippool). Let's load the ipfilter_optionlist in ippool as well.
ipfilter_optionlist load will also occur in the ipfilter rc script in case
the user uses ipfilter without ippool.

Fixes:		df381bec2d

(cherry picked from commit d5d005e9bf)
2025-12-02 07:28:55 -08:00
Jose Luis Duran 549cba3c9d rc: dmesg: Allow umask to be configurable
Allow umask to be configurable.

Being able to set the umask via an rc variable is useful when setting:

    security.bsd.unprivileged_read_msgbuf=0

As it allows a user to configure:

    dmesg_umask="066"

Without modifying the rc script, and preventing the contents of the
$dmesg_file (/var/run/dmesg.boot) from being publicly readable.

PR:		272552
Reviewed by:	netchild
MFC after:	2 days
Differential Revision:	https://reviews.freebsd.org/D53169

(cherry picked from commit edadbc6ee9)
2025-10-20 16:05:40 +00:00
Jose Luis Duran 2779d63101 rc.conf: Fix typo interferring -> interfering
Reviewed by:	emaste
MFC after:	2 days
Differential Revision:	https://reviews.freebsd.org/D53168

(cherry picked from commit 982d70ca2e)
2025-10-20 16:04:00 +00:00
Dag-Erling Smørgrav a42bf0da8d rc.d: Fix mountd service script.
This script references variables beloning to the nfsd and zfs services,
therefore it needs to load their configurations.

MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D51473

(cherry picked from commit aa183bc7f9)
2025-08-05 09:32:41 +00:00
Mateusz Piotrowski 7ee04c7b17 rc: Use check_jail to check values of security.jail MIBs
PR:		282404
Reviewed by:	markj, netchild
Approved by:	markj (mentor)
MFC after:	2 weeks
Event:		Berlin Hackathon 202507
Differential Revision:	https://reviews.freebsd.org/D47329

(cherry picked from commit 46f18ecf8d)
2025-07-30 11:55:30 +02:00
Michael Proto 0bb490bdbf /etc/rc.d/pf: Fix for multi-line pf_fallback_rules
Setting multiple pf_fallback_rules in /etc/rc.conf as per the
documentation produces invalid pf syntax due to the lack of echo
quoting $pf_fallback_rules in /etc/rc.d/pf. Adding quotes around
the $pf_fallback_rules echo maintains newlines needed for valid
pfctl syntax. Provided patch resolves the issue

Also updating rc.conf(5) to reflect that multi-line pf_fallback_rules
should not include a trailing backslash (\) as line breaks are
needed when passing rules to pfctl via stdin.

PR:		288197
Reviewed by:	kp
MFC after:	2 weeks

(cherry picked from commit 9e8c1f9576)
2025-07-29 09:48:51 +02:00
Mateusz Piotrowski cdd5fece16 rc.subr: Fix a typo in check_jail()'s description
MFC after:	3 days
Event:		Berlin Hackathon 202507

(cherry picked from commit 5d5258653b)
2025-07-15 02:24:27 +02:00
Eugene Grosbein 5d15e09a26 libexec/rc: MFC: improve performance of pccard_ether script
Replace "ifconfig -ul" with "ifconfig -n" because netlink-enabled
/sbin/ifconfig utility has sub-optimal performance for listing.

Combined with the commit b1b17432aa,
these changes mostly eliminate performance regression of the command
"service devd start" for a system having hundreds of network interfaces
created before devd starts, after FreeBSD 14+ switched
/sbin/ifconfig to netlink(4)

PR:		287872

(cherry picked from commit 6d3bc576ab)
(cherry picked from commit 24e8ed535f)
2025-07-13 22:48:37 +07:00
Cy Schubert 067cf605f8 Revert "ntpd: Use the ntpd -u option in preference to the rc su plumbing"
Using the ntpd -u option to set the credentials ntpd is to run under
while still using rc(8) to invoke causes some FreeBSD installs to fail
to load mac_ntp. The fact that that can_run_nonroot() does not
indicate why failures occur leaves people on the mailing lists
guessing as to why there are failures. Let's revert back to using
the rc(8) provided su. The ntpd rc script will be rewritten when
the ntpd chroot will be implemented.

Reported on:	freebsd-stable@

This reverts commit 521f66715a.

(cherry picked from commit 5ca7754519)
2025-03-11 10:59:36 -07:00
Cy Schubert 2fae556f6a var_run: Clean up style
Clean up style and make more consistent.

Replace test with if-then-else to make the script more legible.

Replace the call to dirname with the shell %/* operator avoiding a
fork & exec.

Reorder the test for $var_run_autosave before the test for /var/run on
tmpfs. This avoids gratuitously scanning the mount table for a tmpfs
/var/run.

Initial concept by and in discussion with:
	Harry Schmalzbauer <[email protected]>

No functional change intended.

MFC after:		2 weeks
Differnential revision:	https://reviews.freebsd.org/D47773

(cherry picked from commit ed9712f894)
2025-03-04 20:46:14 -08:00
Cy Schubert 92c834c698 ntpd: Use the ntpd -u option in preference to the rc su plumbing
Using the rc plumbing to setuid(2) is preferred as it allows the user
to use the -i option in ntpd_flags to chroot ntpd.

Chrooting ntpd by default will be a 2025 project.

MFC after:		1 week
Reviewed by:		markj
Differential Revision:	https://reviews.freebsd.org/D48191

(cherry picked from commit 521f66715a)
2025-02-24 16:38:10 -08:00
Tijl Coosemans 242eb8d4e0 rc.d/sendmail: Fix error with some configurations
The sendmail startup script can run 4 daemons: sendmail, sendmail_submit,
sendmail_outbound, and sendmail_msp_queue.  Of the first 3 at most one
can be enabled.  There's a run_rc_command call for each and the ones for
sendmail and sendmail_msp_queue run unconditionally.  For some rc
commands this triggers warnings or errors when sendmail_enable="NO" or
sendmail_msp_queue_enable="NO".  Since d2e7bb630b these errors are
propagated and the whole script fails.

Fix this by first determining which daemons are enabled, setting ${name}
and ${rcvar} accordingly, and then always calling run_rc_command
conditionally.

Also replace ${name}.cf with sendmail.cf because ${name} isn't always
sendmail.

PR:		282585
Reviewed by:	markj
Differential Revision:	https://reviews.freebsd.org/D47757

(cherry picked from commit 6b17d944a1)
2024-12-31 14:17:46 +01:00
Cy Schubert 2904d7309b rc.d/var_run: Add missing $(dirname)
We intend to create the containing directory here. Fix this typo.

PR:		282939

(cherry picked from commit 4d58cf6ff9)
2024-12-04 09:09:41 -08:00
Cy Schubert 6739198793 ipfilter: Set ipf -T optionlist at boot
There is no easy way to set ipfilter optionlist variables during boot.
Add plumbing to the rc script to support this.

PR:			130555
Reviewed by:		jlduran
Differential Revision:	https://reviews.freebsd.org/D47346

(cherry picked from commit 8d6feaaaa2)
2024-11-18 16:27:06 -08:00
Mateusz Piotrowski d36998a6cc rc.d/sendmail: Return non-zero if the daemon fails to start or is not running
If you have a mail server that is running sendmail daemon
(sendmail_enable=YES) and sendmail queue runner (sendmail_msp_queue=YES)
and the sendmail daemon dies, /etc/rc.d/sendmail status does see the
daemon is not running but returns 0 as the exit code.  This prevents
other programs (like puppet) from restarting sendmail to fix the issue.

Make sure that the exit code is propagated towards the end of the script
if any of the sendmail services fail.

This patch does not call exit directly but instead just sets the exit
status code by calling exit in a subshell. This way we do not exit the
current shell in case the service script is sourced (e.g., when
rc_fast_and_loose is active).

PR:		223132
MFC after:	2 weeks
Reported by:	pirzyk
Discussed with:	jilles, eugen
Reviewed by:	christos, gshapiro (previous version), markj
Approved by:	christos (mentor), markj (mentor)
Differential Revision:	https://reviews.freebsd.org/D46862
Co-authored-by: Jim Pirzyk <[email protected]>

(cherry picked from commit d2e7bb630b)
2024-11-04 15:55:55 +01:00
Robert William Vesterman a151fecbd5 libexec/rc/rc.d/netif: Typo fix
Just fixing a typo ("configuriing" => "configuring").

Pull Request:	https://github.com/freebsd/freebsd-src/pull/1484

(cherry picked from commit 65691b2daf)
2024-10-30 17:58:21 -07:00
Mateusz Piotrowski 0313a36cb9 rc/tests: Skip oomprotect tests in a jail
oomprotect cannot be used in a jail.

Reviewed by:	bnovkov, christos, markj
Approved by:	bnovkov (mentor), christos (mentor), markj (mentor)
MFC after:	1 week

(cherry picked from commit 6fa42b91ca)
2024-10-28 13:46:05 +01:00
Mateusz Piotrowski 4fc260561e rc.d/sendmail: Fix stopping service during shutdown
The sendmail service script needs to be stopped during shutdown
to ensure a clean shutdown of active SMTP connections (and writing
any in memory queue files).

rcorder(8) requires the rcorder block to be an uninterrupted sequence of
REQUIRE, PROVIDE, BEFORE, and KEYWORD lines. Having a comment in between
REQUIRE and KEYWORD makes rcorder stop parsing the block when it reaches
the comment.

Fix that by moving the comment out from the rcorder block.

Reviewed by:	bnovkov, christos, gshapiro, markj
Approved by:	bnovkov (mentor), christos (mentor), markj (mentor)
MFC after:	3 days
Differential Revision:	https://reviews.freebsd.org/D46924

(cherry picked from commit 8751fbe36f)
2024-10-14 12:23:44 +02:00
Mateusz Piotrowski 35d8a02eea rc.subr: Consistently use an absolute path for sysrc
MFC after:	2 weeks
Approved by:	christos

(cherry picked from commit 401516dbc5)
2024-10-02 11:27:05 +02:00
Bjoern A. Zeeb 267ad286ef rc: network.subr update consitency with older change (v6/v4 order)
As of 1b5be7204e we setup parts of IPv6
before IPv4 if configured.  For consistency change a case in ifn_start()
calling ipv6_up() before ipv4_up() and reverse in ifn_stop().

Reviewed by:	zlei
Differential Revision: https://reviews.freebsd.org/D33426

(cherry picked from commit ed4d2a54fc)
2024-09-28 11:07:58 +00:00
Ed Maste 6b9c7f29b0 Remove "All Rights Reserved" from FreeBSD Foundation copyrights
These ones were unambiguous cases where the Foundation was the only
listed copyright holder.

Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 5c2bc3db20)
(cherry picked from commit f06d322e9d)
2024-09-07 12:30:19 -04:00
Isaac Cilia Attard 1f0f31f082 dhclient: rc.conf option to disable ARP resolution
Introduce a new rc.conf option to not wait for ARP resolution within
dhclient. This is plausible on many modern networks where it is possible
to trust the DHCP server to know whether an IP address is available.

Sponsored by:	Google LLC (GSoC 2024)
Signed-off-by:	Isaac Cilia Attard <[email protected]>
MFC after:	10 days
Reviwed by:	cperciva, brooks, Tom Hukins, Alexander Ziaee
Pull Request:	https://github.com/freebsd/freebsd-src/pull/1368

(cherry picked from commit 503adcdf1d)
2024-08-19 21:58:36 -07:00
Cy Schubert 176f8488e1 rc.conf: Leap-seconds sources: Add IANA back
11da791920 switched Leap-seconds source from IANA to IERS, as IERS
is the canonoical source. The problem ist that IERS is not accessible
from IPv6 only networks. To work around this we must add IANA back in
order to provide IPv6-only users a source for leap-seconds fetch.

PR:		279413
Fixes:		11da791920

(cherry picked from commit 66f360515d)
2024-07-21 19:37:03 -07:00
Eugene Grosbein 73d1f732ce rc.subr: improve description for ${name}_offcmd
Clarify that ${name}_offcmd is for method start.

(cherry picked from commit af1b0aa5b9)
2024-06-21 15:29:53 +07:00
Eugene Grosbein 61d43332e6 rc.subr(8): MFC: introduce ${name}_offcmd
New variable ${name}_offcmd may be used to supply commands
executed if named service is not enabled. Previously start_precmd
could be used for such a task but now rc.subr(8) does not call it
if a service is not enabled.

Fix devd startup script to use it instead of start_precmd.

PR:		279198
Reported by:	Dmitry S. Lukhtionov
Tested by:	Dmitry S. Lukhtionov

(cherry picked from commit 32a579e4fc)
(cherry picked from commit c2db3a0c7d)
2024-06-17 12:06:59 +07:00
Cy Schubert e750111ced kdc: Add restart option
Add a new kdc_restart rc variable that manages kdc (or krb5kdc) under
daemon(8). This automatically restarts the kdc should it fail, i.e.
when it's configured to use LDAP as a backend and cannot connect to its
LDAP directory.

Set kdc_restart="YES" to auto restart kdc on abnormal termination.

Set kdc_restart_delay="N" to the number of seconds to delay before
restarting the kdc. The daemon(8) default seconds applies when not set.

Reported by:		Lexi Winter <[email protected]>
PR:			278395
Differential Revision:	https://reviews.freebsd.org/D44898

(cherry picked from commit 9e248b7f64)
2024-04-29 05:51:11 -07:00
Warner Losh 0eea8292ae leapseconds: Update to the canonical place.
IERS is the source of truth for leap seconds. Their leapsecond file is
updated most quickly and is always right (unlike the IANA one which
often lags). IERS operates this public service for the express purpose
of random people downloading it. Their terms of service are compatible
with open source (we could include this in our release). Rather than
fighting with questions around this because the IANA one changed
locations or the auto update script broken, just use this.

This is in preference to the NIST ftp copy. NIST is in the process of
retiring their FTP services.

Sponsored by:		Netflix
Reviewed by:		philip, delphij, cy
Differential Revision:	https://reviews.freebsd.org/D43752

(cherry picked from commit 11da791920)
2024-02-07 22:15:47 -07:00
Cy Schubert 02f097e7f3 rc.d/kdc: Support start of MIT krb5kdc
Some users wishing to use the MIT krb5kdc have discovered the
kdc script workaround applied to the MIT krb5 ports is insufficient.
Let's build into this rc script the smarts to determine whether
base or ports Hiemdal kdc is being invoked or the MIT krb5kdc.

While at it, remove kdc_start_precmd(). This will simplify a future
jail patch.

Suggested by:		netchild
Original patch:		netchild
Reviewed by:		emaste, netchild
Differential Revision:	https://reviews.freebsd.org/D43523

(cherry picked from commit 91f78c32be)
2024-01-28 16:26:13 -08:00
Philip Paeps 74a8c6da4f rc.conf: correct $ntp_leapfile_sources
IETF is no longer serving leap-seconds.list.  Point at IANA instead.

This fixes "service ntpd fetch".

(cherry picked from commit b1c95af454)
2023-12-16 10:33:58 +08:00
Eugene Grosbein 2d6a03dd43 rc.conf(5): add <service>_umask to run the service using this value
None of tools working with login classes change umask(1)
and we had no ways to specify non-default umask for a service
not touching its startup script. This change makes in possible.

Some file-sharing services that create new files may benefit from it.

Differential:	https://reviews.freebsd.org/D36309

(cherry picked from commit 160a2f2cdd)
2023-12-02 15:15:52 +07:00
Franco Fichtner ed36613e65 rc: add ${name}_setup script support
Run a service-based setup script before running the start command.
Useful for automatic configuration file generation.

Reviewed by:	https://reviews.freebsd.org/D36006
2023-12-02 15:03:49 +07:00
Konstantin Belousov 9026d9e613 ldconfig: filter out non-existing directories from default path
(cherry picked from commit 806e4e3273)
2023-11-28 13:42:22 +02:00
John W. O'Brien 481273492b rc.d/ldconfig: Prepend rtld stdlib paths to ldconfig(32)_paths
PR:			275031

(cherry picked from commit 99132daf6f)
2023-11-28 13:42:22 +02:00
Mateusz Piotrowski 755710da71 rc.subr: Fix a typo
MFC after:	3 days

(cherry picked from commit 7f6754d965)
2023-10-04 13:14:52 +02:00
Mateusz Piotrowski 220af70281 rc: Start testing the rc(8) framework (beginning with *_oomprotect)
This change adds 2 tests to make sure that the *_oomprotect variable
sets the protection against OOM killer properly within rc(8) scripts.

This is also adding the first tests for the rc(8) framework. More tests
will be added as we go.

PR:		256148
Approved by:	des
MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D35745

(cherry picked from commit e7437ae907)
2023-10-04 13:11:18 +02:00
наб 7af7a0d1b1 rc.d/hostid: remove useless cat
We've already read it and validated it ‒ re-reading is wasteful

PR:		264376
(cherry picked from commit 11bd40d04a)
2023-09-24 11:48:34 -04:00
Daniel Tameling 95d4529fb0 rc.subr: don't require service to be enabled for status
For a service that sets an rcvar, there is a check whether it has been
enabled before the actual command is executed. If the check fails, one
gets a message to enable it and the returned exit status is 0.
However, this is usually undesirable for the status command, which is
a) supposed to check whether the service is running anyway and
b) returns a non-zero exit code if that is not the case.
Thus, skip the check for the status command.

PR:		272282
Reviewed by:	emaste

(cherry picked from commit ba793728a8)
(cherry picked from commit f701d9da1d)
2023-09-24 10:07:40 -04:00
Andrew Fengler e8deaa3c6b rc.d/routing: Correct setting default gateway for each FIB
There was a mistake in the previous commit, it used the incorrect
spelling of the FIB variable name and was not functional

Also corrects an issue with the IPv6 default route variable name.

Fixes:	30659d1dcb ("Add support for adding default routes for other FIBs")
Sponsored-by:	ScaleEngine Inc.
Differential Revision:	https://reviews.freebsd.org/D37685

(cherry picked from commit f81be7a831)
2023-08-30 20:06:51 +08:00
Warner Losh 023fc80ee3 Remove $FreeBSD$: one-line sh pattern
Remove /^\s*#[#!]?\s*\$FreeBSD\$.*$\n/

Similar commit in main:
(cherry picked from commit d0b2dbfa0e)
2023-08-23 11:43:30 -06:00
Bjoern A. Zeeb 6a50f0e12d network.subr: adjust regex for wlans_xxxxx rc.conf entries
Drivers like ath1[012]k will not match the current wlans_*-regex as
they have digits followed by letters.  Adjust the regex to allow
this combination in order to be able to configure interfaces with
names like wlans_ath11k0="..."

Reviewed by:	emaste
Differential Revision: https://reviews.freebsd.org/D39674

(cherry picked from commit de1dde5dfe)
2023-06-26 09:04:12 +00:00
Bjoern A. Zeeb ded53e898c rc/WPA: driver_bsd.c: backout upstream IFF_ change and add logging
This reverts the state to our old supplicant logic setting or clearing
IFF_UP if needed.  In addition this adds logging for the cases in which
we do (not) change the interface state.

Depending on testing this seems to help bringing WiFi up or not log
any needed changes (which would be the expected wpa_supplicant logic
now).  People should look out for ``(changed)`` log entries (at least
if debugging the issue; this way we will at least have data points).

There is a hypothesis still pondered that the entire IFF_UP toggling
only exploits a race in net80211 (see further discssussions for more
debugging and alternative solutions see D38508 and D38753).
That may also explain why the changes to the rc startup script [1]
only helped partially for some people to no longer see the
continuous CTRL-EVENT-SCAN-FAILED.

It is highly likely that we will want further changes and until
we know for sure that people are seeing ''(changed)'' events
this should stay local.  Should we need to upstream this we'll
likely need #ifdef __FreeBSD__ around this code.

Remove ifconfig down/up workaround (bfb202c455) in
rc.d/wpa_supplicant as it is no longer needed.

[1] 5fcdc19a81 and
    d06d7eb091

Sponsored by:	The FreeBSD Foundation
Reviewed by:	cy, enweiwu (earlier)
Differential Revision: https://reviews.freebsd.org/D38807

(cherry picked from commit bfb202c455)

Reviewed by:	bz (for wireless)
Differential Revision:	https://reviews.freebsd.org/D39257

(cherry picked from commit 052211e08c)
2023-06-26 09:00:55 +00:00
Eugene Grosbein 428647d483 motd: MFC: unbreak for source upgrade
In case of source upgrade path from 12.x proper merge of new /etc
installs /etc/motd.template. Becase of that, the system is left
without symlink /etc/motd -> /var/run/motd but with stale /etc/motd contents.

Fix it creating symlink despite of presence of /etc/motd.template.

(cherry picked from commit 79a96e294c)
2023-06-26 11:26:47 +07:00
Rick Macklem 5d574146b0 rc.d: Fix NFS server startup scripts to enable vnet prison use
Now that commit cbbb22031f is in main,
it is possible to run nfsd(8), nfsuserd(8), mountd(8),
gssd(8) and rpc.tlsservd(8) in an appropriately configured vnet
prison if the "allow.nfsd" option is specified in jail.conf.

This patch fixes the rc scripts for this.
Mostly just replaces the "nojail" KEYWORD with "nojailvnet",
but also avoids setting vfs.nfsd.srvmaxio in a prison, since it
must be set outside of the prisons and applies to all
nfsd(8) instances.

(cherry picked from commit 0bb08f21cc)
2023-05-22 11:23:58 -07:00
Tijl Coosemans d6852eed98 rc.d: Generate machine-id from hostid_save
rc.d/hostid_save saves a UUID generated by rc.d/hostid in /etc/hostid.
Store the same UUID, without hyphens, in /etc/machine-id.  The hypĥens
are removed with a shell function because hostid_save runs before file
systems are mounted so other tools may not be available yet.

This eliminates some duplication between hostid and machine-id and for
virtual machines machine-id now contains the UUID configured in the
hypervisor like it does on Linux.

Reviewed by:	delphij
Discussed with:	bapt
MFC after:	3 days
Differential Revision:	https://reviews.freebsd.org/D38811

(cherry picked from commit ecad3f5c4d)
2023-03-12 09:59:58 +01:00
Tijl Coosemans baf1e97139 hostid: Generate random UUID by default
This way MAC addresses are no longer exposed.

Discussed with:	bapt
MFC after:	3 days

(cherry picked from commit 862aab6281)
2023-03-12 09:59:58 +01:00
Baptiste Daroussin ebca19e71d machine-id: generate a compact version of the uuid
dbus and other actually expect an uuid without hyphens

Reported by:	tijl
MFC After:	3 days

(cherry picked from commit a28ccb32bf)
2023-03-06 09:04:44 +01:00