Page MenuHomeFreeBSD

rc.subr: remove the dependency on bsdconfig
ClosedPublic

Authored by ivy on May 13 2025, 10:00 AM.
Tags
None
Referenced Files
Unknown Object (File)
Sat, Jun 21, 10:59 PM
Unknown Object (File)
Fri, Jun 20, 8:57 PM
Unknown Object (File)
Wed, Jun 18, 5:21 PM
Unknown Object (File)
Wed, Jun 18, 3:59 PM
Unknown Object (File)
Wed, Jun 18, 3:59 PM
Unknown Object (File)
Tue, Jun 17, 12:17 PM
Unknown Object (File)
Tue, Jun 17, 9:00 AM
Unknown Object (File)
Sun, Jun 15, 1:06 PM
Subscribers

Details

Summary

rc.subr uses sysrc(8) for the 'enable' and 'disable' commands, which
means the entire rc(8) stack depends on bsdconfig. instead, provide a
minimal amount of rc.conf-editing functionality in rc.subr and use it to
implement these commands.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

ivy requested review of this revision.May 13 2025, 10:00 AM

although i don't think rc.subr should depend on bsdconfig in general, the real purpose of this change is to let us move bsdconfig out of the FreeBSD-utilities package in pkgbase.

This revision is now accepted and ready to land.May 13 2025, 10:03 AM
des requested changes to this revision.May 13 2025, 10:41 AM
des added inline comments.
libexec/rc/rc.subr
2743

It bothers me that both /etc/rc.conf and /etc/defaults/rc.conf are hardcoded in several places in rc.subr. Perhaps it's time to define _rc_conf and _defaults_rc_conf at the top of the file. Maybe _rc_conf_d as well.

2745

purely a matter of taste: this intermediate assignment is not really needed

2746

Some rc scripts have multiple names; for instance, /etc/rc.d/netif calls load_rc_config network before load_rc_config netif. You might want to cache the names passed to load_rc_config somewhere so you can iterate over them here.

2749

This entire loop can be rewritten as grep -rl "^${_var}=" "$_files", although you'll have to think about what to do if you get multiple hits. Replacing just the first one (as you currently do) may turn out to have no effect at all.

(you may get false positives since e.g. /etc/rc.conf.d/${name}/foo/bar will be visible to grep but not to load_rc_config; whether or not that is a problem is up for debate)

2784

Have you tested this with a value that contains a /?

2787

I would argue that if /etc/rc.conf.d/${name} exists, then we should put the variable there rather than in /etc/rc.conf.

This revision now requires changes to proceed.May 13 2025, 10:41 AM
libexec/rc/rc.subr
2784

right now the value can only be YES or NO, but i suppose it would be useful to support arbitrary values here since the function isn't documented to only work for _enable vars.

2787

i'm not opposed to this, but it's not how it currently works - are we okay with changing the behaviour?

th documentation in rc(8) just says "Enable the service in rc.conf(5)", so we haven't previously committed to editing a particular file here.

review fixes

i haven't made any cleanup changes here (like adding more variables for
settings) because there's quite a few of those we could do and i think it makes
more sense to do that in a follow-up commit.

Only nits left, up to you if you want to leave them as is or do a final round.

libexec/rc/rc.subr
2737

nit: you can declare multiple local variables in a single statement.

2761

nit: you can declare multiple local variables in a single statement.

2770

this needs to be local

2778

for bonus points, if $_file exists but is a directory, add the variable to a file named enable in that directory.

2797

nit: you can declare multiple local variables in a single statement.

This revision is now accepted and ready to land.May 14 2025, 10:29 AM
ivy marked 8 inline comments as done.May 14 2025, 2:38 PM
ivy added inline comments.
libexec/rc/rc.subr
2778

i think i'll do this in a separate review, because potentially write_rcvar could be used for things which are not ${name}_enable and we probably need to decide when/how to write files to that directory.

This revision was automatically updated to reflect the committed changes.