~ubuntu-branches/ubuntu/trusty/pm-utils/trusty-updates

« back to all changes in this revision

Viewing changes to debian/patches/08-fix-lock-file-handling.patch

  • Committer: Bazaar Package Importer
  • Author(s): Michael Biebl
  • Date: 2010-02-16 15:22:15 UTC
  • mfrom: (40.1.1 experimental)
  • Revision ID: james.westby@ubuntu.com-20100216152215-ldnggaxqkmsxr54s
Tags: 1.3.0~rc3-2
* Bump Standards-Version to 3.8.4. No further changes.
* debian/patches/06-quirk-lkw-cache.patch
  - Store the last_known_working.quirkdb cache file in /var/cache/pm-utils.
* debian/pm-utils.dirs
  - Add /var/cache/pm-utils/ directory.
* debian/pm-utils.preinst
  - Remove last_known_working.quirkdb cache file from /etc/pm on upgrades.
* debian/control
  - Add Recommends on procps. The sysctl binary is required for setting the
    acpi flags in 99video.
* debian/patches/07-fix-typo-pm-action.patch
  - Fix typo ('lits') in pm-action man page. (Closes: #567084)
    Thanks to Filipus Klutiero for spotting this.
* debian/patches/08-fix-lock-file-handling.patch
  - Use flock to make the lock file handling more robust. (Closes: #568565)
* debian/patches/09-document-add-drop-parameters.patch
  - Document the {ADD,DROP}_PARAMETERS configuration variables in the
    pm-action man page. (Closes: #485443)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
Description: Use flock for a more robust lock file handling
 
2
Debian-Bug: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=568565
 
3
Author: Michael Biebl <biebl@debian.org>
 
4
diff --git a/pm/HOWTO.hooks b/pm/HOWTO.hooks
 
5
index ad7d4a7..ce9e8c4 100644
 
6
--- a/pm/HOWTO.hooks
 
7
+++ b/pm/HOWTO.hooks
 
8
@@ -99,7 +99,7 @@ the hook. This will make the following convenience functions available:
 
9
 2:  spin_lock
 
10
        Wrapper around try_lock.  Second parameter is the number of seconds 
 
11
        to wait for the lock before giving up.  If no second parameter
 
12
-       is passed, this function will wait forever.
 
13
+       is passed, this function will wait for 60 seconds.
 
14
 3:  release_lock
 
15
        Release a previously acquired lock.  First parameter is the name of the
 
16
        lock.
 
17
diff --git a/pm/functions.in b/pm/functions.in
 
18
index 8388c65..b07bf44 100644
 
19
--- a/pm/functions.in
 
20
+++ b/pm/functions.in
 
21
@@ -22,13 +22,13 @@ is_set "${PM_DEBUG}" && set -x
 
22
 try_lock()
 
23
 {
 
24
        # $1 = file to use as lockfile
 
25
-       # $2 (optional) content to write to the lockfile,
 
26
-       # extra newline will be appended
 
27
+       local lock="${LOCKDIR}/${1##*/}"
 
28
+
 
29
        # make sure the directory where the lockfile should be exists
 
30
        mkdir -p "${LOCKDIR}"
 
31
-       local lock="${LOCKDIR}/${1##*/}"
 
32
-       # we use noclobber to make sure there are no race conditions
 
33
-       (set -o noclobber; echo "${2}" > "${lock}") 2> /dev/null || return 1
 
34
+       touch "${lock}"
 
35
+       exec 3<"${lock}"
 
36
+       flock -x -n 3 || return 1
 
37
        return 0
 
38
 }
 
39
 
 
40
@@ -37,13 +37,15 @@ try_lock()
 
41
 spin_lock()
 
42
 {
 
43
        # $1 = lockfile
 
44
-       # $2 = optional timeout
 
45
-       local elapsed=0
 
46
-       while ! try_lock $1; do
 
47
-               [ "x$2" != "x" ] && [ $(( $elapsed == $2 )) -ne 0 ] && return 1
 
48
-               elapsed=$(($elapsed + 1))
 
49
-               sleep 1;
 
50
-       done
 
51
+       # $2 = optional timeout (default is 60 secs)
 
52
+       local lock="${LOCKDIR}/${1##*/}"
 
53
+       local timeout="${2:-60}"
 
54
+
 
55
+       mkdir -p "${LOCKDIR}"
 
56
+       touch "${lock}"
 
57
+       exec 3<"${lock}"
 
58
+       flock -x -w "${timeout}" 3 || return 1
 
59
+       return 0
 
60
 }
 
61
 
 
62
 # release the lock