summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xdebootstrap.sh31
1 files changed, 31 insertions, 0 deletions
diff --git a/debootstrap.sh b/debootstrap.sh
index 913bc66..520be3b 100755
--- a/debootstrap.sh
+++ b/debootstrap.sh
@@ -164,12 +164,43 @@ chroot_image()
164 name=$2 164 name=$2
165 shift 2 165 shift 2
166 [ $# -gt 0 ] || set -- $default_chroot_command 166 [ $# -gt 0 ] || set -- $default_chroot_command
167 cgdir=/sys/fs/cgroup/pids/vm-$suite-$name
168 mkdir "$cgdir"
167 set -- \ 169 set -- \
170 cgexec -g pids:vm-$suite-$name \
168 unshare -f -m -p \ 171 unshare -f -m -p \
169 chroot . \ 172 chroot . \
170 /bin/sh -c 'mount -t proc proc /proc; mount -t devpts devpts /dev/pts; exec "$@"' sh \ 173 /bin/sh -c 'mount -t proc proc /proc; mount -t devpts devpts /dev/pts; exec "$@"' sh \
171 "$@" 174 "$@"
172 sh_image "$suite" "$name" "$@" 175 sh_image "$suite" "$name" "$@"
176
177 kill_cgroup "$cgdir"
178}
179
180kill_cgroup()
181{
182 (
183 cgdir="$1"
184
185 # exec >/dev/null 2>&1
186
187 kill=
188 sleep=0.2
189 for n in $(seq 1 20); do
190
191 [ ! -d "$cgdir" ] || rmdir "$cgdir" && return
192
193 pids=$(cat "$cgdir"/tasks)
194 [ -z "$pids" ] || continue
195
196 kill $kill $pids
197 sleep $sleep
198 [ "$n" -eq 5 ] && sleep=1
199 [ "$n" -eq 7 ] && sleep=3
200 [ "$n" -eq 10 ] && kill=-KILL
201 done
202 return 1
203 )
173} 204}
174 205
175clone() 206clone()