# This software is distributed under the 2-Clause BSD License.
# ==============================================================================
+FS_UNMOUNT_RETIAL_MAXNUM=5 # Number of retrial of unmounting
+FS_UNMOUNT_RETIAL_WAIT=3 # Wait seconds in retrial of unmounting
+
# ============= Check the safety of the base directory of builder chroot environment =============
fs_chk_safety_basedir ()
{
message_echo "Unmounting the file systems for builder chroot."
fs_gen_fstab
umount -F "${DBDIR}/fstab" -af 2> /dev/null || :
- if ! fs_chk_unmount "$systembase"
+ itrial=${FS_UNMOUNT_RETIAL_MAXNUM}
+ while [ $itrial -gt 0 ]
+ do
+ fs_chk_unmount "$systembase" && break
+ message_echo "(Retrying to unmount the file systems...)" >&2
+ sleep ${FS_UNMOUNT_RETIAL_WAIT}
+ umount -F "${DBDIR}/fstab" -af 2> /dev/null || :
+ itrial=$(($itrial-1))
+ done
+ if [ $itrial -eq 0 ]
then
message_echo "WARNING: Failed to unmount the file systems. Some of them remain mounted." >&2
return 1
{
local mountpoint basedir mountpoint_real
mountpoint=$1
- [ -e "$mountpoint" ] || return
fs_inspect_fs_privilege
basedir=`cat "${TMPDIR}"/fs_privilege/basedir 2> /dev/null || :`
- mountpoint_real=`realpath "$mountpoint"`
+ if [ -e "$mountpoint" ]
+ then
+ mountpoint_real=`realpath "$mountpoint"`
+ else
+ curdir=$mountpoint
+ curnode=$mountpoint
+ relative=
+ while { curbase=`basename "$curdir"`; curdir=`dirname "$curdir"`; [ -n "$curdir" ]; }
+ do
+ relative=$curbase/$relative
+ if [ -e "$curdir" ]
+ then
+ mountpoint_real=`realpath "$curdir"`/$relative
+ break
+ fi
+ done
+ fi
mountpoint_real_full=`str_regularize_df_path "$basedir/$mountpoint_real"`
str_escape_regexp "$mountpoint_real_full"
}