[PATCH] Don't test if a service is enabled when it's required

Xin LI delphij at delphij.net
Tue Aug 23 21:23:23 UTC 2011


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

Hi,

Thanks for Jilles' comments.  I've added a new procedure called
fast_depend (poor name perhaps?) with a proposed changeset to all
these rc.d scripts that uses force_depend.

Comments?

Cheers,
- -- 
Xin LI <delphij at delphij.net>	https://www.delphij.net/
FreeBSD - The Power to Serve!		Live free or die
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.18 (FreeBSD)

iQEcBAEBCAAGBQJOVBpJAAoJEATO+BI/yjfBP0oIANOfSLNtqPhCL4QixTgDOknw
UVlMdk1yqr9nYsyC21rQZoGIkKb2a9BplW0ZNbRYmwCZEGhG0JJE4Tm52rhISdqe
1ITd/T+eU1I9lQ37Weo6dEjywCX/1kVl7Hd7i6v0Mmuc3ZTIjwP8ZBKbZj/9P/0C
Wd/slxaAzl8m/AOO4MknP4Vq5Dktz1wR8wWItP9fiKHKFFDqv/n7kXE+uAmfBRl7
0X/bUVILVRRTsX7dJIZINwMBNtxHUUlIU/HCu7/T2jLg+SsMW6Z0JaS2w7lenoPk
XTZAqk18qPZjkT7L834SNBXnPy1iAEumM8kdOP/YZ7MZfgc8mGhRJ2CR6JrjelE=
=9nGD
-----END PGP SIGNATURE-----
-------------- next part --------------
Index: etc/rc.d/amd
===================================================================
--- etc/rc.d/amd	(revision 225122)
+++ etc/rc.d/amd	(working copy)
@@ -19,16 +19,9 @@
 
 amd_precmd()
 {
-	if ! checkyesno nfs_client_enable; then
-		force_depend nfsclient || return 1
-	fi
+	fast_depend nfsclient nfs_client_enable || return 1
+	fast_depend rpcbind || return 1
 
-	if ! checkyesno rpcbind_enable  && \
-	    ! /etc/rc.d/rpcbind forcestatus 1>/dev/null 2>&1
-	then
-		force_depend rpcbind || return 1
-	fi
-
 	case ${amd_map_program} in
 	[Nn][Oo] | '')
 		;;
