Use of rcorder for local rc.d/*.sh scripts

J.R. Oldroyd jr at opal.com
Tue Jun 7 03:37:36 GMT 2005


On Jun 06, 17:31, Brooks Davis wrote:
> 
> I think your original suggestion is the direction we should take.
> Things that truly need to run before or after localpkg can be handled by
> an existing ports mechanism.
> 

OK, well, below is probably a more complete patch.  I've added the
shutdown part, and copied the "-k shutdown" option and the "-s
nojail" option from /etc/rc and /etc/rc.shutdown.

The code to handle file names with embedded spaces using the IFS
change is not actually needed if the shell patterns to match the
filenames are expanded in the for loop which executes the scripts.
So this patch removes all that code.  Note that the matching of
"*.sh" is what the script does now.  I've not changed that.  If we
want to remove the requirement that scripts in the local_startup
dirs be named *.sh, this code can be simplified even further.

	-jr




--- /etc/rc.d/localpkg.orig	Fri Oct  8 13:52:43 2004
+++ /etc/rc.d/localpkg	Mon Jun  6 23:25:47 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,12 @@
 	*)
 		echo -n 'Local package initialization:'
 		slist=""
-		if [ -z "${script_name_sep}" ]; then
-			script_name_sep=" "
-		fi
 		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}/*.sh"
 			fi
 		done
-		script_save_sep="$IFS"
-		IFS="${script_name_sep}"
-		for script in ${slist}; do
+		for script in `rcorder -s nostart ${rcorder_opts} ${slist} 2>/dev/null`; do
 			if [ -x "${script}" ]; then
 				(set -T
 				trap 'exit 1' 2
@@ -45,7 +41,6 @@
 				echo -n " (skipping ${script##*/}, not executable)"
 			fi
 		done
-		IFS="${script_save_sep}"
 		echo '.'
 		;;
 	esac
@@ -61,26 +56,18 @@
 		;;
 	*)
 		slist=""
-		if [ -z "${script_name_sep}" ]; then
-			script_name_sep=" "
-		fi
 		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}/*.sh"
 			fi
 		done
-		script_save_sep="$IFS"
-		IFS="${script_name_sep}"
-		for script in `reverse_list ${slist}`; do
+		for script in `reverse_list \`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



-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 390 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/freebsd-rc/attachments/20050606/111730f1/attachment.bin


More information about the freebsd-rc mailing list