[Pm-utils] [PATCH 02/12] Make run_hooks skip disabled hooks.

Victor Lowther victor.lowther at gmail.com
Tue Mar 11 18:08:24 PDT 2008


Eventually we will print a helpful diagnostic in the logfile saying what
disabled the hook based on the contents of the disabled file, but that is a
job for a later date.
---
 pm/functions.in    |    2 +-
 pm/pm-functions.in |   15 +++++++++++++--
 2 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/pm/functions.in b/pm/functions.in
index 421fa65..82ff157 100644
--- a/pm/functions.in
+++ b/pm/functions.in
@@ -157,7 +157,7 @@ restartservice()
 
 disablehook()
 {
-	echo "${2:-${0$$*/}}" > "${STORAGEDIR}/disable_hook:$1"
+	echo "${2:-${0$$*/}}" > "${STORAGEDIR}/disable_hook:${1##*/}"
 }
 
 savestate()
diff --git a/pm/pm-functions.in b/pm/pm-functions.in
index 88eb841..76e8845 100644
--- a/pm/pm-functions.in
+++ b/pm/pm-functions.in
@@ -29,6 +29,8 @@ LOCKDIR="${PM_UTILS_RUNDIR}/locks"
 STORAGEDIR="${PM_UTILS_RUNDIR}/storage"
 SLEEP_MODULE="kernel"
 NA=254
+NX=253
+DX=252
 PM_FUNCTIONS="$PM_UTILS_LIBDIR/functions"
 # Use c sort order
 export LC_COLLATE=C
@@ -67,10 +69,19 @@ hook_exit_status(){
 	case $1 in
 		0) echo "success." ;;
 		$NA) echo "not applicable." ;;
+		$NX) echo "not executable." ;;
+		$DX) echo "disabled." ;;
 		*) echo "Returned exit code $1." ;;
 	esac
 }
 
+hook_ok()
+{
+	[ -f "$STORAGEDIR/disable_hook:${1##*/}" ] && return $DX
+	[ -x "$1" ] || return $NX
+	return 0
+}
+
 run_hooks() {
 	# $1 = type of hook to find.  
 	# $2 = paramaters to pass to hooks.
@@ -95,12 +106,12 @@ run_hooks() {
 		elif [ -f "$phooks/$base" ]; then
 			hook="$phooks/$base"
 		fi
-		[ -x "${hook}" ] && (
+		hook_ok "$hook" && (
 			IFS="${oifs}"
 			echo "$(date): running ${hook} $2"
 			"${hook}" $2
-			hook_exit_status $?
 		)
+		hook_exit_status $?
 	done
 	IFS="${oifs}"
 }
-- 
1.5.4.3



More information about the Pm-utils mailing list