bin/mktmpdir: check for filesystem mount options

As was found out by Vladimir Karpinsky (thanks for patience!),
the autochosen directory might still have too restrictive mount
options -- nodev and/or noexec.  Hopefully the diags are a bit
better and faster by now.
This commit is contained in:
Michael Shigorin 2012-01-10 16:00:56 +02:00
parent 87bfa3f65d
commit 5a1065c33e
2 changed files with 22 additions and 2 deletions

View File

@ -31,6 +31,12 @@ contemplate_dirs()
| uniq # _not_ sort -u
}
# hasher emits no meaningful errors regarding those, sigh
check_options()
{
! egrep -q "^$1 $2 .*no(dev|exec)" /proc/mounts
}
# pick existing, writeable, >256M free space dirs
# rank them wrt type: tmpfs > realfs > rootfs
choose_tmpdir() {
@ -41,6 +47,7 @@ choose_tmpdir() {
done \
| sort -unk6 \
| while read dir dev fstype size used free percent mnt; do
check_options "$dev" "$mnt" || continue
[ "$free" -gt "$MINSIZE" ] || continue
[ "$fstype" = "tmpfs" ] && { echo "2 $dir $free"; continue; }
[ "$mnt" = "/" ] && { echo "0 $dir $free"; continue; }
@ -54,12 +61,21 @@ choose_tmpdir() {
# bringing it all together
TMPDIRS="`contemplate_dirs $DIRS`"
if [ -z "$TMPDIRS" ]; then
echo "error: no suitable directories found" >&2
echo "error: no suitable directories found;" >&2
echo "please check docs, filesystem and hasher setup" >&2
echo "(mount enough tmpfs into /tmp or fix hasher-priv prefix?)" >&2
exit 1
fi
DIR="`choose_tmpdir $TMPDIRS`/`dirname "$1"`"
TEMP="`choose_tmpdir $TMPDIRS`"
if [ -z "$TEMP" ]; then
echo "error: no suitable directories found;" >&2
echo "please check hasher docs and filesystem setup" >&2
echo "(nodev and/or noexec on an otherwise suitable filesystem?)" >&2
exit 1
fi
DIR="$TEMP/`dirname "$1"`"
NAME="`basename "${1:-tmpdir}"`"
mkdir -p "$DIR" # in case $1 contains slash(es)
mktemp -d "$NAME.XXXXXXX" --tmpdir="${DIR%/.}"

View File

@ -19,6 +19,10 @@ else \
fi; )
endif
ifeq (,$(BUILDDIR))
$(error suitable BUILDDIR unavailable)
endif
# even smart caching only hurts when every build goes from scratch
NO_CACHE ?= 1