* 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>
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="\\" ;;
((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