Use pivot_root on kernels supporting two namespaces per context.
[util-vserver.git] / scripts / vserver-build.functions
index f94a6aa..1df67e5 100644 (file)
@@ -44,6 +44,8 @@ function makeDevEntry
        (f)     touch "$dst"
                chmod $4 "$dst"
                ;;
+       (l)     ln -s "$4" "$dst"
+               ;;
        (*)     echo "Unknown dev-entry mode '$3'" >&2
                false
                ;;
@@ -54,7 +56,8 @@ function populateDev
 {
     local spec
 
-    mkdir -p -m755 "$VDIR"/dev/pts
+    mkdir -p -m755 "$VDIR"/dev
+    mkdir -m755 "$VDIR"/dev/pts
 
     while read spec; do
        makeDevEntry "$VDIR"/dev $spec
@@ -202,6 +205,9 @@ exist already; please try to use '--force', or remove them manually."
 
     mkdir -p -m755 "$VDIR"
     $_SETATTR --~barrier "$VDIR"
+    $_SETATTR --barrier "$VDIR"/.. || colwarn $"\
+WARNING: could not set the barrier attribute on '$VDIR/..',
+         please set it manually."
     base._addGeneratedFile "$VDIR"
     
     mkdir -p -m755 "$SETUP_CONFDIR"/apps "$VDIR"/etc
@@ -234,11 +240,25 @@ function base._initVariables
     findFile BUILD_INITPOST "$__CONFDIR/.distributions/$DISTRIBUTION/initpost"  "$__DISTRIBDIR/$DISTRIBUTION/initpost" ""
 }
 
+declare -a __BASE_CLEANUP
+function base.pushCleanup
+{
+    __BASE_CLEANUP=( "${__BASE_CLEANUP[@]}" "$*" )
+}
+
+function base.popCleanup
+{
+    unset __BASE_CLEANUP[$((${#__BASE_CLEANUP[@]} - 1))]
+}
+
 function base.__cleanup
 {
-    test -z "$OPTION_KEEP"    || return 0
-    test -z "$__BASE_SUCCESS" || return 0
+    for cmd in "${__BASE_CLEANUP[@]}"; do
+       $cmd
+    done
     
+    test -z "$__BASE_SUCCESS" || return 0
+    test -z "$OPTION_KEEP"    || return 0
     rm -rf "${__BASE_GENERATED_FILES[@]}"
 }
 
@@ -260,10 +280,11 @@ function base.setSuccess
 function startSleepingGuest
 {
     local guest="$1"
-    local timeout="$2"
+    local timeout="${2:-15}"
     $_VSERVER "$guest" start --rescue --rescue-init bash -c "
        exec  > /dev/null
        exec 2> /dev/null
+       trap 'kill -s 9 -- -1; exit 0' INT
        sleep $timeout
        kill -s 15 -- -1
        sleep 1