From eikemeier@fillmore-labs.com  Fri Sep 12 08:30:29 2003
Return-Path: <eikemeier@fillmore-labs.com>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id C6AEB16A4BF
	for <FreeBSD-gnats-submit@FreeBSD.org>; Fri, 12 Sep 2003 08:30:29 -0700 (PDT)
Received: from mx2.fillmore-labs.com (lima.fillmore-labs.com [62.138.193.83])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 793F943FF3
	for <FreeBSD-gnats-submit@FreeBSD.org>; Fri, 12 Sep 2003 08:30:26 -0700 (PDT)
	(envelope-from eikemeier@fillmore-labs.com)
Received: from p5080ba02.dip.t-dialin.net
	([80.128.186.2] helo=fillmore-labs.com ident=29sps6mv8tz2c6a8)
	by mx2.fillmore-labs.com with asmtp (TLSv1:AES256-SHA:256)
	(Exim 4.22)
	id 19xpsO-000N9C-Pt
	for FreeBSD-gnats-submit@FreeBSD.org; Fri, 12 Sep 2003 17:30:25 +0200
Message-Id: <3F61E68D.8040205@fillmore-labs.com>
Date: Fri, 12 Sep 2003 17:30:21 +0200
From: Oliver Eikemeier <eikemeier@fillmore-labs.com>
To: FreeBSD-gnats-submit@FreeBSD.org
Subject: [PATCH] rcNG: enable packages to participate in rcorder(8)

>Number:         56736
>Category:       conf
>Synopsis:       [PATCH] rcNG: enable packages to participate in rcorder(8)
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    dougb
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Fri Sep 12 08:40:13 PDT 2003
>Closed-Date:    Wed Dec 21 08:51:59 GMT 2005
>Last-Modified:  Wed Dec 21 08:51:59 GMT 2005
>Originator:     Oliver Eikemeier
>Release:        FreeBSD 5.1-CURRENT i386
>Organization:
Fillmore Labs - http://www.fillmore-labs.com
>Environment:
System: FreeBSD nuuk.fillmore-labs.com 5.1-CURRENT

>Description:

- as ports adopt the rcNG system, they should be able to
  participate in rcorder(8), i.e. to provide alternative
  services (named from the bind9 port, mail from exim or
  an alternative inetd).

The following patch does the following:

- any file in ${local_startup} that contains
  '^# KEYWORDS?:'
  is started/stopped by /etc/rc
- scripts that do not contain this line are
  handled as usual

The only caveat is that run_rc_script from rc.subr(8)
sources files ending with .sh into the current shell,
not into a sub shell, which may abort the boot process
if a start script exits. Maybe the suffix should be
changed in /etc/rc.subr to .src, .fast or something
other unusual.

The patch addresses some other issues:

- rcorder(8) is looking for '# KEYWORD:' or '# KEYWORDS:',
  so adapt rc.shutdown to that.
- rc(8) wasn't loading rc.conf, so rc_fast_and_loose
  was ignored.

>How-To-Repeat:
>Fix:

--- localpkg.patch begins here ---
diff -u src/etc/rc.orig src/etc/rc
--- src/etc/rc.orig	Sun May 18 19:31:40 2003
+++ src/etc/rc	Fri Sep 12 16:02:39 2003
@@ -66,7 +66,14 @@
 fi
 
 os=`eval ${CMD_OSTYPE}`
-files=`rcorder -k ${os} -s nostart /etc/rc.d/* 2>/dev/null`
+load_rc_config "rc"
+_startup="/etc/rc.d/*"
+for dir in ${local_startup}; do
+	if [ -d "${dir}" ]; then
+		startup="${_startup} ${dir}/*"
+	fi
+done
+files=`rcorder -k ${os} -s nostart ${_startup} 2>/dev/null`
 
 for _rc_elem in ${files}; do
 	run_rc_script ${_rc_elem} ${_boot}
diff -u src/etc/rc.d/localpkg.orig src/etc/rc.d/localpkg
--- src/etc/rc.d/localpkg.orig	Wed Aug  6 02:35:13 2003
+++ src/etc/rc.d/localpkg	Fri Sep 12 16:20:17 2003
@@ -29,7 +29,7 @@
 		fi
 		for dir in ${local_startup}; do
 			if [ -d "${dir}" ]; then
