From cfa1d2e02fa3392431cbcf0d483d86bb7b3ad6ec Mon Sep 17 00:00:00 2001 From: Fabio Rehm Date: Sun, 9 Mar 2014 22:59:18 -0300 Subject: [PATCH] boxes: Update lxc-template to use a file lock around rootfs extraction --- boxes/common/lxc-template | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/boxes/common/lxc-template b/boxes/common/lxc-template index a9318d1..b420c2a 100755 --- a/boxes/common/lxc-template +++ b/boxes/common/lxc-template @@ -106,8 +106,24 @@ fi # Unpack the rootfs echo "Unpacking the rootfs" -mkdir -p ${LXC_ROOTFS} -(cd ${LXC_ROOTFS} && tar xfz ${LXC_TARBALL} --strip-components=2) + +( + flock -x 200 + if [ $? -ne 0 ]; then + echo "Cache repository is busy." + return 1 + fi + + mkdir -p ${LXC_ROOTFS} + (cd ${LXC_ROOTFS} && tar xfz ${LXC_TARBALL} --strip-components=2) + if [ $? -ne 0 ]; then + echo "Failed to extract rootfs" + return 1 + fi + + return 0 + +) 200>/var/lock/subsys/lxc mkdir -p ${LXC_ROOTFS}/dev/pts/