Description: Fix /dev/shm workaround to only trigger when /dev/shm is a directory
Author: Stéphane Graber <stgraber@ubuntu.com>

Origin: vendor
Bug-Ubuntu: https://bugs.launchpad.net/launchpad/+bug/974584
Forwarded: no

Index: lxc/templates/lxc-ubuntu.in
===================================================================
--- lxc.orig/templates/lxc-ubuntu.in	2012-07-26 13:07:32.000000000 -0400
+++ lxc/templates/lxc-ubuntu.in	2012-07-26 13:11:20.604099863 -0400
@@ -503,9 +503,8 @@
     # I'm afraid of doing rm -rf $rootfs/dev/shm, in case it did
     # get bind mounted to the host's /run/shm.  So try to rmdir
     # it, and in case that fails move it out of the way.
-    if [ -d $rootfs/run/shm ]; then
-        [ -d "$rootfs/dev/shm" ] && rmdir $rootfs/dev/shm
-        [ -e "$rootfs/dev/shm" ] && mv $rootfs/dev/shm $rootfs/dev/shm.bak
+    if [ ! -L $rootfs/dev/shm ] && [ -d $rootfs/run/shm ] && [ -e $rootfs/dev/shm ]; then
+        mv $rootfs/dev/shm $rootfs/dev/shm.bak
         ln -s /run/shm $rootfs/dev/shm
     fi
 }
Index: lxc/templates/lxc-ubuntu-cloud.in
===================================================================
--- lxc.orig/templates/lxc-ubuntu-cloud.in	2012-07-26 13:26:28.134423000 -0400
+++ lxc/templates/lxc-ubuntu-cloud.in	2012-07-26 13:27:40.772127204 -0400
@@ -96,13 +96,12 @@
 sysfs           sys          sysfs defaults  0 0
 EOF
 
-    # rmdir /dev/shm in precise and quantal containers.
+    # rmdir /dev/shm for containers that have /run/shm
     # I'm afraid of doing rm -rf $rootfs/dev/shm, in case it did
     # get bind mounted to the host's /run/shm.  So try to rmdir
     # it, and in case that fails move it out of the way.
-    if [ $release = "precise" ] || [ $release = "quantal" ]; then
-        [ -d "$rootfs/dev/shm" ] && rmdir $rootfs/dev/shm
-        [ -e "$rootfs/dev/shm" ] && mv $rootfs/dev/shm $rootfs/dev/shm.bak
+    if [ ! -L $rootfs/dev/shm ] && [ -d $rootfs/run/shm ] && [ -e $rootfs/dev/shm ]; then
+        mv $rootfs/dev/shm $rootfs/dev/shm.bak
         ln -s /run/shm $rootfs/dev/shm
     fi
 