-				for script in ${dir}/*.sh; do
+				for script in `grep -EL '^# KEYWORDS?:' ${dir}/*.sh 2>/dev/null`; do
 					slist="${slist}${script_name_sep}${script}"
 				done
 			fi
@@ -66,7 +66,7 @@
 		fi
 		for dir in ${local_startup}; do
 			if [ -d "${dir}" ]; then
-				for script in ${dir}/*.sh; do
+				for script in `grep -EL '^# KEYWORDS?:' ${dir}/*.sh 2>/dev/null`; do
 					slist="${slist}${script_name_sep}${script}"
 				done
 			fi
diff -u src/etc/rc.shutdown.orig src/etc/rc.shutdown
--- src/etc/rc.shutdown.orig	Mon Jul 14 13:01:29 2003
+++ src/etc/rc.shutdown	Fri Sep 12 16:06:18 2003
@@ -82,7 +82,7 @@
 # XXX - rcorder(8) with multiple -k switches works as a logical OR,
 #       so, we can't do this: rcorder -k shutdown -k FreeBSD.
 #
-files=`eval grep -l \'^# KEYWORD:.*FreeBSD\' \`rcorder -k shutdown /etc/rc.d/* 2>/dev/null\``
+files=`eval grep -El \'^# KEYWORDS?:.*FreeBSD\' \`rcorder -k shutdown /etc/rc.d/* 2>/dev/null\``
 
 for _rc_elem in `reverse_list $files`; do
 	debug "run_rc_script $_rc_elem stop"
--- localpkg.patch ends here ---


>Release-Note:
>Audit-Trail:

From: Oliver Eikemeier <eikemeier@fillmore-labs.com>
To: freebsd-gnats-submit@FreeBSD.org
Cc:  
Subject: Re: conf/56736: [PATCH] rcNG: enable packages to participate in rcorder(8)
Date: Fri, 12 Sep 2003 19:10:36 +0200

 sorry, I missed the remark about diskless booting in /etc/rc.
 
 May be we need a two-stage boot process, one without packages
 till mountcritremote, and with packages after that. Can some
 of the diskless gurus comment on this?
 

From: Oliver Eikemeier <eikemeier@fillmore-labs.com>
To: freebsd-gnats-submit@FreeBSD.org
Cc:  
Subject: Re: conf/56736: [PATCH] rcNG: enable packages to participate in rcorder(8)
Date: Fri, 23 Jan 2004 15:48:33 +0100

 An updated patch, which does essentially the following:
 
 - create a dummy dependency /etc/rc.d/PORTS
 
 - executes /etc/rc startup as normal until /etc/rc.d/PORTS, then
   reevalutes rcorder(8), including scripts from ${local_startup}
 
 - include ${local_startup} in /etc/rc.shutdown
 
 - does not start nor stop scripts containing '^# KEYWORD:' from
   /etc/rc.d/localpkg, as they are already handled by /etc/rc and
   /etc/rc.shutdown
 
 The only remaining problem is that '*.sh' scripts are sourced
 from /etc/rc.subr, instead of executed in a subshell. Therefore
 ports should install their start/stop scripts as ${PREFIX}/etc/rc.d/${PKGBASE}
 and add a small stub ${PREFIX}/etc/rc.d/${PKGBASE}.sh:
 
 #!/bin/sh
 #
 # $FreeBSD$
 #
 
 # KEYWORD: FreeBSD nostart
 
 if [ -r ${0%%.sh} ]; then
 	. ${0%%.sh}
 fi
 
 Patch for rc, rc.shutdown, rc.d/localpkg and rc.d/PORTS:
 
 --- src/etc/rc.orig	Fri May  2 07:27:33 2003
 +++ src/etc/rc	Fri Jan 23 15:35:40 2004
 @@ -53,7 +53,7 @@
  . /etc/rc.subr
  
  # Note: the system configuration files are loaded as part of
 -# the RCNG system (rc.d/rccond).  Do not load them here as it may
 +# the RCNG system (rc.d/rcconf.sh).  Do not load them here as it may
  # interfere with diskless booting.
  #
  if [ "$1" = autoboot ]; then
 @@ -69,6 +69,35 @@
  files=`rcorder -k ${os} -s nostart /etc/rc.d/* 2>/dev/null`
  
  for _rc_elem in ${files}; do
 +	if [ ${_rc_elem} = "/etc/rc.d/PORTS" ]; then
 +		break
 +	fi
 +	run_rc_script ${_rc_elem} ${_boot}
 +done
 +
 +# system configuration is loaded, reevalute rcorder
 +case ${local_startup} in
 +[Nn][Oo] | '')
 +	;;
 +*)
 +	_rc_startup="/etc/rc.d/*"
 +	for d in ${local_startup}; do
 +		if [ -d $d ]; then
 +			_rc_startup="${_rc_startup} ${d}/*"
 +		fi
 +	done
 +	files=`rcorder -k ${os} -s nostart ${_rc_startup} 2>/dev/null`
 +esac
 +
 +_rc_done=true
 +for _rc_elem in ${files}; do
 +	if ${_rc_done}; then
 +		if [ ${_rc_elem} = "/etc/rc.d/PORTS" ]; then
 +			_rc_done=false
 +		else
 +			continue
 +		fi
 +	fi
  	run_rc_script ${_rc_elem} ${_boot}
  done
  
 --- src/etc/rc.shutdown.orig	Tue Jul  8 04:52:14 2003
 +++ src/etc/rc.shutdown	Fri Jan 23 15:39:01 2004
 @@ -82,7 +82,19 @@
  # XXX - rcorder(8) with multiple -k switches works as a logical OR,
  #       so, we can't do this: rcorder -k shutdown -k FreeBSD.
  #
 -files=`eval grep -l \'^# KEYWORD:.*FreeBSD\' \`rcorder -k shutdown /etc/rc.d/* 2>/dev/null\``
 +_rc_startup="/etc/rc.d/*"
 +case ${local_startup} in
 +[Nn][Oo] | '')
 +        ;;
 +*)
 +	for d in ${local_startup}; do
 +		if [ -d $d ]; then
 +			_rc_startup="${_rc_startup} ${d}/*"
 +		fi
 +	done
 +	;;
 +esac
 +files=`eval grep -l \'^# KEYWORD:.*FreeBSD\' \`rcorder -k shutdown ${_rc_startup} 2>/dev/null\``
  
  for _rc_elem in `reverse_list $files`; do
  	debug "run_rc_script $_rc_elem stop"
 --- src/etc/rc.d/localpkg.orig	Wed Aug  6 02:35:13 2003
 +++ src/etc/rc.d/localpkg	Fri Jan 23 13:08:48 2004
 @@ -30,7 +30,9 @@
  		for dir in ${local_startup}; do
  			if [ -d "${dir}" ]; then
  				for script in ${dir}/*.sh; do
 -					slist="${slist}${script_name_sep}${script}"
 +					if ! grep -sq '^# KEYWORD:' ${script}; then
 +						slist="${slist}${script_name_sep}${script}"
 +					fi
  				done
  			fi
  		done
 @@ -67,7 +69,9 @@
  		for dir in ${local_startup}; do
  			if [ -d "${dir}" ]; then
  				for script in ${dir}/*.sh; do
 -					slist="${slist}${script_name_sep}${script}"
 +					if ! grep -sq '^# KEYWORD:' ${script}; then
 +						slist="${slist}${script_name_sep}${script}"
 +					fi
  				done
  			fi
  		done
 --- src/etc/rc.d/PORTS.orig	Fri Jan 23 15:11:00 2004
 +++ src/etc/rc.d/PORTS	Fri Jan 23 13:09:50 2004
 @@ -0,0 +1,11 @@
 +#!/bin/sh
 +#
 +# $FreeBSD$
 +#
 +
 +# PROVIDE: PORTS
 +# REQUIRE: diskless mountcritlocal
 +# BEFORE: addswap random
 +# KEYWORD: FreeBSD
 +
 +#	This is a dummy dependency to include ports into rcorder(8)

From: Oliver Eikemeier <eikemeier@fillmore-labs.com>
To: freebsd-gnats-submit@FreeBSD.org
Cc:  
Subject: Re: conf/56736: [PATCH] rcNG: enable packages to participate in rcorder(8)
Date: Fri, 23 Jan 2004 16:48:34 +0100

 I essentially reimplemented my 5.1 patch for 5.2, ending with
 a slightly less elegant solution. Also take into account that
 rcorder(8) accepts KEYWORDS:
 
 --- src/etc/rc.orig	Fri May  2 07:27:33 2003
 +++ src/etc/rc	Fri Jan 23 16:24:47 2004
 @@ -53,7 +53,7 @@
  . /etc/rc.subr
  
  # Note: the system configuration files are loaded as part of
 -# the RCNG system (rc.d/rccond).  Do not load them here as it may
 +# the RCNG system (rc.d/rcconf.sh).  Do not load them here as it may
  # interfere with diskless booting.
  #
  if [ "$1" = autoboot ]; then
 @@ -69,6 +69,35 @@
  files=`rcorder -k ${os} -s nostart /etc/rc.d/* 2>/dev/null`
  
  for _rc_elem in ${files}; do
 +	if [ ${_rc_elem} = "/etc/rc.d/PORTS" ]; then
 +		break
 +	fi
 +	run_rc_script ${_rc_elem} ${_boot}
 +done
 +
 +# system configuration is loaded, reevalute rcorder
 +case ${local_startup} in
 +[Nn][Oo] | '')
 +	;;
 +*)
 +	_rc_startup="/etc/rc.d/*"
 +	for dir in ${local_startup}; do
 +		if [ -d "${dir}" ]; then
 +			_rc_startup="${_rc_startup} ${dir}/*"
 +		fi
 +	done
 +	files=`rcorder -k ${os} -s nostart ${_rc_startup} 2>/dev/null`
 +esac
 +
 +_rc_done=true
 +for _rc_elem in ${files}; do
 +	if ${_rc_done}; then
 +		if [ ${_rc_elem} = "/etc/rc.d/PORTS" ]; then
 +			_rc_done=false
 +		else
 +			continue
 +		fi
 +	fi
  	run_rc_script ${_rc_elem} ${_boot}
  done
  
 --- src/etc/rc.shutdown.orig	Tue Jul  8 04:52:14 2003
 +++ src/etc/rc.shutdown	Fri Jan 23 16:29:59 2004
 @@ -82,7 +82,19 @@
  # XXX - rcorder(8) with multiple -k switches works as a logical OR,
  #       so, we can't do this: rcorder -k shutdown -k FreeBSD.
  #
 -files=`eval grep -l \'^# KEYWORD:.*FreeBSD\' \`rcorder -k shutdown /etc/rc.d/* 2>/dev/null\``
 +_rc_startup="/etc/rc.d/*"
 +case ${local_startup} in
 +[Nn][Oo] | '')
 +        ;;
 +*)
 +	for dir in ${local_startup}; do
 +		if [ -d "${dir}" ]; then
 +			_rc_startup="${_rc_startup} ${dir}/*"
 +		fi
 +	done
 +	;;
 +esac
 +files=`eval grep -El \'^# KEYWORDS?:.*FreeBSD\' \`rcorder -k shutdown ${_rc_startup} 2>/dev/null\``
  
  for _rc_elem in `reverse_list $files`; do
  	debug "run_rc_script $_rc_elem stop"
 --- src/etc/rc.d/localpkg.orig	Wed Aug  6 02:35:13 2003
 +++ src/etc/rc.d/localpkg	Fri Jan 23 16:22:58 2004
 @@ -29,7 +29,7 @@
  		fi
  		for dir in ${local_startup}; do
  			if [ -d "${dir}" ]; then
 -				for script in ${dir}/*.sh; do
 +				for script in `grep -EL '^# KEYWORDS?:' ${dir}/*.sh 2>/dev/null`; do
  					slist="${slist}${script_name_sep}${script}"
  				done
  			fi
 @@ -66,7 +66,7 @@
  		fi
  		for dir in ${local_startup}; do
  			if [ -d "${dir}" ]; then
 -				for script in ${dir}/*.sh; do
 +				for script in `grep -EL '^# KEYWORDS?:' ${dir}/*.sh 2>/dev/null`; do
  					slist="${slist}${script_name_sep}${script}"
  				done
  			fi
 --- src/etc/rc.d/PORTS.orig	Fri Jan 23 15:11:00 2004
 +++ src/etc/rc.d/PORTS	Fri Jan 23 13:09:50 2004
 @@ -0,0 +1,11 @@
 +#!/bin/sh
 +#
 +# $FreeBSD$
 +#
 +
 +# PROVIDE: PORTS
 +# REQUIRE: diskless mountcritlocal
 +# BEFORE: addswap random
 +# KEYWORD: FreeBSD
 +
 +#	This is a dummy dependency to include ports into rcorder(8)
 
Responsible-Changed-From-To: freebsd-bugs->mtm 
Responsible-Changed-By: mtm 
Responsible-Changed-When: Sat Jul 24 16:22:11 GMT 2004 
Responsible-Changed-Why:  


http://www.freebsd.org/cgi/query-pr.cgi?pr=56736 
State-Changed-From-To: open->patched 
State-Changed-By: dougb 
State-Changed-When: Mon Dec 5 08:30:49 GMT 2005 
State-Changed-Why:  

This is remarkably similar to the solution I committed recently 
to HEAD. Nice to see that great minds think alike. :) 


Responsible-Changed-From-To: mtm->dougb 
Responsible-Changed-By: dougb 
Responsible-Changed-When: Mon Dec 5 08:30:49 GMT 2005 
Responsible-Changed-Why:  

I'm taking responsibility for this transition, and Mike has 
unfortunately been MIA for a while. 

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

I've MFC'ed the changes that will effect what this PR is 
asking for to RELENG_6, and they will not be MFC'ed to 
RELENG_5. 

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