On Mon January 28 2008, Till Maas wrote: > seems to be the best location, i.e. /var/run/pm-utils/lock. The FHS demands > here that it is cleaned and the purpose fits, too.
Here is now a patch agains pm-utils git with /var/run/pm-utils/lock as lockfile. It also makes sure that /var/run/pm-utils, i.e. the directory for the lockfile is generated, and it uses variables for the directories to store state and service information and creates/removes them properly. They are now subdirectories of /var/run/pm-utils. Also it moves the "take_suspend_lock()" line back to its original place, one of the other patches moved it to the wrong location within the funtions file. Regards, Till
diff --git a/pm/functions b/pm/functions
index 439d255..68c14f7 100755
--- a/pm/functions
+++ b/pm/functions
@@ -16,7 +16,9 @@ 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"
+STATEDIR="/var/run/pm-utils/state"
+SERVICEDIR="/var/run/pm-utils/service"
# Use c sort order
export LC_COLLATE=C
@@ -37,14 +39,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,7 +56,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
elapsed=$(($elapsed + 1))
local elapsed=0
@@ -65,28 +69,28 @@ 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 $?
}
+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 "${SERVICEDIR}" "${STATEDIR}"
return 0
}
remove_suspend_lock()
{
- rm -rf /var/run/pm-suspend
+ rm -rf "${SERVICEDIR}" "${STATEDIR}"
chvt 1
chvt $VT
- release_lock "${LOCKDIR}"
+ release_lock "${LOCK}"
}
find_hooks() {
@@ -256,22 +260,22 @@ fi
stopservice()
{
if service "$1" status 2>/dev/null | grep -c -q running; then
- touch "/var/run/pm-suspend/service:$1"
+ touch "${SERVICEDIR}/service:$1"
service "$1" stop
fi
}
restartservice()
{
- [ -f "/var/run/pm-suspend/service:$1" ] && service "$1" start
+ [ -f "${SERVICEDIR}/service:$1" ] && service "$1" start
}
savestate()
{
- echo "$2" > "/var/run/pm-suspend/state:$1"
+ echo "$2" > "${STATEDIR}/state:$1"
}
restorestate()
{
- cat "/var/run/pm-suspend/state:${1}"
+ cat "${STATEDIR}/state:${1}"
}
diff --git a/pm/sleep.d/90clock b/pm/sleep.d/90clock
index 277f349..d4094f8 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
signature.asc
Description: This is a digitally signed message part.
_______________________________________________ Pm-utils mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/pm-utils
