[Pm-utils] [RFC PATCH 1/3] Rearrange functions.in .

Victor Lowther victor.lowther at gmail.com
Sun Mar 9 19:59:27 PDT 2008


On Wed, Mar 05, 2008 at 07:51:26PM -0800, Victor Lowther wrote:
> Prepare to split functions.in into two separate files.  Do hooks really need
> a function in scope that allows them to run more hooks?  I don't think so.

If there are no strenuous objections to this patch series by Saturday,
March 15, I will merge it (or, the git branch it is a snapshot of, at
least) into the fd.o upstream.
 
> ---
>  pm/functions.in |  164 +++++++++++++++++++++++++++---------------------------
>  1 files changed, 82 insertions(+), 82 deletions(-)
> 
> diff --git a/pm/functions.in b/pm/functions.in
> index e0fc960..bfa9a55 100644
> --- a/pm/functions.in
> +++ b/pm/functions.in
> @@ -9,7 +9,10 @@
>  # RESUME_MODULES
>  #
>  # for great debugging!
> -[ "${PM_DEBUG}" = "true" ] && set -x
> +[ "${PM_DEBUG}" = "true" ] && {
> +	export PM_DEBUG
> +	set -x
> +}
>  set -a
>  PM_UTILS_LIBDIR="@PM-UTILS-LIBDIR@"
>  PM_UTILS_ETCDIR="@PM-UTILS-SYSCONFDIR@"
> @@ -34,17 +37,87 @@ export LC_COLLATE=C
>  
>  set +a
>  
> -source_configs()
> +for cfg in "${PM_UTILS_ETCDIR}"/config.d/*[!~] ; do
> +	[ -f "$cfg" ] || continue
> +	set -a
> +	. "${cfg}"
> +	set +a
> +done
> +
> +take_suspend_lock()
>  {
> -	for cfg in "${PM_UTILS_ETCDIR}"/config.d/*[!~] ; do
> -		[ -f "$cfg" ] || continue
> -		set -a
> -		. "${cfg}"
> -		set +a
> +	VT=$(fgconsole)
> +	chvt 63
> +	try_lock "pm-utils.lock" || return 1
> +	mkdir -p "${STORAGEDIR}"
> +	return 0
> +}
> +
> +remove_suspend_lock()
> +{
> +	rm -rf "${STORAGEDIR}"
> +	chvt 1
> +	chvt $VT
> +	release_lock "pm-utils.lock"
> +}
> +
> +hook_exit_status(){
> +	case $1 in
> +		0) echo "success." ;;
> +		$NA) echo "not applicable." ;;
> +		*) echo "Returned exit code $1." ;;
> +	esac
> +}
> +
> +run_hooks() {
> +	# $1 = type of hook to find.  
> +	# $2 = paramaters to pass to hooks.
> +	# $3 = 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"
> +	local sort="sort"
> +	local base
> +	local hook
> +	local oifs="${IFS}"
> +	# the next two lines are not a typo or a formatting error!
> +	local nifs="
> +"
> +	IFS="${nifs}" # tolerate spaces in filenames.
> +	[ "$3" = "reverse" ] && sort="sort -r"
> +	for base in $(IFS="${oifs}"; for f in "$syshooks/"*[!~] "$phooks/"*[!~];
> +		do [ -O "$f" ] && echo ${f##*/} ; done | $sort | uniq) ;
> +	do
> +		if [ -f "$syshooks/$base" ]; then
> +			hook="$syshooks/$base"
> +		elif [ -f "$phooks/$base" ]; then
> +			hook="$phooks/$base"
> +		fi
> +		[ -x "${hook}" ] && (
> +			IFS="${oifs}"
> +			echo "$(date): running ${hook} $2"
> +			"${hook}" $2
> +			hook_exit_status $?
> +		)
>  	done
> +	IFS="${oifs}"
> +}
> +
> +init_logfile()
> +{
> +	if [ -h "$1" ]; then
> +		echo "$1 is a symbolic link, refusing to overwrite."
> +		return 1
> +	elif [ ! -O "$1" ]; then
> +		echo "We do not own $1, refusing to overwrite."
> +		return 1
> +	elif [ -z "$1" ]; then
> +		echo "Please pass a filename to init_logfile."
> +		return 1
> +	fi
> +	exec > "$1" 2>&1
>  }
>  
> -source_configs
>  
>  SLEEP_FUNCTIONS="${PM_UTILS_LIBDIR}/module.d/${SLEEP_MODULE}"
>  [ -f "${SLEEP_FUNCTIONS}" ] || { 
> @@ -54,6 +127,7 @@ SLEEP_FUNCTIONS="${PM_UTILS_LIBDIR}/module.d/${SLEEP_MODULE}"
>  
>  . "${SLEEP_FUNCTIONS}"
>  
> +
>  # try to take the lock.  Fail if we cannot get it.
>  try_lock()
>  {
> @@ -93,23 +167,6 @@ release_lock()
>  }
>  
>  
> -take_suspend_lock()
> -{
> -	VT=$(fgconsole)
> -	chvt 63
> -	try_lock "pm-utils.lock" || return 1
> -	mkdir -p "${STORAGEDIR}"
> -	return 0
> -}
> -
> -remove_suspend_lock()
> -{
> -	rm -rf "${STORAGEDIR}"
> -	chvt 1
> -	chvt $VT
> -	release_lock "pm-utils.lock"
> -}
> -
>  
>  command_exists()
>  {
> @@ -119,48 +176,6 @@ command_exists()
>  	return $?
>  }
>  
> -hook_exit_status(){
> -	case $1 in
> -		0) echo "success." ;;
> -		$NA) echo "not applicable." ;;
> -		*) echo "Returned exit code $1." ;;
> -	esac
> -}
> -
> -run_hooks() {
> -	# $1 = type of hook to find.  
> -	# $2 = paramaters to pass to hooks.
> -	# $3 = 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"
> -	local sort="sort"
> -	local base
> -	local hook
> -	local oifs="${IFS}"
> -	# the next two lines are not a typo or a formatting error!
> -	local nifs="
> -"
> -	IFS="${nifs}" # tolerate spaces in filenames.
> -	[ "$3" = "reverse" ] && sort="sort -r"
> -	for base in $(IFS="${oifs}"; for f in "$syshooks/"*[!~] "$phooks/"*[!~];
> -		do [ -O "$f" ] && echo ${f##*/} ; done | $sort | uniq) ;
> -	do
> -		if [ -f "$syshooks/$base" ]; then
> -			hook="$syshooks/$base"
> -		elif [ -f "$phooks/$base" ]; then
> -			hook="$phooks/$base"
> -		fi
> -		[ -x "${hook}" ] && (
> -			IFS="${oifs}"
> -			echo "$(date): running ${hook} $2"
> -			"${hook}" $2
> -			hook_exit_status $?
> -		)
> -	done
> -	IFS="${oifs}"
> -}
> -
>  get_power_status()
>  {
>  	RETVAL=0
> @@ -180,21 +195,6 @@ get_power_status()
>  	return $RETVAL
>  }
>  
> -init_logfile()
> -{
> -	if [ -h "$1" ]; then
> -		echo "$1 is a symbolic link, refusing to overwrite."
> -		return 1
> -	elif [ ! -O "$1" ]; then
> -		echo "We do not own $1, refusing to overwrite."
> -		return 1
> -	elif [ -z "$1" ]; then
> -		echo "Please pass a filename to init_logfile."
> -		return 1
> -	fi
> -	exec > "$1" 2>&1
> -}
> -
>  _rmmod()
>  {
>  	if modprobe -r "$1"; then
> -- 
> 1.5.4.3
> 

-- 
Victor Lowther
Ubuntu Certified Professional


More information about the Pm-utils mailing list