Index: etc/rc.d/ypset
===================================================================
--- etc/rc.d/ypset	(revision 225122)
+++ etc/rc.d/ypset	(working copy)
@@ -20,16 +20,8 @@
 {
 	local _domain
 
-	if ! checkyesno rpcbind_enable  && \
-	    ! /etc/rc.d/rpcbind forcestatus 1>/dev/null 2>&1
-	then
-		force_depend rpcbind || return 1
-	fi
-	if ! checkyesno nis_client_enable && \
-	    ! /etc/rc.d/ypbind forcestatus 1>/dev/null 2>&1
-	then
-		force_depend ypbind || return 1
-	fi
+	fast_depend rpcbind || return 1
+	fast_depend ypbind nis_client_enable || return 1
 
 	_domain=`domainname`
 	if [ -z "$_domain" ]; then
Index: etc/rc.d/mountd
===================================================================
--- etc/rc.d/mountd	(revision 225122)
+++ etc/rc.d/mountd	(working copy)
@@ -19,11 +19,7 @@
 
 mountd_precmd()
 {
-	if ! checkyesno rpcbind_enable  && \
-	    ! /etc/rc.d/rpcbind forcestatus 1>/dev/null 2>&1
-	then
-		force_depend rpcbind || return 1
-	fi
+	fast_depend rpcbind || return 1
 
 	# mountd flags will differ depending on rc.conf settings
 	#
Index: etc/rc.d/yppasswdd
===================================================================
--- etc/rc.d/yppasswdd	(revision 225122)
+++ etc/rc.d/yppasswdd	(working copy)
@@ -22,16 +22,9 @@
 {
 	local _domain
 
-	if ! checkyesno rpcbind_enable  && \
-	    ! /etc/rc.d/rpcbind forcestatus 1>/dev/null 2>&1
-	then
-		force_depend rpcbind || return 1
-	fi
-	if ! checkyesno nis_server_enable && \
-	    ! /etc/rc.d/ypserv forcestatus 1>/dev/null 2>&1
-	then
-		force_depend ypserv || return 1
-	fi
+	fast_depend rpcbind || return 1
+	fast_depend ypserv nis_server_enable || return 1
+
 	_domain=`domainname`
 	if [ -z "$_domain" ]; then
 		warn "NIS domainname(1) is not set."
Index: etc/rc.d/keyserv
===================================================================
--- etc/rc.d/keyserv	(revision 225122)
+++ etc/rc.d/keyserv	(working copy)
@@ -19,11 +19,7 @@
 
 keyserv_prestart()
 {
-	if ! checkyesno rpcbind_enable  && \
-		! /etc/rc.d/rpcbind forcestatus 1>/dev/null 2>&1
-	then
-		force_depend rpcbind || return 1
-	fi
+	fast_depend rpcbind || return 1
 
 	return 0
 }
Index: etc/rc.d/ypupdated
===================================================================
--- etc/rc.d/ypupdated	(revision 225122)
+++ etc/rc.d/ypupdated	(working copy)
@@ -18,16 +18,8 @@
 {
 	local _domain
 
-	if ! checkyesno rpcbind_enable  && \
-	    ! /etc/rc.d/rpcbind forcestatus 1>/dev/null 2>&1
-	then
-		force_depend rpcbind || return 1
-	fi
-	if ! checkyesno nis_server_enable && \
-	    ! /etc/rc.d/ypserv forcestatus 1>/dev/null 2>&1
-	then
-		force_depend ypserv || return 1
-	fi
+	fast_depend rpcbind || return 1
+	fast_depend ypserv nis_server_enable || return 1
 
 	_domain=`domainname`
 	if [ -z "$_domain" ]; then
Index: etc/rc.d/apmd
===================================================================
--- etc/rc.d/apmd	(revision 225122)
+++ etc/rc.d/apmd	(working copy)
@@ -20,11 +20,7 @@
 	case `${SYSCTL_N} hw.machine_arch` in
 	i386)
 		# Enable apm if it is not already enabled
-		if ! checkyesno apm_enable  && \
-		    ! /etc/rc.d/apm forcestatus 1>/dev/null 2>&1
-		then
-			force_depend apm || return 1
-		fi
+		fast_depend apm || return 1
 
 		# Warn user about acpi apm compatibility support which
 		# does not work with apmd.
Index: etc/rc.d/nfsd
===================================================================
--- etc/rc.d/nfsd	(revision 225122)
+++ etc/rc.d/nfsd	(working copy)
@@ -43,30 +43,16 @@
 		fi
 
 		if checkyesno nfsv4_server_enable; then
-			if ! checkyesno nfsuserd_enable  && \
-			    ! /etc/rc.d/nfsuserd forcestatus 1>/dev/null 2>&1
-			then
-				if ! force_depend nfsuserd; then
-					err 1 "Cannot run nfsuserd"
-				fi
-			fi
+			fast_depend nfsuserd || err 1 "Cannot run nfsuserd"
 		else
 			echo 'NFSv4 is disabled'
 			sysctl vfs.nfsd.server_max_nfsvers=3 > /dev/null
 		fi
 	fi
 
-	if ! checkyesno rpcbind_enable  && \
-	    ! /etc/rc.d/rpcbind forcestatus 1>/dev/null 2>&1
-	then
-		force_depend rpcbind || return 1
-	fi
+	fast_depend rpcbind || return 1
+	fast_depend mountd || return 1
 
-	if ! checkyesno mountd_enable  && \
-	    ! /etc/rc.d/mountd forcestatus 1>/dev/null 2>&1
-	then
-		force_depend mountd || return 1
-	fi
 	return 0
 }
 
Index: etc/rc.d/lockd
===================================================================
--- etc/rc.d/lockd	(revision 225122)
+++ etc/rc.d/lockd	(working copy)
@@ -30,11 +30,7 @@
 	then
 		ret=1
 	fi
-	if ! checkyesno rpcbind_enable && \
-	    ! /etc/rc.d/rpcbind forcestatus 1>/dev/null 2>&1
-	then
-		force_depend rpcbind || ret=1
-	fi
+	fast_depend rpcbind || ret=1
 	rc_flags=${rpc_lockd_flags}
 	return ${ret}
 }
Index: etc/rc.d/statd
===================================================================
--- etc/rc.d/statd	(revision 225122)
+++ etc/rc.d/statd	(working copy)
@@ -30,11 +30,7 @@
 	then
 		ret=1
 	fi
-	if ! checkyesno rpcbind_enable && \
-	    ! /etc/rc.d/rpcbind forcestatus 1>/dev/null 2>&1
-	then
-		force_depend rpcbind || ret=1
-	fi
+	fast_depend rpcbind || ret=1
 	rc_flags=${rpc_statd_flags}
 	return ${ret}
 }
