Skip to content

Commit 48ba7f5

Browse files
committed
More tweaks by Marcus
Thanks!
1 parent 8a95adc commit 48ba7f5

5 files changed

+44
-27
lines changed

build-vm-ec2

+2-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ vm_detach_swap_ec2() {
131131

132132
vm_fixup_ec2() {
133133
# No way to handle this via init= parameter here....
134-
rm -rf "$BUILD_ROOT/sbin/init"
134+
buildroot_rm /sbin/init
135135
echo "#!/bin/sh" > "$BUILD_ROOT/sbin/init"
136136
echo 'exec /.build/build "$@"' >> "$BUILD_ROOT/sbin/init"
137137
chmod 0755 "$BUILD_ROOT/sbin/init"
@@ -146,6 +146,7 @@ vm_fixup_ec2() {
146146
if ! test -e "$BUILD_ROOT/boot/grub/menu.lst"; then
147147
assert_dirs boot/grub
148148
mkdir -p "$BUILD_ROOT/boot/grub"
149+
buildroot_rm /boot/grub/menu.lst
149150
echo "serial --unit=0 --speed=9600" > "$BUILD_ROOT/boot/grub/menu.lst"
150151
echo "terminal --dumb serial" >> "$BUILD_ROOT/boot/grub/menu.lst"
151152
echo "default 0" >> "$BUILD_ROOT/boot/grub/menu.lst"

build-vm-lxc

+7-6
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ lxcsh() {
4444
vm_startup_lxc() {
4545
lxc_get_id
4646
LXCCONF="$BUILD_ROOT/.build.lxc.conf"
47-
rm -rf "$LXCCONF"
47+
buildroot_rm .build.lxc.conf
4848
vm_startup_lxc_$LXC_TYPE
4949
BUILDSTATUS="$?"
5050
test "$BUILDSTATUS" != 255 || BUILDSTATUS=3
@@ -71,7 +71,7 @@ vm_startup_lxc_standalone() {
7171
;;
7272
esac
7373
# XXX: do this always instead of leaking the hosts' one?
74-
rm -rf "$BUILD_ROOT/etc/mtab"
74+
buildroot_rm /etc/mtab
7575
echo "rootfs / rootfs rw 0 0" > "$BUILD_ROOT/etc/mtab"
7676
lxc-destroy -n "$LXCID" >/dev/null 2>&1 || true
7777
mkdir -p "$LXCROOTFS"
@@ -94,8 +94,8 @@ vm_startup_lxc_standalone() {
9494
cleanup_and_exit 1
9595
;;
9696
esac
97-
if ! [ -r "$BUILD_ROOT/.build/_exitcode" ]; then
98-
echo "'$BUILD_ROOT/.build/_exitcode' not found"
97+
if ! [ -r "$BUILD_ROOT/.build/_exitcode" -a ! -L "$BUILD_ROOT/.build/_exitcode" ]; then
98+
echo "'$BUILD_ROOT/.build/_exitcode' not found or symlink"
9999
return 3
100100
fi
101101
exitcode=$(cat $BUILD_ROOT/.build/_exitcode)
@@ -149,15 +149,16 @@ vm_startup_lxc_libvirt() {
149149
</domain>
150150
EOF
151151
# XXX: do this always instead of leaking the hosts' one?
152+
buildroot_rm /etc/mtab
152153
echo "rootfs / rootfs rw 0 0" > $BUILD_ROOT/etc/mtab
153154
# could LOGFILE be used instead?
154155
lxcsh create --console $LXCCONF | sed -ure 's/\x0d//g;:redo /.\x08/{s/.\x08//; b redo}'
155156
exitcode="${PIPESTATUS[0]}"
156157
if [ "$exitcode" -gt 0 ]; then
157158
return $exitcode # libvirt errors
158159
fi
159-
if ! [ -r "$BUILD_ROOT/.build/_exitcode" ]; then
160-
echo "'$BUILD_ROOT/.build/_exitcode' not found"
160+
if ! [ -r "$BUILD_ROOT/.build/_exitcode" -a ! -L "$BUILD_ROOT/.build/_exitcode" ]; then
161+
echo "'$BUILD_ROOT/.build/_exitcode' not found or symlink"
161162
return 3
162163
fi
163164
exitcode=$(cat $BUILD_ROOT/.build/_exitcode)

build-vm-zvm

+6-2
Original file line numberDiff line numberDiff line change
@@ -342,8 +342,10 @@ vm_initrd_obs_modules_zvm() {
342342
current_kernel_version=$(ls lib/modules)
343343
# copy modules from kernel that is installed to the buildsystem:
344344
mkdir -p "$TEMPDIR/lib/modules/$3"
345+
assert_dir_path "lib/modules/${3}"
345346
while read module; do
346347
(cd ${BUILD_ROOT}/lib/modules/${3}; \
348+
assert_dir_path "lib/modules/${3}/${module%.xz}"
347349
rsync -a --relative $module ${TEMPDIR}/lib/modules/$3)
348350
done < <(cd $TEMPDIR/lib/modules/${current_kernel_version}; \
349351
find . -name "*.xz")
@@ -366,8 +368,7 @@ vm_fixup_zvm() {
366368
# have to copy kernel/initrd and run zipl to be able to IPL
367369
# have to set init_script before unmounting, thus doing it statically for now.
368370
zvm_init_script="/.build/build"
369-
assert_dirs boot boot/zipl
370-
mkdir -p $BUILD_ROOT/boot
371+
assert_dir_path boot/zipl
371372
mkdir -p $BUILD_ROOT/boot/zipl
372373
vm_kernel="/.build.kernel.kvm"
373374
test -e "${BUILD_ROOT}${vm_kernel}" -a ! -L "${BUILD_ROOT}${vm_kernel}" || cleanup_and_exit 1 "${vm_kernel} does not exist"
@@ -377,8 +378,11 @@ vm_fixup_zvm() {
377378
vm_initrd="${vm_initrd}-${kernel_version}"
378379
# copy initrd to build worker:
379380
echo "copy $vm_initrd to $BUILD_ROOT"
381+
rm -rf "${BUILD_ROOT}/boot/${vm_initrd}"
380382
cp -a "${vm_initrd}" "${BUILD_ROOT}/boot"
381383
# finally, install bootloader to the worker disk
384+
# XXX/TODO: does zipl read or write ${BUILD_ROOT}${vm_initrd}? Either
385+
# rm -rf the file or check for a symlink
382386
zipl -t "$BUILD_ROOT/boot/zipl" -i "${BUILD_ROOT}${vm_kernel}" \
383387
-r "${BUILD_ROOT}${vm_initrd}" \
384388
--parameters "${zvm_param} init=$zvm_init_script rootfsopts=noatime"

common_functions

+29
Original file line numberDiff line numberDiff line change
@@ -154,3 +154,32 @@ buildroot_umount() {
154154
umount -n "$BUILD_ROOT/$d" 2>/dev/null || true
155155
}
156156

157+
# rm that makes sure the file is gone
158+
buildroot_rm() {
159+
rm -rf "$BUILD_ROOT/$1"
160+
test -e "$BUILD_ROOT/$1" && cleanup_and_exit 1 "could not remove $BUILD_ROOT/$1"
161+
}
162+
163+
164+
assert_dirs() {
165+
local d rl
166+
if test -z "$1" ; then
167+
set usr sbin usr/bin usr/sbin etc .build .init_b_cache .init_b_cache/scripts .init_b_cache/rpms .preinstall_image proc proc/sys proc/sys/fs proc/sys/fs/binfmt_misc sys dev dev/pts dev/shm mnt
168+
fi
169+
for d in "$@" ; do
170+
if test -L "$BUILD_ROOT/$d" ; then
171+
rl="$(readlink "$BUILD_ROOT/$d")"
172+
test "$d" = sbin -a "x$rl" = "xusr/sbin" && continue
173+
test "$d" = sbin -a "x$rl" = "xusr/bin" && continue
174+
test "$d" = usr/sbin -a "x$rl" = "xbin" && continue
175+
cleanup_and_exit 1 "$d: illegal symlink to $rl"
176+
else
177+
test -e "$BUILD_ROOT/$d" -a ! -d "$BUILD_ROOT/$d" && cleanup_and_exit 1 "$d: not a directory"
178+
fi
179+
done
180+
}
181+
182+
assert_dir_path() {
183+
test "$1" != "${1%/*}" && assert_dir_path "${1%/*}"
184+
assert_dir "$1"
185+
}

init_buildsystem

-18
Original file line numberDiff line numberDiff line change
@@ -203,24 +203,6 @@ preinstall_image_filter() {
203203
done
204204
}
205205

206-
assert_dirs() {
207-
local d rl
208-
if test -z "$1" ; then
209-
set usr sbin usr/bin usr/sbin etc .build .init_b_cache .init_b_cache/scripts .init_b_cache/rpms .preinstall_image proc proc/sys proc/sys/fs proc/sys/fs/binfmt_misc sys dev dev/pts dev/shm mnt
210-
fi
211-
for d in "$@" ; do
212-
if test -L "$BUILD_ROOT/$d" ; then
213-
rl="$(readlink "$BUILD_ROOT/$d")"
214-
test "$d" = sbin -a "x$rl" = "xusr/sbin" && continue
215-
test "$d" = sbin -a "x$rl" = "xusr/bin" && continue
216-
test "$d" = usr/sbin -a "x$rl" = "xbin" && continue
217-
cleanup_and_exit 1 "$d: illegal symlink to $rl"
218-
else
219-
test -e "$BUILD_ROOT/$d" -a ! -d "$BUILD_ROOT/$d" && cleanup_and_exit 1 "$d: not a directory"
220-
fi
221-
done
222-
}
223-
224206
preinstall_setup() {
225207
cd "$BUILD_ROOT" || cleanup_and_exit 1
226208
rm -rf build-preinstall

0 commit comments

Comments
 (0)