On Monday 28 January 2008 17:22:07 Victor Lowther wrote: > Patches welcome. Remember to take into account cleaning the stale > lockfiles in case of system reboot, including the issues surrounding > PID and datestamp checking.
Here is a patch agains you git repo, I hope I did it right. It also changes 90clock to completely use the lock framework instead of having it's own function to remove the lockdir. Also it moves the ntpd_lock to /var/lock. Regards, Till
diff --git a/pm/functions b/pm/functions
index 7421c6b..d36529e 100755
--- a/pm/functions
+++ b/pm/functions
@@ -16,7 +16,7 @@ INHIBIT=/var/run/pm-utils.inhibit
PM_LOGFILE=${PM_LOGFILE:=/var/log/pm-suspend.log}
SUSPEND_MODULES=""
TEMPORARY_CPUFREQ_GOVERNOR="userspace"
-LOCKDIR="/tmp/.suspended"
+LOCKFILE="/var/lock/pm-utils"
# Use c sort order
export LC_COLLATE=C
@@ -40,10 +40,11 @@ source_configs
# 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
+ # we use noclobber to make sure there are no race conditions
+ (set -o noclobber; echo "${2}" > "${1}") 2> /dev/null || return 1
return 0
}
@@ -51,7 +52,7 @@ 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
local elapsed=0
while ! try_lock $1; do
@@ -63,7 +64,7 @@ spin_lock()
# release the lock
release_lock()
{
- # $1 = directory used as the lock directory
+ # $1 = lockfile
# make sure it is ours first.
rm -rf "$1"
return $?
@@ -72,7 +73,7 @@ release_lock()
take_suspend_lock()
{
- try_lock "$LOCKDIR" || return 1
+ try_lock "$LOCKFILE" || return 1
VT=$(fgconsole)
chvt 63
[ -d /var/run/pm-suspend ] && rm -rf /var/run/pm-suspend
@@ -85,7 +86,7 @@ remove_suspend_lock()
rm -rf /var/run/pm-suspend
chvt 1
chvt $VT
- release_lock "${LOCKDIR}"
+ release_lock "${LOCKFILE}"
}
find_hooks() {
diff --git a/pm/sleep.d/90clock b/pm/sleep.d/90clock
index 35b9843..18cb2ae 100755
--- a/pm/sleep.d/90clock
+++ b/pm/sleep.d/90clock
@@ -1,13 +1,10 @@
#!/bin/sh
. /usr/lib/pm-utils/functions
-NTPD_LOCK=/tmp/.pm-ntpd.lock
-release_ntpd_lock() {
- rmdir "${NTPD_LOCK}"
-}
+NTPD_LOCK=/var/lock/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 +16,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
signature.asc
Description: This is a digitally signed message part.
_______________________________________________ Pm-utils mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/pm-utils
