File pm-utils-0.99.4-uswsusp-support.diff of Package pm-utils

Index: b/pm/functions
===================================================================
--- a/pm/functions
+++ b/pm/functions
@@ -12,10 +12,12 @@ export PATH=/sbin:/usr/sbin:/bin:/usr/bi
 set -a
 HIBERNATE_RESUME_POST_VIDEO=no
 INHIBIT=/var/run/pm-utils.inhibit
 PM_LOGFILE=${PM_LOGFILE:=/var/log/pm-suspend.log}
 SUSPEND_MODULES=""
+HIBERNATE_METHOD=""
+S2DISK_CONF="/etc/suspend.conf"
 TEMPORARY_CPUFREQ_GOVERNOR="userspace"
 
 [ -f /usr/lib/pm-utils/defaults ] && . /usr/lib/pm-utils/defaults
 set +a
 
@@ -73,35 +75,36 @@ find_sleepd_files()
 	done
 }
 
 run_hooks()
 {
+	# $1=suspend/suspend_hybrid/hibernate $2=suspend/hibernate/thaw/resume $3=reverse/""
 	[ -z "$1" ] && return 0
 
 	[ -f /var/run/pm-suspend ] && . /var/run/pm-suspend
 	rm -f /var/run/pm-suspend
 
-	echo "$(date): running $1 hooks."
+	echo "$(date): running '$1'/'$2'/'$3' hooks."
 
 	files=$(find_sleepd_files)
-	if [ "$2" = "reverse" ]; then
+	if [ "$3" = "reverse" ]; then
 		filea=($files)
 		filen=${#filea[*]}
 		while [ "$filen" -gt 0 ]; do
 			let filen--
 			file="${filea[$filen]}"
 			echo "===== $(date): running hook: $file ====="
-			$file $1
+			$file $2 $1
 		done
 	else
 		for file in $files ; do
 			echo "===== $(date): running hook: $file ====="
-			$file $1
+			$file $2 $1
 		done
 	fi
 
-	echo "$(date): done running $1 hooks."
+	echo "$(date): done running $1/$2 hooks."
 }
 
 get_power_status()
 {
 	RETVAL=0
@@ -119,47 +122,183 @@ get_power_status()
 			;;
 	esac
 	return $RETVAL
 }
 
+get_s2ram_cmdline()
+{
+	local ACPI_FLAG UNHANDLED
+	let ACPI_FLAG=0
+	if [ -n "$QUIRK_NONE" ]; then
+		echo "INFO: HAL quirks state no quirk is neeed."
+		return;
+	fi
+	[ -n "$QUIRK_S3_BIOS" ] && ACPI_FLAG=1
+	[ -n "$QUIRK_S3_MODE" ] && let ACPI_FLAG+=2
+	[ $ACPI_FLAG -ne 0 ] &&			S2RAM_OPTS+="--acpi_sleep $ACPI_FLAG "
+	[ -n "$QUIRK_VBE_POST" ] &&		S2RAM_OPTS+="--vbe_post "
+	[ -n "$QUIRK_VBEMODE_RESTORE" ] &&	S2RAM_OPTS+="--vbe_mode "
+	[ -n "$QUIRK_VBESTATE_RESTORE" ] &&	S2RAM_OPTS+="--vbe_save "
+	[ -n "$QUIRK_RADEON_OFF" ] &&		S2RAM_OPTS+="--radeontool "
+	# the unhandled quirks...
+	[ -n "$QUIRK_DPMS_ON" ] &&		UNHANDLED+="QUIRK_DPMS_ON "
+	[ -n "$QUIRK_DPMS_SUSPEND" ] &&		UNHANDLED+="QUIRK_DPMS_SUSPEND "
+	[ -n "$QUIRK_RESET_BRIGHTNESS" ] &&	UNHANDLED+="QUIRK_RESET_BRIGHTNESS "
+	[ -n "$QUIRK_VGA_MODE_3" ] &&		UNHANDLED+="QUIRK_VGA_MODE_3 "
+	if [ -n "$UNHANDLED" ]; then
+		echo "INFO: those quirks are not handled yet: $UNHANDLED"
+	fi
+	echo "INFO: S2RAM_OPTS from HAL quirks: '$S2RAM_OPTS'."
+}
+
+# this function tries to assemble the best s2ram options from various sources, falling back
+# to other methods...
+get_s2ram_opts()
+{
+	# if S2RAM_OPTS is set - then use it. The user told us so. Obey his wish.
+	if [ -n "$S2RAM_OPTS" ]; then
+		echo "INFO: using user-supplied options: S2RAM_OPTS='$S2RAM_OPTS' for suspending."
+		return
+	fi
+
+	# The user did not tell us the options, so let's check if he expressed a preference for
+	# quirks passed by HAL via the command line...
+	if [ "$S2RAM_QUIRKS_SOURCE" = "hal" ]; then
+		# use the quirks from HAL
+		S2RAM_OPTS="--force"
+		get_s2ram_cmdline
+		return
+	fi
+
+	# ...or if he prefers the s2ram built in list...
+	if [ "$S2RAM_QUIRKS_SOURCE" = "s2ram" ]; then
+		if  /usr/sbin/s2ram -n >/dev/null; then
+			echo "INFO: using s2ram built-in database, machine is supported."
+			return
+		else
+			echo "WARN: S2RAM_QUIRKS_SOURCE=s2ram, but machine is unknown, continuing..."
+		fi
+	fi
+
+	# still nothing. So let's try to be smart.
+	# first check if a "good" kernel module is loaded.
+	for MODULE in i915 fglrx nvidia; do
+		if [ -d /sys/module/$MODULE ]; then
+			echo "INFO: module $MODULE is loaded, trusting it to restore video after resume."
+			S2RAM_OPTS="--force"
+			return
+		fi
+	done
+
+	# now we check if s2ram knows the machine.
+	if /usr/sbin/s2ram -n >/dev/null; then
+		echo "INFO: machine is in s2ram database, using it."
+		return;
+	fi
+
+	# s2ram does not know the machine, ask HAL...
+	echo "INFO: no quirks found, using info passed by HAL."
+	get_s2ram_cmdline
+	if [ -n "$S2RAM_OPTS" ]; then
+		S2RAM_OPTS+="--force "
+	fi
+
+	# if we came here and S2RAM_OPTS is empty, suspend won't work :-(
+}
+
 do_suspend()
 {
-	pm-pmu --suspend || echo -n "mem" > /sys/power/state
+	local RET
+	echo "INFO: going to suspend. In case of problems with the selected suspend options,"
+	echo "INFO: please read /usr/share/doc/packages/pm-utils/README.smart-suspend-to-RAM"
+	get_s2ram_opts
+	if [ -x /usr/sbin/s2ram ]; then
+		set -x
+		/usr/sbin/s2ram $S2RAM_OPTS
+		RET=$?
+		set +x
+	else
+		pm-pmu --suspend || echo -n "mem" > /sys/power/state
+		RET=$?
+	fi
+	return $RET
 }
 
 do_hibernate()
 {
-	echo -n "platform" > /sys/power/disk
-	echo -n "disk" > /sys/power/state
+	local RET=1
+	if [ -z "$HIBERNATE_METHOD" ]; then
+		if [ -x /usr/sbin/s2disk -a -c /dev/snapshot ]; then
+			HIBERNATE_METHOD="userspace"
+		else
+			HIBERNATE_METHOD="kernel"
+		fi
+	fi
+	case $HIBERNATE_METHOD in
+		userspace)
+			set -x
+			/usr/sbin/s2disk --config $S2DISK_CONF
+			RET=$?
+			set +x
+			;;
+		kernel)
+			echo -n "platform" > /sys/power/disk
+			echo -n "disk" > /sys/power/state
+			RET=$?
+			;;
+	esac
+	return $RET
 }
 
 do_suspend_hybrid()
 {
-	return 1
+	local RET=1
+	if [ -z "$HIBERNATE_METHOD" ]; then
+		if [ -x /usr/sbin/s2both -a -c /dev/snapshot ]; then
+			HIBERNATE_METHOD="userspace"
+		else
+			HIBERNATE_METHOD="kernel"
+		fi
+	fi
+	case $HIBERNATE_METHOD in
+		userspace)
+			get_s2ram_opts
+			set -x
+			/usr/sbin/s2both --config $S2DISK_CONF
+			RET=$?
+			set +x
+			;;
+		*)
+			RET=1
+			;;
+	esac
+	return $RET
 }
 
 pm_main()
 {
+	local RET=1
 	if [ -n "$PM_LOGFILE" ]; then
 		exec > "$PM_LOGFILE" 2>&1
 	fi
 	take_suspend_lock || exit 1
 
 	rm -f "$INHIBIT"
 
-	run_hooks "$1"
+	run_hooks "$1" "$2"
 
 	if [ ! -e "$INHIBIT" -a "$(type -t "do_$1")" == "function" ]; then
 		sync ; sync ; sync
 		"do_$1"
+		RET=$?
 	fi
 
-	run_hooks "$2" reverse
+	run_hooks "$1" "$3" reverse
 
 	remove_suspend_lock 200
 
-	return 0
+	return $RET
 }
 
 _rmmod() {
 	if modprobe -r $1; then
 		echo "export RESUME_MODULES=\"$1 \$RESUME_MODULES\"" \
Index: b/src/pm-is-supported
===================================================================
--- a/src/pm-is-supported
+++ b/src/pm-is-supported
@@ -34,13 +34,13 @@ case "$ARG" in
 	hibernate)
 		[ -f /sys/power/disk ] || exit 1
 		grep -q disk /sys/power/state || exit 1
 		;;
 	suspend-hybrid)
