On Tue January 29 2008, Victor Lowther wrote:

> suspend_clock() {
>       if try_lock "${NTPD_LOCK}"; then
> -             trap release_ntpd_lock 0
> +             trap 'release_lock ${NTPD_LOCK}"' 0 <-- bad quoting, which is
> probably why the lockfile is not getting removed.
>               stopservice ntpd
>       fi

Fixed in attached patch.

> +STATEDIR="/var/run/pm-utils/state"
> +SERVICEDIR="/var/run/pm-utils/service"
> +MODULEDIR="/var/run/pm-utils/modules"

Now it is only STORAGEDIR. Also this patch fixes the spin_lock issue that 
Michael found.

Regards,
Till
diff --git a/pm/functions b/pm/functions
index fbf03f8..92ece00 100755
--- a/pm/functions
+++ b/pm/functions
@@ -16,7 +16,8 @@ INHIBIT=/var/run/pm-utils.inhibit
 PM_LOGFILE=${PM_LOGFILE:=/var/log/pm-suspend.log}
 SUSPEND_MODULES=""
 TEMPORARY_CPUFREQ_GOVERNOR="performance"
-LOCKDIR="/tmp/.suspended"
+LOCK="/var/run/pm-utils/lock"
+STORAGEDIR="/var/run/pm-utils/storage"
 
 # Use c sort order
 export LC_COLLATE=C
@@ -37,14 +38,16 @@ source_configs()
 
 source_configs
 
-take_suspend_lock()
 # try to take the lock.  Fail if we cannot get it.
 try_lock()
 {
-	# $1 = directory to use as lock directory
-	# we use directory creation because the kernel enforces atomicity, 
-	# and mkdir will fail if the directory already exists.
-	mkdir "$1" >/dev/null 2>&1 || return 1
+	# $1 = file to use as lockfile
+	# $2 (optional) content to write to the lockfile,
+	#               extra newline will be appended
+	# make sure the directory where the lockfile should be exists
+	mkdir -p ${1%/*}
+	# we use noclobber to make sure there are no race conditions
+	(set -o noclobber; echo "${2}" > "${1}") 2> /dev/null || return 1
 	return 0
 }
 
@@ -52,41 +55,41 @@ try_lock()
 # return once we have it, or the timeout has expired
 spin_lock()
 {
-	# $1 = directory to use as the lock directory
+	# $1 = lockfile
 	# $2 = optional timeout
-		elapsed=$(($elapsed + 1))
 	local elapsed=0
 	while ! try_lock $1; do
 		sleep 1;
 		[ "x$2" != "x" ] && [ $(( $elapsed == $2 )) -ne 0 ] && return 1
+		elapsed=$(($elapsed + 1))
 	done
 }
 
 # release the lock
 release_lock()
 {
-	# $1 = directory used as the lock directory
+	# $1 = lockfile
 	# make sure it is ours first.
 	rm -rf "$1"
 	return $?
 }
 
 
+take_suspend_lock()
 {
 	VT=$(fgconsole)
 	chvt 63
-	try_lock "$LOCKDIR" || return 1
-	[ -d /var/run/pm-suspend ] && rm -rf /var/run/pm-suspend
-	mkdir /var/run/pm-suspend
+	try_lock "$LOCK" || return 1
+	mkdir -p "${STORAGEDIR}"
 	return 0
 }
 
 remove_suspend_lock()
 {
-	rm -rf /var/run/pm-suspend
+	rm -rf "${STORAGEDIR}"
 	chvt 1
 	chvt $VT
-	release_lock "${LOCKDIR}"
+	release_lock "${LOCK}"
 }
 
 find_hooks() {
@@ -188,7 +191,7 @@ pm_main()
 
 _rmmod() {
 	if modprobe -r $1; then
-		touch "/var/run/pm-suspend/module:$1"
+		touch "${STORAGEDIR}/module:$1"
 		return 0
 	else
 		echo "# could not unload '$1', usage count was $2"
@@ -234,7 +237,7 @@ modunload()
 # reload all the modules in no particular order.
 modreload()
 {
-	for x in /var/run/pm-suspend/module:* ; do
+	for x in ${STORAGEDIR}/module:* ; do
 		[ -f "${x}" ] && modprobe "${x##*:}" >/dev/null 2>&1
 	done
 }
@@ -253,22 +256,22 @@ fi
 stopservice()
 {
 	if service "$1" status 2>/dev/null | grep -c -q running; then
-		touch "/var/run/pm-suspend/service:$1"
+		touch "${STORAGEDIR}/service:$1"
 		service "$1" stop
 	fi
 }
 
 restartservice()
 {
-	[ -f "/var/run/pm-suspend/service:$1" ] && service "$1" start
+	[ -f "${STORAGEDIR}/service:$1" ] && service "$1" start
 }
 
 savestate()
 {
-	echo "$2" > "/var/run/pm-suspend/state:$1"
+	echo "$2" > "${STORAGEDIR}/state:$1"
 }
 
 restorestate()
 {
-	cat "/var/run/pm-suspend/state:${1}"
+	cat "${STORAGEDIR}/state:${1}"
 }
diff --git a/pm/sleep.d/90clock b/pm/sleep.d/90clock
index 277f349..6e73714 100755
--- a/pm/sleep.d/90clock
+++ b/pm/sleep.d/90clock
@@ -1,13 +1,11 @@
 #!/bin/sh
 . /usr/lib/pm-utils/functions
 
-NTPD_LOCK=/tmp/.pm-ntpd.lock
-release_ntpd_lock() {
-	rmdir "${NTPD_LOCK}"
-}
+NTPD_LOCK="/var/run/pm-utils/pm-ntpd.lock"
+
 suspend_clock() {
 	if try_lock "${NTPD_LOCK}"; then
-		trap release_ntpd_lock 0
+		trap 'release_lock "${NTPD_LOCK}"' 0
 		stopservice ntpd
 	fi
 	/sbin/hwclock --systohc >/dev/null 2>&1 0<&1
@@ -19,7 +17,7 @@ resume_clock() {
 	rc=$?
 	# Bring back ntpd _after_ NetworkManager and such come back...
 	( 	spin_lock "${NTPD_LOCK}";
-		trap release_ntpd_lock 0
+		trap 'release_lock "${NTPD_LOCK}"' 0
 		sleep 20; 
 		restartservice ntpd; ) &
 	return $rc

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