Adds a generic locking mechanism built around directory creation/removal.
diff -U 0 -rNX diffignore pm-utils.updates/pm/functions working/pm/functions
--- pm-utils.updates/pm/functions 2008-01-27 11:58:02.000000000 -0600
+++ working/pm/functions 2008-01-27 11:26:51.000000000 -0600
@@ -18,0 +18 @@
+LOCKDIR="/tmp/.suspended"
@@ -42,0 +38,33 @@
+# 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
+ return 0
+}
+
+# spin waiting for the lock with optional timeout.
+# return once we have it, or the timeout has expired
+spin_lock()
+{
+ # $1 = directory to use as the lock directory
+ # $2 = optional timeout
+ local elapsed=0
+ while ! try_lock $1; do
+ sleep 1;
+ [ "x$2" != "x" ] && [ $(( $elapsed == $2 )) -ne 0 ] && return 1
+ done
+}
+
+# release the lock
+release_lock()
+{
+ # $1 = directory used as the lock directory
+ # make sure it is ours first.
+ rm -rf "$1"
+ return $?
+}
+
+
_______________________________________________
Pm-utils mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/pm-utils