Page MenuHomeFreeBSD

sysrc: Add support for ``rc.conf.d'' service(8) configuration file(s)
ClosedPublic

Authored by dteske on Sep 2 2015, 7:29 PM.

Details

Summary

Add sysrc(8) support for "rc.conf.d" file(s) when given "-s name" to
indicate service(8) script. While here, add "-l" option for listing the
set of configuration file(s) considered (in order; separated by space).
Also add "-L" for exploring all configuration files and "-E" to omit
files that don't exist from operations.

Test Plan

Check that "-L name" lists "rc.conf.d" entries for named "rc.d" script:

$ sysrc -L ipfw

/etc/rc.conf.d/ipfw /usr/local/etc/rc.conf.d/ipfw

$ sysrc -L dhclient

/etc/rc.conf.d/dhclient /usr/local/etc/rc.conf.d/dhclient \
/etc/rc.conf.d/network /usr/local/etc/rc.conf.d/network

$ sysrc -L nosuchservice

(no output)

Check that "-ls name" lists "rc.conf" and "rc.conf.d" entries:

$ sysrc -ls ipfw

/etc/rc.conf /etc/rc.conf.local \
/etc/rc.conf.d/ipfw /usr/local/etc/rc.conf.d/ipfw

$ sysrc -ls dhclient

/etc/rc.conf /etc/rc.conf.local \
/etc/rc.conf.d/dhclient /usr/local/etc/rc.conf.d/dhclient \
/etc/rc.conf.d/network /usr/local/etc/rc.conf.d/network

$ sysrc -ls nosuchservice

/etc/rc.conf /etc/rc.conf.local

Check that "-l" lists "rc.conf" entries:

$ sysrc -l

/etc/rc.conf /etc/rc.conf.local

Check that "-lD" lists the default rc.conf:

/etc/defaults/rc.conf

Check that "-s name variable" is able to get settings from "rc.conf.d":

$ sysrc -f /etc/rc.conf.d/ipfw foo=bar

foo: -> bar

$ sysrc -s ipfw foo

foo: bar

$ sysrc -Fs ipfw foo
foo: /etc/rc.conf.d/ipfw

Check that "-s name variable=value" is able to put settings in "rc.conf.d":

$ sysrc -vs ipfw bar=baz

/etc/rc.conf.d/ipfw: bar: -> baz

Check that "-L" produces a list of all usable configuration files:

$ sysrc -L

(long output)

Check that "-Lv" produces a list of services and their configuration files:

$ sysrc -Lv

(long output)

Check that "-EL" produces a list of existing configuration files:

$ sysrc -Lv

(depends on system)

Check that "-ELv" shows all existing configuration files and what uses them:

$ sysrc -ELv

(depends on system)

Check that "-qL ipfw" returns success:

$ sysrc -qL ipfw && echo found

found

Check that "-qL xxx" returns failure:
$ sysrc -qL xxx || echo not found

not found

Diff Detail

Repository
rS FreeBSD src repository
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

dteske retitled this revision from to sysrc: Add support for ``rc.conf.d'' service(8) configuration file(s).Sep 2 2015, 7:29 PM
dteske updated this object.
dteske edited the test plan for this revision. (Show Details)
dteske added reviewers: allanjude, bapt, eadler, delphij.
dteske added subscribers: allanjude, bdrewery, bapt.
dteske updated this revision to Diff 8430.
dteske edited edge metadata.Sep 2 2015, 9:20 PM
dteske updated this revision to Diff 8437.

Fix code typo preventing local_startup based rc.conf.d entries

dteske edited edge metadata.Sep 2 2015, 9:27 PM
dteske updated this revision to Diff 8438.

Add support for `rc.conf.d/$name' as a directory.

wollman added a subscriber: wollman.Sep 6 2015, 8:20 PM

Can we add some unit tests, please?

Can we add some unit tests, please?

Did you see the "Test Plan" section in this review? Or did you mean a test harness?

In D3551#73903, @dteske wrote:

Can we add some unit tests, please?

Did you see the "Test Plan" section in this review? Or did you mean a test harness?

Tests should be in the source tree, IMO.

allanjude added inline comments.Sep 9 2015, 1:52 AM
usr.sbin/bsdconfig/share/sysrc.subr
248 ↗(On Diff #8438)

rcNG allows /etc/rc.conf.d/<service>/* as well

rc.subr does it this way:

for _d in /etc ${local_startup}; do
        _d=${_d%/rc.d}
        if [ -f ${_d}/rc.conf.d/"$_name" ]; then
                debug "Sourcing ${_d}/rc.conf.d/$_name"
                . ${_d}/rc.conf.d/"$_name"
        elif [ -d ${_d}/rc.conf.d/"$_name" ] ; then
                local _rc
                for _rc in ${_d}/rc.conf.d/"$_name"/* ; do
                        if [ -f "$_rc" ] ; then
                                debug "Sourcing $_rc"
                                . "$_rc"
                        fi
                done
        fi
done
allanjude edited edge metadata.Sep 9 2015, 2:37 AM
allanjude accepted this revision.
allanjude added inline comments.
usr.sbin/bsdconfig/share/sysrc.subr
248 ↗(On Diff #8438)

nevermind, you already addressed this

This revision is now accepted and ready to land.Sep 9 2015, 2:37 AM
dteske planned changes to this revision.Sep 11 2015, 9:47 PM

More to come

dteske edited edge metadata.Sep 12 2015, 11:42 PM
dteske updated this revision to Diff 8702.

Add -E' for "Existing Only" and -L' for "List all".
Update usage and help statements.
Change -l' and -s name' handling for robustness.
Produce usage if arguments are given to `-l'.
More manual updates.

dteske updated this object.Sep 12 2015, 11:58 PM
dteske edited the test plan for this revision. (Show Details)
dteske edited edge metadata.
dteske edited the test plan for this revision. (Show Details)
dteske updated this object.
dteske updated this object.
dteske edited the test plan for this revision. (Show Details)Sep 13 2015, 12:03 AM
dteske updated this revision to Diff 8737.Sep 14 2015, 2:54 AM

Support -q' with -L [name ...]' and minor manual update

dteske edited the test plan for this revision. (Show Details)Sep 14 2015, 2:57 AM
dteske edited edge metadata.

Still a little more to do; I'd like to add more to the manual page with respect to examples using -l and -L. For instance, documenting "sysrc -ELv" is very important, as it's a quick way to get a list of all configuration files that exist and which services use them.

Bump (review please)

dteske added a comment.Nov 3 2015, 7:31 PM

ETIMEOUT for additional reviewers

This revision was automatically updated to reflect the committed changes.

Committed to stable/10 as SVN r292833