]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
lxc-create: cleanup whenever exiting with error
authorSerge Hallyn <serge.hallyn@ubuntu.com>
Wed, 24 Apr 2013 20:16:21 +0000 (15:16 -0500)
committerStéphane Graber <stgraber@ubuntu.com>
Wed, 24 Apr 2013 23:54:39 +0000 (01:54 +0200)
Otherwise we leave bad containers sitting around and further confuse
things on retries.

Reported-by: Mukanyiligira Didacienne <siyana223@gmail.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
src/lxc/lxc-create.in

index fbb566f63dc260fec61065a002686d1b61d9339b..553ffd27106bf277b36c6c73a7bb42b652371246 100644 (file)
@@ -286,7 +286,7 @@ fi
 
 if [ ! -r "$lxc_config" ]; then
     echo "$(basename $0): '$lxc_config' configuration file not found" >&2
-    exit 1
+    cleanup
 fi
 
 if [ ! -z "$lxc_template" ]; then
@@ -317,11 +317,11 @@ echo "" >> $lxc_path/$lxc_name/config
 if [ -n "$custom_rootfs" ]; then
     if grep -q "lxc.rootfs" $lxc_path/$lxc_name/config ; then
         echo "configuration file already specifies a lxc.rootfs"
-        exit 1
+        cleanup
     fi
     if [ -d "$custom_rootfs" ]; then
         echo "specified rootfs ($custom_rootfs) already exists.  Bailing."
-        exit 1
+        cleanup
     fi
     echo "lxc.rootfs = $custom_rootfs" >> $lxc_path/$lxc_name/config
 fi
@@ -329,9 +329,9 @@ fi
 # Create the fs as needed
 if [ "$backingstore" = "lvm" ]; then
     [ -d "$rootfs" ] || mkdir $rootfs
-    lvcreate -L $fssize -n $lvname $vgname || exit 1
+    lvcreate -L $fssize -n $lvname $vgname || cleanup
     udevadm settle
-    mkfs -t $fstype $rootdev || exit 1
+    mkfs -t $fstype $rootdev || cleanup
     mount -t $fstype $rootdev $rootfs
 fi