-		# grep -q mem /sys/power/state || exit 1
-		# grep -q disk /sys/power/state || exit 1
-		exit 1
+		grep -q mem /sys/power/state || exit 1
+		grep -q disk /sys/power/state || exit 1
+		[ -x /usr/sbin/s2both -a -c /dev/snapshot ] || exit 1
 		;;
 	help)
 		help_options
 		;;
 	*)
Index: b/src/pm-action
===================================================================
--- a/src/pm-action
+++ b/src/pm-action
@@ -97,10 +97,11 @@ set +a
 
 
 ACTION=$(basename "$0")
 ACTION=${ACTION#pm-}
 ACTION=${ACTION/-/_}
+METHOD=$ACTION
 
 case "$ACTION" in
 	suspend)
 		if ! grep -q mem /sys/power/state ; then
 			echo "Error: kernel cannot suspend to ram." 1>&2
@@ -112,15 +113,23 @@ case "$ACTION" in
 			echo "Error: kernel cannot suspend to disk." 1>&2
 			exit 1
 		fi
 		REVERSE=thaw
 		;;
+	suspend_hybrid)
+		if ! pm-is-supported --suspend-hybrid; then
+			echo "Error: system cannot do hybrid suspend." 1>&2
+			exit 1
+		fi
+		ACTION=suspend
+		REVERSE=resume
+		;;
 	*)
 		exit 1
 		;;
 esac
 
 export PM_CMDLINE="$@"
 
-pm_main "$ACTION" "$REVERSE"
+pm_main "$METHOD" "$ACTION" "$REVERSE"
 
 exit $?
openSUSE Build Service is sponsored by