Bug 201641 - /etc/rc.subr error fails to parse rc.conf.d directories from $local_startup correctly
Summary: /etc/rc.subr error fails to parse rc.conf.d directories from $local_startup c...
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: conf (show other bugs)
Version: 10.2-STABLE
Hardware: Any Any
: --- Affects Some People
Assignee: Jilles Tjoelker
URL:
Keywords: patch
Depends on:
Blocks:
 
Reported: 2015-07-17 00:29 UTC by Jamie Landeg-Jones
Modified: 2015-10-27 21:00 UTC (History)
2 users (show)

See Also:
jilles: mfc-stable10+
jilles: mfc-stable9-
jilles: mfc-stable8-


Attachments
fix to /etc/rc.subr (375 bytes, patch)
2015-07-17 00:32 UTC, Jamie Landeg-Jones
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jamie Landeg-Jones 2015-07-17 00:29:22 UTC
/etc/rc.subr contains the following snippet:

for _d in /etc ${local_startup%*/rc.d}; do
                if [ -f ${_d}/rc.conf.d/"$_name" ]; then
                        debug "Sourcing ${_d}/rc.conf.d/$_name"
                        . ${_d}/rc.conf.d/"$_name"

However, as local_startup can contain more than one path, only the last entry has "/rc.d" stripped correctly, thus making the rc.conf.d directories invalid for other entries.

This patch fixes it.

Example, before patch:

0:02 (99) "/etc" root@lapcat# grep local_startup /etc/rc.conf
local_startup="/usr/local/etc/rc.d /usr/common/etc/rc.d /usr/me/etc/rc.d" # startup script dirs.

23:48 (42) "/etc" root@lapcat# service lpd restart
+ [ -f /etc/rc.conf.d/XXX ]
+ [ -d /etc/rc.conf.d/XXX ]
+ [ -f /usr/local/etc/rc.d/rc.conf.d/XXX ]
+ [ -d /usr/local/etc/rc.d/rc.conf.d/XXX ]
+ [ -f /usr/common/etc/rc.d/rc.conf.d/XXX ]
+ [ -d /usr/common/etc/rc.d/rc.conf.d/XXX ]
+ [ -f /usr/me/etc/rc.conf.d/XXX ]
+ [ -d /usr/me/etc/rc.conf.d/XXX ]
+ [ -f /etc/rc.conf.d/lpd ]
+ [ -d /etc/rc.conf.d/lpd ]
+ [ -f /usr/local/etc/rc.d/rc.conf.d/lpd ]
+ [ -d /usr/local/etc/rc.d/rc.conf.d/lpd ]
+ [ -f /usr/common/etc/rc.d/rc.conf.d/lpd ]
+ [ -d /usr/common/etc/rc.d/rc.conf.d/lpd ]
+ [ -f /usr/me/etc/rc.conf.d/lpd ]
+ [ -d /usr/me/etc/rc.conf.d/lpd ]

Example, after patch:

23:49 (43) "/etc" root@lapcat# service lpd restart
+ _d=/etc
+ [ -f /etc/rc.conf.d/XXX ]
+ [ -d /etc/rc.conf.d/XXX ]
+ _d=/usr/local/etc
+ [ -f /usr/local/etc/rc.conf.d/XXX ]
+ [ -d /usr/local/etc/rc.conf.d/XXX ]
+ _d=/usr/common/etc
+ [ -f /usr/common/etc/rc.conf.d/XXX ]
+ [ -d /usr/common/etc/rc.conf.d/XXX ]
+ _d=/usr/me/etc
+ [ -f /usr/me/etc/rc.conf.d/XXX ]
+ [ -d /usr/me/etc/rc.conf.d/XXX ]
+ _d=/etc
+ [ -f /etc/rc.conf.d/lpd ]
+ [ -d /etc/rc.conf.d/lpd ]
+ _d=/usr/local/etc
+ [ -f /usr/local/etc/rc.conf.d/lpd ]
+ [ -d /usr/local/etc/rc.conf.d/lpd ]
+ _d=/usr/common/etc
+ [ -f /usr/common/etc/rc.conf.d/lpd ]
+ [ -d /usr/common/etc/rc.conf.d/lpd ]
+ _d=/usr/me/etc
+ [ -f /usr/me/etc/rc.conf.d/lpd ]
+ [ -d /usr/me/etc/rc.conf.d/lpd ]

This problem exists in 10-STABLE and 11-CURRENT

As an aside, a commit to rc.subr by des 7 months ago, scheduled to be MFC after a week still hasn't bern actioned:

base r275359

 | des
 | Date: Mon Dec 1 12:17:42 2014 UTC (7 months, 2 weeks ago)
 | Log Message: Allow load_rc_config to be called without a service name.
 |
 | MFC after: 1 week

Cheers, Jamie
Comment 1 Jamie Landeg-Jones 2015-07-17 00:32:34 UTC
Created attachment 158897 [details]
fix to /etc/rc.subr
Comment 2 commit-hook freebsd_committer freebsd_triage 2015-08-01 22:00:53 UTC
A commit references this bug:

Author: jilles
Date: Sat Aug  1 22:00:26 UTC 2015
New revision: 286163
URL: https://svnweb.freebsd.org/changeset/base/286163

Log:
  rc.subr: Allow rc.conf.d with multi-directory local_startup.

  I also changed ${...%*/rc.d} to ${...%/rc.d} since the shortest match always
  has an empty string for the asterisk.

  PR:		201641
  Submitted by:	Jamie Landeg-Jones (original version)
  MFC after:	1 week

Changes:
  head/etc/rc.subr
Comment 3 Jamie Landeg-Jones 2015-08-03 08:02:25 UTC
Cheers!

> I also changed ${...%*/rc.d} to ${...%/rc.d} since the shortest match always has an empty string for the asterisk.

Oops, yes, good catch!  I moved that from the original code, but missed the unnecessary asterisk!

Thanks, Jamie
Comment 4 commit-hook freebsd_committer freebsd_triage 2015-10-27 20:59:01 UTC
A commit references this bug:

Author: jilles
Date: Tue Oct 27 20:58:14 UTC 2015
New revision: 290062
URL: https://svnweb.freebsd.org/changeset/base/290062

Log:
  MFC r286163: rc.subr: Allow rc.conf.d with multi-directory local_startup.

  I also changed ${...%*/rc.d} to ${...%/rc.d} since the shortest match always
  has an empty string for the asterisk.

  PR:		201641
  Submitted by:	Jamie Landeg-Jones (original version)

Changes:
_U  stable/10/
  stable/10/etc/rc.subr