From hetzels@WBIw009.westbend.net  Thu Oct 31 16:21:22 2002
Return-Path: <hetzels@WBIw009.westbend.net>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP
	id 689B037B401; Thu, 31 Oct 2002 16:21:22 -0800 (PST)
Received: from mail.westbend.net (ns1.westbend.net [216.47.253.3])
	by mx1.FreeBSD.org (Postfix) with ESMTP
	id 9C2A243E8A; Thu, 31 Oct 2002 16:21:21 -0800 (PST)
	(envelope-from hetzels@WBIw009.westbend.net)
Received: from WBIw009.westbend.net (wbiw009 [216.47.253.29])
	by mail.westbend.net (8.12.5/8.12.5) with ESMTP id gA10L71U086725;
	Thu, 31 Oct 2002 18:21:08 -0600 (CST)
	(envelope-from hetzels@WBIw009.westbend.net)
Received: from WBIw009.westbend.net (localhost [127.0.0.1])
	by WBIw009.westbend.net (8.12.6/8.12.6) with ESMTP id gA10L743007900;
	Thu, 31 Oct 2002 18:21:07 -0600 (CST)
	(envelope-from hetzels@WBIw009.westbend.net)
Received: (from root@localhost)
	by WBIw009.westbend.net (8.12.6/8.12.6/Submit) id gA10L6vR007899;
	Thu, 31 Oct 2002 18:21:06 -0600 (CST)
Message-Id: <200211010021.gA10L6vR007899@WBIw009.westbend.net>
Date: Thu, 31 Oct 2002 18:21:06 -0600 (CST)
From: "Scot W. Hetzel" <hetzels@westbend.net>
Reply-To: "Scot W. Hetzel" <hetzels@westbend.net>
To: FreeBSD-gnats-submit@freebsd.org
Cc: Gordon <gordon@freebsd.org>
Subject: RC_NG for local rc scripts
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         44800
>Category:       conf
>Synopsis:       RC_NG for local rc scripts
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    mtm
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Thu Oct 31 16:30:01 PST 2002
>Closed-Date:    Sat Aug 16 22:01:17 PDT 2003
>Last-Modified:  Sat Aug 16 22:01:17 PDT 2003
>Originator:     Scot W. Hetzel
>Release:        FreeBSD 5.0-CURRENT i386
>Organization:
West Bend Internet
>Environment:
System: FreeBSD Current.westbend.net 5.0-CURRENT FreeBSD 5.0-CURRENT #3: Sat Oct 26 19:44:41 CDT 2002     root@Current.westbend.net:/usr/obj/usr/src/srcC/sys/GENERIC-SMP  i386

>Description:

I have converted several ports rc scripts to RC_NG, but I noticed
that load_rc_config could only read configuration files from /etc.
Attached is a patch that adds load_local_rc_config to /etc/rc.subr.
With this patch, ports scripts can read their configuration from
the following files and listed order:

    ${prefix}/etc/rc.conf.d/<name>
    /etc/default/rc.conf
    /etc/rc.conf
    /etc/rc.conf.d/<name>

I have submitted the folowing ports PRs with rc.d scripts that support
both 5.0-CURRENT and *-STABLE.

    PR 43667    mail/cyrus_imapd
    PR 43668    mail/cyrus_imapd2
    PR 43669    databases/mysql323-{server,client}
    PR 43670    net/openldap
    PR 43671    net/openldap2
    PR 43672    security/cyrus-sasl
    PR 43673    security/cyrus-sasl2
    PR 43681    www/apache13-fp

Currently, these rc.d scripts are using a different method to read their
configuration information from ${prefix}/etc/rc.conf.d/<name>.

>How-To-Repeat:
>Fix:

Attached are patchs for rc.subr and mtree/BSD.local.dist

NOTE: BSD.local.dist should be MFC'd to STABLE.

Index: rc.subr
===================================================================
RCS file: /home/ncvs/src/etc/rc.subr,v
retrieving revision 1.6
diff -u -r1.6 rc.subr
--- rc.subr	12 Sep 2002 17:27:36 -0000	1.6
+++ rc.subr	31 Oct 2002 22:12:13 -0000
@@ -833,6 +833,48 @@
 }
 
 #
+# load_local_rc_config
+# 	Source in the configuration file for a given local command.
+#
+#       The following globals are used:
+#
+#	Name		Needed	Purpose
+#	----		------	-------
+#	prefix		y	Base directory that script is located in (i.e /usr/local)
+#
+#	rcvar		n	Name of variable used to enable the service.
+#
+load_local_rc_config()
+{
+	_command=$1
+	if [ -z "$_command" ]; then
+		err 3 "USAGE: load_local_rc_config command"
+	fi
+
+	if [ -z "$prefix" ]; then
+		err 3 'load_local_rc_config: $prefix is not set.'
+	fi
+
+	if [ -f ${prefix}/etc/rc.conf.d/"$_command" ]; then
+                debug "Sourcing ${prefix}/etc/rc.conf.d/${_command}"
+                . ${prefix}/etc/rc.conf.d/"$_command"
+        fi
+
+	# Let either /etc/rc.conf or /etc/rc.conf.d/"$_command"
+	# override ${prefix}/etc/rc.conf.d/"$_command"
+	load_rc_config $_command
+
+	# Used for compatibilty with old behavior for local rc scripts.
+	if [ -n "$rcvar" ]; then
+		eval _value=\$${rcvar}
+		if [ -z "${_value}" ]; then
+			debug "load_local_rc_config: setting ${rcvar} to YES"
+			eval ${rcvar}=YES
+		fi
+	fi
+}
+
+#
 # rc_usage commands
 #	Print a usage string for $0, with `commands' being a list of
 #	valid commands.
Index: BSD.local.dist
===================================================================
RCS file: /home/ncvs/src/etc/mtree/BSD.local.dist,v
retrieving revision 1.92
diff -u -r1.92 BSD.local.dist
--- BSD.local.dist	25 Oct 2002 22:00:34 -0000	1.92
+++ BSD.local.dist	31 Oct 2002 19:51:06 -0000
@@ -10,6 +10,8 @@
     etc
         pam.d
         ..
+        rc.conf.d
+        ..
         rc.d
         ..
     ..
>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->mtm 
Responsible-Changed-By: kris 
Responsible-Changed-When: Sat Jul 12 16:56:42 PDT 2003 
Responsible-Changed-Why:  
Assign to rc.d maintainer 

http://www.freebsd.org/cgi/query-pr.cgi?pr=44800 
State-Changed-From-To: open->closed 
State-Changed-By: kuriyama 
State-Changed-When: Sat Aug 16 22:00:53 PDT 2003 
State-Changed-Why:  
Originator's request.  See ports/43671. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=44800 
>Unformatted:
