[Pm-utils] [PATCH] Do not inhibit further power.d hooks if one fails

Chase Douglas chase.douglas at ubuntu.com
Mon Mar 22 11:27:07 PDT 2010


From: Chase Douglas <chase.douglas at canonical.com>

Sleep hooks are dependency ordered, so we must bail if any hook fails.
However, powersave hooks generally do not have any dependencies. It
makes more sense to allow all powersave hooks to run even if one of them
fails.

Signed-off-by: Chase Douglas <chase.douglas at canonical.com>
---
 pm/pm-functions.in  |   18 +++++++++++-------
 src/pm-action.in    |    6 +++---
 src/pm-powersave.in |    6 +++---
 3 files changed, 17 insertions(+), 13 deletions(-)

diff --git a/pm/pm-functions.in b/pm/pm-functions.in
index dfbc59f..0862520 100644
--- a/pm/pm-functions.in
+++ b/pm/pm-functions.in
@@ -193,11 +193,14 @@ hook_ok()
 }
 
 _run_hook() {
-	# $1 = hook to run
+	# $1 = "inhibit" or "advance" further hooks after a hook failure
+	# $2 = hook to run
 	# rest of args passed to hook unchanged.
+	local do_inhibit=$1
+	shift
 	log -n "$*:"
 	hook_ok "$1" && "$@"
-	hook_exit_status $? && LAST_HOOK="${1##*/}" || inhibit
+	hook_exit_status $? && LAST_HOOK="${1##*/}" || [ "$do_inhibit" = "inhibit" ] && inhibit
 }
 
 if profiling; then
@@ -210,7 +213,8 @@ fi
 _run_hooks() {
 	# $1 = type of hook to find.  
 	# $2 = paramaters to pass to hooks.
-	# $3 = if present and equal to "reverse", run hooks backwards.
+	# $3 = "inhibit" or "advance" further hooks after a hook failure
+	# $4 = if present and equal to "reverse", run hooks backwards.
 	# Currently only power and sleep are meaningful.
 	local syshooks="${PM_UTILS_ETCDIR}/$1.d"
 	local phooks="${PM_UTILS_LIBDIR}/$1.d"
@@ -223,25 +227,25 @@ _run_hooks() {
 	local nifs="
 "
 	IFS="${nifs}" # tolerate spaces in filenames.
-	[ "$3" = "reverse" ] && sort="sort -r"
+	[ "$4" = "reverse" ] && sort="sort -r"
 	for base in $(IFS="${oifs}"; for f in "$syshooks/"*[!~] "$phooks/"*[!~];
 		do [ -O "$f" ] && echo ${f##*/} ; done | $sort | uniq) ;
 	do
 		IFS="${oifs}"
 		# if we are running backwards, skip hooks that we did not 
 		# run going forwards due to a hook failing.
-		[ "$3" -a "$3" = "reverse" -a "$LAST_HOOK" ] && \
+		[ "$4" -a "$4" = "reverse" -a "$LAST_HOOK" ] && \
 		    [ "$base" \> "$LAST_HOOK" ] && continue
 		# if we have already inhibited suspend/resume,
 		# don't run any more hooks.
-		[ ! "$3" ] && inhibited && break
+		[ ! "$4" ] && inhibited && break
 		update_parameters
 		if [ -f "$syshooks/$base" ]; then
 			hook="$syshooks/$base"
 		elif [ -f "$phooks/$base" ]; then
 			hook="$phooks/$base"
 		fi
-		run_hook "$hook" $2
+		run_hook $3 "$hook" $2
 		IFS="${nifs}"
 	done
 	IFS="${oifs}"
diff --git a/src/pm-action.in b/src/pm-action.in
index e148585..3d89ab6 100755
--- a/src/pm-action.in
+++ b/src/pm-action.in
@@ -37,7 +37,7 @@ help()
 	echo "${0##*/} [options]"
 	echo
 	echo "Options can change how suspend or hibernate is done."
-	run_hooks sleep help
+	run_hooks sleep help advance
 	sleep_module_help
 	exit 0
 }
@@ -96,7 +96,7 @@ load_hook_parameters
 
 # run the sleep hooks
 log "$(date): Running hooks for $ACTION."
-if run_hooks sleep "$ACTION $METHOD"; then
+if run_hooks sleep "$ACTION $METHOD" inhibit; then
         # Sleep only if we know how and if a hook did not inhibit us.
 	log "$(date): performing $METHOD"
 	sync
@@ -107,7 +107,7 @@ else
 fi
 log "$(date): Running hooks for $REVERSE"
 # run the sleep hooks in reverse with the wakeup action
-if run_hooks sleep "$REVERSE $METHOD" reverse; then
+if run_hooks sleep "$REVERSE $METHOD" inhibit reverse; then
         log "$(date): Finished."
 else 
         exit $((r+1))
diff --git a/src/pm-powersave.in b/src/pm-powersave.in
index 08e4f5b..e0a4b8d 100644
--- a/src/pm-powersave.in
+++ b/src/pm-powersave.in
@@ -42,14 +42,14 @@ load_hook_blacklist
 
 if [ "$1" = "true" -o "$1" = "false" ] ; then
 	init_logfile "${PM_LOGFILE}"
-	run_hooks power "$1"
+	run_hooks power "$1" advance
 elif [ ! "$1" ]; then
     # no arg?  Guess!
     init_logfile "${PM_LOGFILE}"
     if on_ac_power; then
-	run_hooks power false;
+	run_hooks power false advance;
     else
-	run_hooks power true;
+	run_hooks power true advance;
     fi
 else
     echo "Argument needs to be true or false" >&2
-- 
1.6.3.3



More information about the Pm-utils mailing list