diff options
author | Victor Lowther <victor.lowther@gmail.com> | 2009-12-07 19:02:35 -0600 |
---|---|---|
committer | Victor Lowther <victor.lowther@gmail.com> | 2009-12-07 19:02:35 -0600 |
commit | 09da44bedc97ddd75e77ed87b7a057dc21e01a38 (patch) | |
tree | c534c5702766f19e841bdf259e8da271268c5e89 | |
parent | 57ff1f997d6297557340057e9fdbb2f956b31aa0 (diff) |
Track suspend/hibernate failures and exit accordingly.
It turns out that echo whatever >/sys/power/state will fail if
transitioning to that state fails. If transitioning to the
reuested power state fails, pm-action will return an error code
greater or equal than 128.
-rwxr-xr-x | pm/module.d/tuxonice | 3 | ||||
-rw-r--r-- | pm/pm-functions.in | 17 | ||||
-rwxr-xr-x | src/pm-action.in | 8 |
3 files changed, 20 insertions, 8 deletions
diff --git a/pm/module.d/tuxonice b/pm/module.d/tuxonice index 3db8cbe..3fcc995 100755 --- a/pm/module.d/tuxonice +++ b/pm/module.d/tuxonice @@ -27,10 +27,13 @@ if [ -z "$SUSPEND_HYBRID_MODULE" -a -n "$TUXONICE_LOC" ] && \ SUSPEND_HYBRID_MODULE="tuxonice" do_suspend_hybrid() { + r=0 echo 3 >"${TUXONICE_LOC}/powerdown_method" echo anything >"${TUXONICE_LOC}/do_hibernate" + r=$? [ -f /sys/power/tuxonice/did_suspend_to_both ] && \ [ "$(cat /sys/power/tuxonice/did_suspend_to_both)" != "1" ] && \ REVERSE="thaw" + return $r } fi diff --git a/pm/pm-functions.in b/pm/pm-functions.in index fff943a..dfbc59f 100644 --- a/pm/pm-functions.in +++ b/pm/pm-functions.in @@ -325,13 +325,18 @@ if [ -z "$SUSPEND_HYBRID_MODULE" -a -w "$PM_RTC/wakealarm" ] && \ WAKETIME=$(( $(cat "$PM_RTC/since_epoch") + PM_HIBERNATE_DELAY)) echo >"$PM_RTC/wakealarm" echo $WAKETIME > "$PM_RTC/wakealarm" - do_suspend - NOW=$(cat "$PM_RTC/since_epoch") - if [ "$NOW" -ge "$WAKETIME" -a "$NOW" -lt $((WAKETIME + 30)) ]; then - log "Woken by RTC alarm, hibernating." - do_hibernate + if do_suspend; then + NOW=$(cat "$PM_RTC/since_epoch") + if [ "$NOW" -ge "$WAKETIME" -a "$NOW" -lt $((WAKETIME + 30)) ]; then + log "Woken by RTC alarm, hibernating." + # if hibernate fails for any reason, go back to suspend. + do_hibernate || do_suspend + else + echo > "$PM_RTC/wakealarm" + fi else - echo > "$PM_RTC/wakealarm" + # if we cannot suspend, just try to hibernate. + do_hibernate fi } fi diff --git a/src/pm-action.in b/src/pm-action.in index 88bdb4e..e148585 100755 --- a/src/pm-action.in +++ b/src/pm-action.in @@ -29,6 +29,9 @@ export STASHNAME=pm-suspend export METHOD="$(echo ${0##*pm-} |tr - _)" . "@PM-UTILS-LIBDIR@/pm-functions" +# return code tracking for when suspend fails +r=0 + help() { echo "${0##*/} [options]" @@ -97,7 +100,7 @@ if run_hooks sleep "$ACTION $METHOD"; then # Sleep only if we know how and if a hook did not inhibit us. log "$(date): performing $METHOD" sync - "do_$METHOD" + "do_$METHOD" || r=128 log "$(date): Awake." else log "$(date): Inhibit found, will not perform $METHOD" @@ -107,5 +110,6 @@ log "$(date): Running hooks for $REVERSE" if run_hooks sleep "$REVERSE $METHOD" reverse; then log "$(date): Finished." else - exit 1 + exit $((r+1)) fi +exit $r |