Michael Biebl wrote: > Regarding your patch: I discussed that with my co-maintainer. His opinion is, > that your proposed patch is rather a hack then a proper solution, as you would > be unable to suspend for a whole day in case of stale lockfile. His suggestion > was, to use /usr/bin/flock.
Attached is a proposed patch which uses flock. -- Why is it that all of the instruments seeking intelligent life in the universe are pointed away from Earth?
diff --git a/src/pm-action.in b/src/pm-action.in
index e148585..cff96d7 100755
--- a/src/pm-action.in
+++ b/src/pm-action.in
@@ -47,15 +47,9 @@ if [ "$(id -u)" != "0" ]; then
exit 1
fi
-remove_suspend_lock()
-{
- release_lock "${STASHNAME}.lock"
-}
-
-try_lock "${STASHNAME}.lock" || exit 1
-
-# make sure we release the lock no matter how we exit
-trap remove_suspend_lock 0
+touch "${STASHNAME}.lock"
+exec 3<"${STASHNAME}.lock"
+flock -w 0.1 3 || { echo "Lock taken already. Exiting now."; exit 1; }
# clean up from the last run
rm -rf "${STORAGEDIR}"
diff --git a/src/pm-powersave.in b/src/pm-powersave.in
index dff1f64..335dfff 100644
--- a/src/pm-powersave.in
+++ b/src/pm-powersave.in
@@ -27,14 +27,10 @@
export STASHNAME=pm-powersave
. "@PM-UTILS-LIBDIR@/pm-functions"
-remove_powersave_lock() {
- release_lock "${STASHNAME}.lock"
-}
+touch "${STASHNAME}.lock"
+exec 3<"${STASHNAME}.lock"
+flock -w 0.1 3 || { echo "Lock taken already. Exiting now."; exit 1; }
-# take the powersave lock.
-# ensure it gets released no matter how we exit.
-try_lock "${STASHNAME}.lock" || exit 1
-trap remove_powersave_lock 0
mkdir -p "${STORAGEDIR}"
rm -f "${INHIBIT}"
signature.asc
Description: OpenPGP digital signature

