From jr@opal.com  Thu Jun  9 03:14:06 2005
Return-Path: <jr@opal.com>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id AC4C516A41C
	for <FreeBSD-gnats-submit@freebsd.org>; Thu,  9 Jun 2005 03:14:06 +0000 (GMT)
	(envelope-from jr@opal.com)
Received: from smtp.vzavenue.net (smtp.vzavenue.net [66.171.59.140])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 4B07A43D49
	for <FreeBSD-gnats-submit@freebsd.org>; Thu,  9 Jun 2005 03:14:06 +0000 (GMT)
	(envelope-from jr@opal.com)
Received: from linwhf.opal.com (112.79.171.66.subscriber.vzavenue.net [66.171.79.112])
	by smtp.vzavenue.net (MOS 3.4.8-GR)
	with ESMTP id CJB31562;
	Wed, 8 Jun 2005 23:13:58 -0400 (EDT)
Received: from ASSP-nospam (localhost [127.0.0.1])
	by linwhf.opal.com (8.13.3/8.13.3) with ESMTP id j593Dvju075555
	for <FreeBSD-gnats-submit@freebsd.org>; Wed, 8 Jun 2005 23:13:57 -0400 (EDT)
	(envelope-from jr@opal.com)
Received: from 127.0.0.1 ([127.0.0.1] helo=linwhf.opal.com) by ASSP-nospam ;  9 Jun 05 03:13:57 -0000
Received: (from jr@localhost)
	by linwhf.opal.com (8.13.3/8.13.3/Submit) id j593Dv3O075554;
	Wed, 8 Jun 2005 23:13:57 -0400 (EDT)
	(envelope-from jr)
Message-Id: <200506090313.j593Dv3O075554@linwhf.opal.com>
Date: Wed, 8 Jun 2005 23:13:57 -0400 (EDT)
From: "J.R. Oldroyd" <fbsd@opal.com>
Reply-To: "J.R. Oldroyd" <fbsd@opal.com>
To: FreeBSD-gnats-submit@freebsd.org
Subject: patch to /etc/rc.d/localpkg to partially sort scripts using rcorder(8)
X-Send-Pr-Version: 3.113

>Number:         82059
>Category:       conf
>Synopsis:       [patch] /etc/rc.d/localpkg: partially sort scripts using rcorder(8)
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    dougb
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu Jun 09 03:20:01 GMT 2005
>Closed-Date:    Wed Dec 21 08:53:38 GMT 2005
>Last-Modified:  Wed Dec 21 08:53:38 GMT 2005
>Originator:     J.R. Oldroyd
>Release:        FreeBSD 6.0-CURRENT i386
>Organization:
>Environment:
System: FreeBSD linwhf.opal.com 6.0-CURRENT FreeBSD 6.0-CURRENT #83: Thu Jun 2 09:20:18 EDT 2005 xxx:/usr/src-current/sys/i386/compile/LINWHF i386
>Description:
Certain local rc.d scripts do not currently start because scripts are
executed in alphabetic order, even though many ports provide rcorder(8)
tags.  This patch modifies /etc/rc.d/localpkg to sort the local scripts
using rcorder tags, if present, while preserving existing semantics
for scripts named 000.foo.sh.
>How-To-Repeat:
Install www/apache2 and net/freenet6.
Configure apache to use a freenet6 IPv6 address.
Reboot and watch apache fail to start because apache2.sh is run before freenet6.sh.
>Fix:
--- /etc/rc.d/localpkg.orig	Fri Oct  8 13:52:43 2004
+++ /etc/rc.d/localpkg	Tue Jun  7 15:19:19 2005
@@ -14,6 +14,9 @@
 start_cmd="pkg_start"
 stop_cmd="pkg_stop"
 
+rcorder_opts=""
+[ `/sbin/sysctl -n security.jail.jailed` -eq 1 ] && rcorder_opts="-s nojail"
+
 pkg_start()
 {
 	# For each dir in $local_startup, search for init scripts matching *.sh
@@ -24,19 +27,14 @@
 	*)
 		echo -n 'Local package initialization:'
 		slist=""
-		if [ -z "${script_name_sep}" ]; then
-			script_name_sep=" "
-		fi
+		zlist=""
 		for dir in ${local_startup}; do
 			if [ -d "${dir}" ]; then
-				for script in ${dir}/*.sh; do
-					slist="${slist}${script_name_sep}${script}"
-				done
+				slist="${slist} ${dir}/[^0-9]*.sh"
+				zlist="${zlist} ${dir}/[0-9]*.sh"
 			fi
 		done
-		script_save_sep="$IFS"
-		IFS="${script_name_sep}"
-		for script in ${slist}; do
+		for script in ${zlist} `rcorder -s nostart ${rcorder_opts} ${slist} 2>/dev/null`; do
 			if [ -x "${script}" ]; then
 				(set -T
 				trap 'exit 1' 2
@@ -45,7 +43,6 @@
 				echo -n " (skipping ${script##*/}, not executable)"
 			fi
 		done
-		IFS="${script_save_sep}"
 		echo '.'
 		;;
 	esac
@@ -61,26 +58,20 @@
 		;;
 	*)
 		slist=""
-		if [ -z "${script_name_sep}" ]; then
-			script_name_sep=" "
-		fi
+		zlist=""
 		for dir in ${local_startup}; do
 			if [ -d "${dir}" ]; then
-				for script in ${dir}/*.sh; do
-					slist="${slist}${script_name_sep}${script}"
-				done
+				slist="${slist} ${dir}/[^0-9]*.sh"
+				zlist="${zlist} ${dir}/[0-9]*.sh"
 			fi
 		done
-		script_save_sep="$IFS"
-		IFS="${script_name_sep}"
-		for script in `reverse_list ${slist}`; do
+		for script in `reverse_list ${zlist} \`rcorder -k shutdown ${rcorder_opts} ${slist} 2>/dev/null\``; do
 			if [ -x "${script}" ]; then
 				(set -T
 				trap 'exit 1' 2
 				${script} stop)
 			fi
 		done
-		IFS="${script_save_sep}"
 		echo '.'
 		;;
 	esac


>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->patched 
State-Changed-By: dougb 
State-Changed-When: Mon Dec 5 08:34:36 GMT 2005 
State-Changed-Why:  

Some of these ideas have been incorporated into the work 
that I committed recently to HEAD. I'll close this when 
I MFC it to RELENG_6. 


Responsible-Changed-From-To: freebsd-bugs->dougb 
Responsible-Changed-By: dougb 
Responsible-Changed-When: Mon Dec 5 08:34:36 GMT 2005 
Responsible-Changed-Why:  

I'm taking responsibility for this transition. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=82059 
State-Changed-From-To: patched->closed 
State-Changed-By: dougb 
State-Changed-When: Wed Dec 21 08:52:26 UTC 2005 
State-Changed-Why:  

The overall changes to include rc.d files in the local_startup 
directories, including some of the changes suggested here, 
have been MFC'ed to RELENG_6, and will not be MFC'ed to 
RELENG_5. 

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