# cleanup_and_exit
#
cleanup_and_exit () {
+ trap EXIT
test -z "$1" && set 0
if test -n "$RUNNING_IN_XEN" ; then
cd /
exit $1
}
+fail_exit()
+{
+ cleanup_and_exit 1
+}
+
shellquote()
{
for arg; do
fi
}
+#### main ####
+
+trap fail_exit EXIT
+
shopt -s nullglob
if detect_xen_2nd_stage ; then
if test -z "$VM_IMAGE" ; then
if ! $BUILD_DIR/killchroot -s 9 $BUILD_ROOT ; then
echo "could not kill build in $BUILD_ROOT"
- exit 1
+ cleanup_and_exit 1
fi
else
XENID="${VM_IMAGE%/root}"
if xm list "build:$XENID" >/dev/null 2>&1 ; then
if ! xm destroy "build:$XENID" ; then
echo "could not kill xen build $XENID"
- exit 1
+ cleanup_and_exit 1
fi
fi
fi
- exit 0
+ cleanup_and_exit 0
fi
if [ -z "$RPMLIST" ]; then
if test -n "$LIST_STATE" ; then
BUILD_ROOT=`mktemp -d /var/tmp/build-list-state-XXXXXX`
- test -d "$BUILD_ROOT" || exit 1
+ test -d "$BUILD_ROOT" || cleanup_and_exit 1
SPECFILE=$SPECFILES # only one specified anyways
if test "$SPECFILE" != "${SPECFILE%.src.rpm}" ; then
rm -rf $BUILD_ROOT/usr/src/packages
BUILDSTATUS=`dd if="$XENSWAP" bs=12 count=1 2>/dev/null`
case $BUILDSTATUS in
BUILDSTATUS[0-9])
- exit ${BUILDSTATUS#BUILDSTATUS}
+ cleanup_and_exit ${BUILDSTATUS#BUILDSTATUS}
;;
esac
- exit 1
+ cleanup_and_exit 1
fi
- exit 0
+ cleanup_and_exit 0
fi
if test "$DO_INIT" = true ; then
#
function cleanup_and_exit {
+ trap EXIT
[ "$BUILD_ROOT" != / ] || chown $browner $BUILD_ROOT
# umount so init_buildsystem can be used standalone
# XXX: use stat -f /dev/pts/ -c %T to check whether it's mounted and not suppress errors then?
fi
}
+fail_exit()
+{
+ cleanup_and_exit 1
+}
+
+trap fail_exit EXIT
+
if [ "$BUILD_ROOT" = / ]; then
read dummy dummy browner dummy < <(ls -ld /)
fi
echo "${SRC##*/}"
done < $BUILD_ROOT/.init_b_cache/rpmlist
rm -rf $BUILD_ROOT/.init_b_cache
- exit 0
+ cleanup_and_exit 0
fi
PACKAGES_TO_INSTALL=
echo "PACKAGES_TO_RUNSCRIPTS='${PACKAGES_TO_RUNSCRIPTS//"'"/$Q}'" >> $BUILD_ROOT/.build/init_buildsystem.data
echo "PSUF='$PSUF'" >> $BUILD_ROOT/.build/init_buildsystem.data
rm -f $BUILD_IS_RUNNING
- exit 0
+ cleanup_and_exit 0
fi
mkdir -p $BUILD_ROOT/proc