Browse Source

sde-prepare-chroot: split mount/umount code out of Build-Pkg

user/amery/wip/mount
Alejandro Mery 14 years ago
parent
commit
28b71ec040
3 changed files with 169 additions and 83 deletions
  1. +165
    -0
      bin/sde-prepare-chroot
  2. +4
    -66
      scripts/Build-Pkg
  3. +0
    -17
      scripts/Build-Target

+ 165
- 0
bin/sde-prepare-chroot

@ -0,0 +1,165 @@
#!/bin/sh
# --- SDE-COPYRIGHT-NOTE-BEGIN ---
# This copyright note is auto-generated by ./scripts/Create-CopyPatch.
#
# Filename: bin/sde-prepare-chroot
# Copyright (C) 2006 - 2010 The OpenSDE Project
# Copyright (C) 2004 - 2006 The T2 SDE Project
# Copyright (C) 1998 - 2003 Clifford Wolf
#
# More information can be found in the files COPYING and README.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License. A copy of the
# GNU General Public License can be found in the file COPYING.
# --- SDE-COPYRIGHT-NOTE-END ---
#Description: Prepare sandbox for chrooted building
[ -n "$SDEROOT" ] ||
export SDEROOT=$( cd "${0%/*}/.."; pwd -P )
. "$SDEROOT/lib/libsde.in"
prepare_usage() {
local progname=$(echo ${0##*/} | tr '-' ' ')
[ $# -eq 0 ] || echo_error "$@"
cat <<-EOT
Usage: $progname [-u] [-b <sderoot>] <sandbox> ...
EOT
exit 1
}
# parse arguments
shortopts='?ub:'
longopts='help'
options=$(getopt -o "$shortopts" -l "$longopts" -- "$@")
[ $? -eq 0 ] || prepare_usage
eval set -- "$options"
chroot_mode=mount
chroot_base="$SDEROOT"
while [ $# -gt 0 ]; do
case "$1" in
--help)
check_usage
;;
-u)
chroot_mode=umount
;;
-b)
if [ -x "$2/bin/sde" ]; then
chroot_base="$(cd "$2/" && pwd -P)"
echo_info "Using $chroot_base instead of $SDEROOT"
else
prepare_usage "$2: Invalid tree."
fi
;;
--)
shift; break
;;
*)
break
esac
shift
done
x_mknod() {
[ -c "$1" -o -b "$1" ] || mknod "$@"
}
mountpoint() {
grep -q " $1 " /proc/mounts
}
chroot_mount() {
local realconf= realdown= realbase= realxroot=
local x= s= d=
[ -d dev/loop ] || mkdir -p dev/loop
x_mknod dev/null c 1 3
x_mknod dev/zero c 1 5
x_mknod dev/random c 1 8
x_mknod dev/urandom c 1 9
x_mknod dev/loop/0 b 7 0
x_mknod dev/loop/1 b 7 1
x_mknod dev/loop/2 b 7 2
x_mknod dev/loop/3 b 7 3
#_mknod dev/tty c 5 0
[ -L dev/fd ] || ln -s /proc/self/fd dev/fd
[ -r proc/mounts ] || mount -nt proc none proc
realxroot=$(pwd -P)
realconf=$(cd "$chroot_base"/config; pwd -P)
realdown=$(cd "$chroot_base"/download; pwd -P)
realbase=$(dirname $(cd "$chroot_base"/scripts; pwd -P))
for x in "loop:$realbase" "config:$realconf" "download:$realdown"; do
s="${x#*:}" d="TOOLCHAIN/${x%%:*}"
[ -d "$d" ] || mkdir -p "$d"
mountpoint "$realxroot/$d" || mount --bind "$s" "$d"
done
for x in bin etc lib doc src package architecture target; do
[ -e TOOLCHAIN/$x ] || ln -s "loop/$x" "TOOLCHAIN/$x"
done
x=${realxroot##*/}
if [ ! -e "TOOLCHAIN/build/$x" ]; then
mkdir -p "TOOLCHAIN/build"
ln -sn ../.. "TOOLCHAIN/build/$x"
fi
}
chroot_umount() {
local busy= x= y=
local realxroot=$(pwd -P)
if [ -d var/adm/logs ]; then
if ( cd var/adm/logs; fuser *.log > /dev/null 2>&1 ); then
busy=yes
fi
fi
if [ -z "$busy" ]; then
echo_info "Unmounting loop mounts ..."
for x in loop config mount; do
y=$realxroot/TOOLCHAIN/$x
if mountpoint $y; then
umount -d -f $y || umount -d -f -l $y
fi
done
y=$realxroot/proc
if mountpoint $y; then
umount -d -f $y || umount -d -f -l $y
fi
fi
}
errno=0 cmd="chroot_$chroot_mode"
for d; do
if [ -d "$d/TOOLCHAIN" ]; then
dir="$(cd "$d/" && pwd -P)"
else
dir=
fi
if [ -z "$dir" ]; then
echo_error "$d: Invalid sandbox"
errno=1
else
(set -e; cd "$dir"; "$cmd")
[ $? -eq 0 ] || errno=1
fi
done
exit $errno

+ 4
- 66
scripts/Build-Pkg

@ -152,53 +152,9 @@ builddir="$base/src.$pkg.$config.$id"
if [ "$chroot" = 1 ] ; then
"$base/bin/sde-prepare-chroot" -b "$base" "$xroot" || exit 1
cd "$xroot" || exit 1
x_mknod() {
if [ ! -c "$1" -a ! -b "$1" ]; then
mknod "$@"
fi
}
mkdir -p dev/loop
x_mknod dev/null c 1 3
x_mknod dev/zero c 1 5
x_mknod dev/random c 1 8
x_mknod dev/urandom c 1 9
x_mknod dev/loop/0 b 7 0
x_mknod dev/loop/1 b 7 1
x_mknod dev/loop/2 b 7 2
x_mknod dev/loop/3 b 7 3
#_mknod dev/tty c 5 0
if [ ! -L dev/fd ]; then
ln -s /proc/self/fd dev/fd
fi
realconf=$(cd $base/config; pwd -P)
realdown=$(cd $base/download; pwd -P)
realbase=$(dirname $(cd $base/scripts; pwd -P))
if [ ! -e TOOLCHAIN/loop/scripts ]; then
mkdir -p TOOLCHAIN/{loop,config,download}
mount --bind $realbase TOOLCHAIN/loop
mount --bind $realconf TOOLCHAIN/config
mount --bind $realdown TOOLCHAIN/download
fi
if [ ! -f proc/mounts ]; then
mount -nt proc none proc
fi
for x in $sderootdirs; do
if [ ! -e TOOLCHAIN/$x ]; then ln -s "loop/$x" "TOOLCHAIN/$x"; fi
done
if [ ! -e "TOOLCHAIN/build/$SDECFG_ID" ]; then
mkdir -p "TOOLCHAIN/build"
ln -snf ../.. "TOOLCHAIN/build/$SDECFG_ID"
fi
mkdir -p "TOOLCHAIN/src.$pkg.$config.$id"
ln -s "$PWD/TOOLCHAIN/src.$pkg.$config.$id" "$builddir"
@ -209,24 +165,10 @@ if [ "$chroot" = 1 ] ; then
cat > $builddir/debug.sh <<- EOT
#!/bin/bash
if [ ! -f "$xroot/proc/mounts" ]; then
mount -nt proc none "$xroot/proc"
fi
if [ ! -e "$xroot/TOOLCHAIN/loop/scripts" ]; then
mkdir -p "$xroot/"TOOLCHAIN/{loop,config,download}
mount --bind $realbase "$xroot/TOOLCHAIN/loop"
mount --bind $realconf "$xroot/TOOLCHAIN/config"
mount --bind $realdown "$xroot/TOOLCHAIN/download"
fi
"$base/bin/sde-prepare-chroot" -b "$base" "$xroot" || exit $?
export ROCK_THIS_IS_CHROOT=1
/usr/sbin/chroot "$xroot" /bin/bash TOOLCHAIN/src.$pkg.$config.$id/debug_x.sh
if ! fuser -s "$xroot/TOOLCHAIN/" ; then
echo "Loop mounts appear unused - un-mounting ..."
umount -l "$xroot/TOOLCHAIN/"{download,config,loop}
umount -l "$xroot/proc"
fi
EOT
chmod +x $builddir/debug.sh
@ -968,9 +910,6 @@ fi
cd $base
umount -r -d -f $builddir/* 2> /dev/null
umount -r -d -f -l $builddir/* 2> /dev/null
if [ "$SDECFG_SRC_TMPFS_LOG" = 1 -a -n "$( type -p df )" ]; then
mkdir -p $root/var/adm/sde-debug
if [ ! -f $root/var/adm/sde-debug/tmpfslog.txt ] ; then
@ -984,11 +923,9 @@ if [ "$SDECFG_SRC_TMPFS_LOG" = 1 -a -n "$( type -p df )" ]; then
expand -t20 >> $root/var/adm/sde-debug/tmpfslog.txt
fi
umount -r -d -f $builddir 2> /dev/null
umount -r -d -f -l $builddir 2> /dev/null
if [ -f $root/var/adm/logs/$stagelevel-$xpkg.log ] ; then
if [ $clear_src = 1 ] ; then
# TODO: umount if TMPFS
rm -rf $builddir/* $builddir
else
cp $root/var/adm/logs/$stagelevel-$xpkg.out $builddir/BUILD-LOG
@ -1001,6 +938,7 @@ if [ -f $root/var/adm/logs/$stagelevel-$xpkg.log ] ; then
exit 0
else
if [ $clear_src = 1 -a "$SDECFG_ALWAYS_CLEAN" = 1 ] ; then
# TODO: umount if TMPFS
rm -rf $builddir/* $builddir
else
cp $root/var/adm/logs/$stagelevel-$xpkg.out $builddir/ERROR-LOG

+ 0
- 17
scripts/Build-Target

@ -260,23 +260,6 @@ pkgloop_action() {
return $rc
}
# Try to umount any directories mounted by Build-Pkg -chroot
# if we are the last process using them.
#
umount_chroot() {
exec 201> /dev/null
if ! ( cd ${build_logs}; fuser *.log > /dev/null 2>&1 ); then
echo_status "Unmounting loop mounts ..."
umount -d -f $build_toolchain/{download,config,loop} 2> /dev/null
umount -d -f -l $build_toolchain/{download,config,loop} 2> /dev/null
umount -d -f $build_root/proc 2> /dev/null
umount -d -f -l $build_root/proc 2> /dev/null
fi
}
# must trap outside the group command
trap 'umount_chroot' EXIT
{
ln -sf build_target_$$.log ${build_logs}/build_target.log
./bin/sde-build-tools -1 -c $config

Loading…
Cancel
Save