Aloa,

- test whether statefile exists in restorestate
restorestate did not check whether a file exists before running cat at it.

- only restore governor if one was actually stored
There was a logic error: Only when the stored governor was empty, i.e. no 
governor was stored, it is restored. The test for an empty string was changed 
to a test for a non-empty string.

- return 1 in case there is no cpu that can use a governor

Now the cpufreq hook should return 1 in case there is no cpu available that 
supports setting a governor. Imho we should define some variables to give 
returncodes a meaning, e.g.
RET_OK=0
RET_SKIPPED=1
RET_ERROR=2
and then use RET_SKIPPED in case a hook does not need to be ran, e.g. for the 
cpufreq hook because it does not support setting governors. This could then 
be evaluated by pm-utils. I will write a patch if there are no objections.

- extra quoting in cpufreq
There was a variable assignment without using quotes.

Regards,
Till
diff --git a/pm/functions b/pm/functions
index 2ae533a..600af36 100755
--- a/pm/functions
+++ b/pm/functions
@@ -277,5 +277,6 @@ savestate()
 
 restorestate()
 {
-	cat "${STORAGEDIR}/state:${1}"
+	local statefile="${STORAGEDIR}/state:${1}"
+	[ -f "${statefile}" ] && cat "${statefile}"
 }
diff --git a/pm/sleep.d/94cpufreq b/pm/sleep.d/94cpufreq
index 0c03400..6b81cf5 100755
--- a/pm/sleep.d/94cpufreq
+++ b/pm/sleep.d/94cpufreq
@@ -1,4 +1,5 @@
 #!/bin/sh
+# vim: noexpandtab
 
 . /usr/lib/pm-utils/functions
 
@@ -6,13 +7,11 @@ hibernate_cpufreq()
 {
 	[ -d /sys/devices/system/cpu/ ] || return 1
 	( cd /sys/devices/system/cpu/
-	for x in cpu[0-9]* ; do
-		[ -f "$x/cpufreq/scaling_governor" ] || continue
-		grep -q "$TEMPORARY_CPUFREQ_GOVERNOR" \
-			"$x/cpufreq/scaling_available_governors" || continue
-		savestate "${x}_governor" $(cat "$x/cpufreq/scaling_governor")
-		echo "$TEMPORARY_CPUFREQ_GOVERNOR" > \
-			"$x/cpufreq/scaling_governor"
+	for governor in cpu[0-9]*/cpufreq/scaling_governor ; do
+		[ -f "${governor}" ] || return 1
+		grep -q "$TEMPORARY_CPUFREQ_GOVERNOR" "${governor}" || continue
+		savestate "${governor%%/*}_governor" "$(cat "${governor}")"
+		echo "$TEMPORARY_CPUFREQ_GOVERNOR" > "${governor}"
 	done )
 }
 
@@ -20,8 +19,8 @@ thaw_cpufreq()
 {
 	( cd /sys/devices/system/cpu/
 	for x in cpu[0-9]* ; do
-		local gov=$(restorestate "${x}_governor")
-		[ -z "$gov" ] || continue
+		local gov="$(restorestate "${x}_governor")"
+		[ -n "$gov" ] || continue
 		echo "$gov" > "$x/cpufreq/scaling_governor"
 	done )
 }

Attachment: signature.asc
Description: This is a digitally signed message part.

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

Reply via email to