[Pm-utils] [PATCH 1/6] Do not actually sleep if one of the hooks failed.

Victor Lowther victor.lowther at gmail.com
Fri Mar 21 17:46:59 PDT 2008


On Mon, 2008-03-17 at 17:35 -0700, Victor Lowther wrote:
> This patch series aims to improve logging and abort the suspend/resume process
> if a hook fails with an unknown error code.

After a bit more pondering, I want to wait until we have a release
before applying this series.  I have already cherrypicked bits of it
that just deal with logging and pushed them to fd.o, but the whole thing
needs a good deal of discussion w.r.t how to handle failed hooks and
what to do if a hook fails.

> 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"; }
-- 
Victor Lowther
Ubuntu Certified Professional



More information about the Pm-utils mailing list