Index: etc/rc.d/ypbind
===================================================================
--- etc/rc.d/ypbind	(revision 225122)
+++ etc/rc.d/ypbind	(working copy)
@@ -22,11 +22,7 @@
 {
 	local _domain
 
-	if ! checkyesno rpcbind_enable  && \
-	    ! /etc/rc.d/rpcbind forcestatus 1>/dev/null 2>&1
-	then
-		force_depend rpcbind || return 1
-	fi
+	fast_depend rpcbind || return 1
 
 	_domain=`domainname`
 	if [ -z "$_domain" ]; then
Index: etc/rc.d/ypserv
===================================================================
--- etc/rc.d/ypserv	(revision 225122)
+++ etc/rc.d/ypserv	(working copy)
@@ -21,11 +21,7 @@
 {
 	local _domain
 
-	if ! checkyesno rpcbind_enable  && \
-	    ! /etc/rc.d/rpcbind forcestatus 1>/dev/null 2>&1
-	then
-		force_depend rpcbind || return 1
-	fi
+	fast_depend rpcbind || return 1
 	_domain=`domainname`
 	if [ -z "$_domain" ]; then
 		warn "NIS domainname(1) is not set."
Index: etc/rc.d/ypxfrd
===================================================================
--- etc/rc.d/ypxfrd	(revision 225122)
+++ etc/rc.d/ypxfrd	(working copy)
@@ -20,16 +20,8 @@
 {
 	local _domain
 
-	if ! checkyesno rpcbind_enable  && \
-	    ! /etc/rc.d/rpcbind forcestatus 1>/dev/null 2>&1
-	then
-		force_depend rpcbind || return 1
-	fi
-	if ! checkyesno nis_server_enable && \
-	    ! /etc/rc.d/ypserv forcestatus 1>/dev/null 2>&1
-	then
-		force_depend ypserv || return 1
-	fi
+	fast_depend rpcbind || return 1
+	fast_depend ypserv nis_server_enable || return 1
 
 	_domain=`domainname`
 	if [ -z "$_domain" ]; then
Index: etc/rc.subr
===================================================================
--- etc/rc.subr	(revision 225119)
+++ etc/rc.subr	(working copy)
@@ -159,6 +159,29 @@
 }
 
 #
+# fast_depend script [var] [prefix]
+#	Force a service to start if it's not already, regardless
+#	if it's enabled.  Intended for use by services
+#	to resolve dependency issues.  When rc_fast is set,
+#	only force the dependency if var is set to "NO".
+#	$1 - script name
+#	$2 - variable name if the variable to test is not ${1}_enable
+#	$3 - prefix path if not the default /etc/rc.d
+#
+fast_depend()
+{
+	_script="$1"
+	_variable="${2:-${1}_enable}"
+	_prefix="${3:-/etc/rc.d}"
+
+	if { [ -z "${rc_fast}" ] || ! checkyesno ${_variable}; } &&
+		! ${_prefix}/${_script} forcestatus 1>/dev/null 2>&1
+	then
+		force_depend ${_script} || return 1
+	fi
+}
+
+#
 # reverse_list list
 #	print the list in reverse order
 #


More information about the freebsd-rc mailing list