Correct lock check failures 67/5967/2
authorC.J. Collier <cjcollier@linuxfoundation.org>
Fri, 31 Mar 2017 03:47:34 +0000 (20:47 -0700)
committerC.J. Collier <cjcollier@linuxfoundation.org>
Fri, 31 Mar 2017 04:10:53 +0000 (21:10 -0700)
* fuser can take multiple filenames and return the lock status
  atomically
- This eliminates a race condition we were experiencing

* if the file was locked, run the lock check again.  Otherwise, just
  run apt-get directly

Change-Id: I00eb6e0fa6bdf223eadfcade05f4a4f00745750f
Signed-off-by: C.J. Collier <cjcollier@linuxfoundation.org>
packer/provision/baseline.sh

index aaf1fa1..82edb3f 100644 (file)
@@ -122,7 +122,10 @@ EOF
 
 i=0
 tput sc
-while [ fuser /var/lib/dpkg/lock >/dev/null 2>&1 || fuser /var/lib/apt/lists/lock >/dev/null 2>&1 ]; do
+LOCKFILES="/var/lib/dpkg/lock /var/lib/apt/lists/lock"
+WASLOCKED=0
+while [ fuser ${LOCKFILES} >/dev/null 2>&1 ]; do
+    WASLOCKED=$?
     case $(($i % 4)) in
         0 ) j="-" ;;
         1 ) j="\\" ;;
@@ -135,7 +138,12 @@ while [ fuser /var/lib/dpkg/lock >/dev/null 2>&1 || fuser /var/lib/apt/lists/loc
     ((i=i+1))
 done
 
-/usr/bin/apt-get "$@"
+if [ $WASLOCKED==0 ]
+then
+  /usr/bin/apt-get "$@"
+else
+  exec /usr/local/bin/apt-get "$@"
+fi
 
 EOF
     chmod +x /usr/local/bin/apt-get