This patch series aims to improve logging and abort the suspend/resume process
if a hook fails with an unknown error code.

Skips the actual sleep/wake cycle if one of our hooks failed with an 
unknown error code.
---
 pm/pm-functions.in |    8 ++++++--
 src/pm-action.in   |    4 ++--
 2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/pm/pm-functions.in b/pm/pm-functions.in
index 2c97848..2966baf 100644
--- a/pm/pm-functions.in
+++ b/pm/pm-functions.in
@@ -97,13 +97,15 @@ remove_suspend_lock()
 }
 
 hook_exit_status(){
+       local ret=0
        case $1 in
                0) log "success." ;;
                $NA) log "not applicable." ;;
                $NX) log "not executable." ;;
                $DX) log "disabled." ;;
-               *) log "Returned exit code $1." ;;
+               *) log "Returned exit code $1."; ret=$1 ;;
        esac
+       return $ret
 }
 
 hook_ok()
@@ -129,6 +131,7 @@ run_hooks() {
        local base
        local hook
        local oifs="${IFS}"
+       local ret=0
        # the next two lines are not a typo or a formatting error!
        local nifs="
 "
@@ -147,9 +150,10 @@ run_hooks() {
                        IFS="${oifs}"
                        "${hook}" $2
                )
-               hook_exit_status $?
+               hook_exit_status $? || ret=$?
        done
        IFS="${oifs}"
+       return $ret
 }
 
 init_logfile()
diff --git a/src/pm-action.in b/src/pm-action.in
index bc4022c..bedfd83 100644
--- a/src/pm-action.in
+++ b/src/pm-action.in
@@ -72,8 +72,8 @@ init_logfile "${PM_LOGFILE}"
 # Make sure we are not inhibited before we start.
 rm -f "${INHIBIT}"
 
-# run the sleep hooks
-run_hooks sleep "$ACTION"
+# run the sleep hooks.  If run_hooks returns a failure code, inhibit sleeping
+run_hooks sleep "$ACTION" || touch "$INHIBIT"
 
 # Sleep only if we know how and if a hook did not inhibit us.
 command_exists "do_$ACTION" && [ ! -e "$INHIBIT" ] && { sync; "do_$ACTION"; }
-- 
1.5.4.3

_______________________________________________
Pm-utils mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/pm-utils

Reply via email to