OSDN Git Service

[IMPROVED] Inside- and outside-parent jail/chroot mounting/unmounting operations...
authorMamoru Sakaue / MwGhennndo <glmwghennndo@users.sourceforge.jp>
Tue, 31 Jul 2018 13:49:35 +0000 (21:49 +0800)
committerMamoru Sakaue / MwGhennndo <glmwghennndo@users.sourceforge.jp>
Tue, 31 Jul 2018 13:49:35 +0000 (21:49 +0800)
 Changes to be committed:
modified:   bin/portsreinstall-chroot
modified:   lib/chroot-mount/libcommand.sh
modified:   lib/chroot/libcommand.sh
modified:   lib/chroot/libcommand_do.sh
modified:   lib/chroot/libdatabase_maintain.sh
modified:   lib/chroot/libfs.sh
modified:   lib/chroot/libmain.sh
modified:   lib/libfs.sh
modified:   lib/libmain.sh
modified:   man/portsreinstall.8
modified:   share/bin/portsreinstall-chroot-mount

bin/portsreinstall-chroot
lib/chroot-mount/libcommand.sh
lib/chroot/libcommand.sh
lib/chroot/libcommand_do.sh
lib/chroot/libdatabase_maintain.sh
lib/chroot/libfs.sh
lib/chroot/libmain.sh
lib/libfs.sh
lib/libmain.sh
man/portsreinstall.8
share/bin/portsreinstall-chroot-mount

index 2d0caeb..a8733f7 100755 (executable)
@@ -62,6 +62,7 @@ main_set_version
 misc_init_vardefs
 temp_trap_init
 database_maintain_reset_execflag
+fs_save_current_systembase ''
 
 # ==================================================
 # ========= PARSING OPTIONS AND ARGUMENTS ==========
index a977c20..e41d7be 100644 (file)
@@ -30,11 +30,11 @@ command_all_exec_without_pkgtools ()
        shift || :
        case $COMMAND_MODE in
        mount )
-               fs_mount "${SYSTEMBASE}"
+               fs_mount
                exit
                ;;
        unmount )
-               fs_unmount "${SYSTEMBASE}"
+               fs_unmount
                exit
                ;;
        esac
index dbe92d3..f7312fc 100644 (file)
@@ -55,6 +55,7 @@ command_all_parse_args ()
                _command_parse_args__chk_no_arg $#
                ;;
        auto )
+               COMMAND_RESTART=$COMMAND_MODE
                misc_chk_privilege
                ;;
        do | mount | unmount | enter | sync | options )
@@ -78,14 +79,12 @@ command_all_exec_before_tools_upgrade ()
                exit
                ;;
        unmount )
-               fs_terminate_if_unmount_unavailable
                fs_unmount
                exit
                ;;
        mount )
                command_do_chroot_cleanup
                fs_build_chroot
-               fs_terminate_if_mount_unavailable
                fs_mount
                temp_reset_termination_messages_common
                message_echo "Done"
@@ -94,7 +93,6 @@ command_all_exec_before_tools_upgrade ()
        enter )
                command_do_chroot_cleanup
                fs_build_chroot
-               fs_terminate_if_mount_unavailable
                fs_mount
                command_do_chroot_enter
                message_echo "Exited successfully"
@@ -104,7 +102,6 @@ command_all_exec_before_tools_upgrade ()
        sync )
                command_do_chroot_cleanup
                fs_build_chroot
-               fs_terminate_if_mount_unavailable
                fs_mount
                command_do_update_host_files
                message_echo "Done"
index daafe33..77a6bf0 100644 (file)
@@ -185,7 +185,6 @@ command_do_auto_if_incomplete ()
                until command_do_chroot_auto "$@" || ! command_do_chk_unionfs_error_at_chroot
                do
                        message_echo "INFO: Retrying by re-mounting the file systems for the builder chroot environment." >&2
-                       fs_terminate_if_unmount_unavailable
                        fs_unmount
                        fs_mount
                done
@@ -271,7 +270,6 @@ command_do_pre ()
        
        # Build and mount of the chroot environment
        fs_build_chroot
-       fs_terminate_if_mount_unavailable
        fs_mount
 }
 
index 770cae3..8664793 100644 (file)
 # ============= Destroy the builder chroot environment and clean up the temporary database =============
 database_clean_destroy ()
 {
-       local systembase
-       systembase=$1
        message_echo "Starting to clean up the builder chroot environment..."
-       fs_destroy "$systembase"
+       fs_destroy
        message_echo "Starting to clean up the temporary database..."
        command_exec_without_pkgtools__notify_reset_options
        rm -rf "${DBDIR}"
index b1e6d5d..947560e 100644 (file)
@@ -42,16 +42,68 @@ fs_safeguard_basedir ()
        exit 1
 }
 
+# ============= Save the system base observed currently =============
+fs_save_current_systembase ()
+{
+       local systembase 
+       systembase=$1
+       echo "$systembase" >  ${TMPDIR}/fs_save_current_systembase
+}
+
+# ============= Save the system base observed at the time of mounting =============
+fs_save_mounttime_systembase ()
+{
+       local systembase 
+       systembase=$1
+       echo "$systembase" >  ${DBDIR}/fs_systembase
+}
+
+# ============= Get the system base observed currently =============
+fs_get_current_systembase ()
+{
+       cat  "${TMPDIR}/fs_save_current_systembase" 2> /dev/null
+}
+
+# ============= Get the system base observed at the time of mounting =============
+# Non-zero return means no file system was attempted to mount
+fs_get_mounttime_systembase ()
+{
+       cat "${DBDIR}/fs_systembase" 2> /dev/null
+}
+
+# ============= Get the system base in the scope of accessing =============
+fs_system_base_in_mp_access ()
+{
+       fs_get_current_systembase
+}
+
+# ============= Get the system base in the scope of creating mount points =============
+fs_system_base_in_mp_creation ()
+{
+       fs_get_current_systembase
+}
+
+# ============= Get the system base in the scope of referring to mount points =============
+fs_system_base_in_mp_reference ()
+{
+       str_regularize_df_path "`fs_get_current_systembase`/`fs_get_system_basedir`"
+}
+
+# ============= Get the system base in the scope of targets =============
+# Non-zero return means no file system was attempted to mount
+fs_system_base_in_target ()
+{
+       fs_get_mounttime_systembase
+}
+
 # ============= Build the file systems for the builder chroot environment =============
 fs_build_chroot ()
 {
-       local systembase
-       systembase=$1
        [ -e "${DBDIR}/mount_manifest" ] && return
        message_echo "Building the file systems for builder chroot environment (if not yet)."
        fs_safeguard_basedir "$opt_basedir"
-       fs_unmount "$systembase" || return
-       mkdir -p "$systembase/$opt_basedir"
+       fs_unmount || return
+       mkdir -p "$opt_basedir"
        # Prescan the f file system of the original environment
        cp /dev/null "${TMPDIR}/fs_build_chroot:directories"
        (
@@ -62,30 +114,30 @@ fs_build_chroot ()
                sysdirs_ptn="^/*(`str_escape_regexp_filter < ${TMPDIR}/fs_build_chroot:sys_dirs | tr '\n' '|' | sed 's/\|$//'`)/+"
                while read directory
                do
-                       [ -e "$systembase"/$directory ] || continue
-                       if [ -L "$systembase"/$directory ]
+                       [ -e "/$directory" ] || continue
+                       if [ -L "/$directory" ]
                        then
-                               src_mountpoint_real=`realpath "$systembase"/$directory`
-                                       printf '%s\t%s\n' link $directory >> ${TMPDIR}/fs_build_chroot:directories
+                               src_mountpoint_real=`realpath "/$directory"`
+                                       printf '%s\t%s\n' link "$directory" >> ${TMPDIR}/fs_build_chroot:directories
                                if ! echo "$src_mountpoint_real/" | grep -qE "$sysdirs_ptn"
                                then
                                        printf '%s\t%s\n' real "$src_mountpoint_real" >> ${TMPDIR}/fs_build_chroot:directories
                                        tmpdir_descendant=${TMPDIR}/fs_build_chroot:descendant/$src_mountpoint_real
                                        mkdir -p "$tmpdir_descendant"
-                                       fs_get_descendant_mount_info "$systembase/$src_mountpoint_real" > $tmpdir_descendant/list
+                                       fs_get_descendant_mount_info "/$src_mountpoint_real" > $tmpdir_descendant/list
                                fi
-                       elif [ -d "$systembase"/$directory ]
+                       elif [ -d "/$directory" ]
                        then
                                printf '%s\t%s\n' real $directory >> ${TMPDIR}/fs_build_chroot:directories
                                tmpdir_descendant=${TMPDIR}/fs_build_chroot:descendant/$directory
                                mkdir -p "$tmpdir_descendant"
-                               fs_get_descendant_mount_info "$systembase/$directory" > $tmpdir_descendant/list
+                               fs_get_descendant_mount_info "/$directory" > $tmpdir_descendant/list
                        fi
                done < ${TMPDIR}/fs_build_chroot:sys_dirs
        )
        # Prepare the grand base of the chroot environment
        (
-               cd "$systembase/$opt_basedir"
+               cd "/$opt_basedir"
                for directory in builder mask store
                do
                        [ -d $directory ] || mkdir $directory
@@ -104,21 +156,21 @@ fs_build_chroot ()
        # Build target directories and the manifest for mounting
        cp /dev/null "${DBDIR}/mount_manifest.tmp"
        (
-               cd "$systembase/$opt_basedir"/builder
+               cd "/$opt_basedir"/builder
                while read srcline
                do
                        type=`echo "$srcline" | cut -f 1`
                        directory=`echo "$srcline" | cut -f 2`
                        case $type in
                        link )
-                               [ -e "$directory" -o -L "$directory" ] || cp -RpP "$systembase/$directory" .
+                               [ -e "$directory" -o -L "$directory" ] || cp -RpP "/$directory" .
                                ;;
                        real )
                                mkdir -p "./$directory"
-                               masktarget=$systembase/$opt_basedir/mask/$directory
+                               masktarget=/$opt_basedir/mask/$directory
                                mkdir -p "$masktarget"
-                               printf '%s\t%s\t%s\t%s\n' nullfs "$systembase"/$directory $directory ro >> ${DBDIR}/mount_manifest.tmp
-                               printf '%s\t%s\t%s\t%s\n' unionfs "$masktarget" $directory rw,noatime >> ${DBDIR}/mount_manifest.tmp
+                               printf '%s\t%s\t%s\t%s\n' nullfs "/$directory" "$directory" ro >> ${DBDIR}/mount_manifest.tmp
+                               printf '%s\t%s\t%s\t%s\n' unionfs "$masktarget" "$directory" rw,noatime >> ${DBDIR}/mount_manifest.tmp
                                while read srcline
                                do
                                        fs=`echo "$srcline" | cut -f 1`
@@ -135,7 +187,7 @@ fs_build_chroot ()
                                                        if  ! grep -qFx "$mpath" "${TMPDIR}/fs_build_chroot:shared_dirs:added"
                                                        then
                                                                echo "$mpath" >> ${TMPDIR}/fs_build_chroot:shared_dirs:added
-                                                               mp_share=`realpath "$systembase/$mpath"`
+                                                               mp_share=`realpath "/$mpath"`
                                                                printf '%s\t%s\t%s\t%s\n' nullfs "$mp_share" "$mpath" rw >> ${DBDIR}/mount_manifest.tmp
                                                        fi
                                                done
@@ -144,7 +196,7 @@ fs_build_chroot ()
                                        [ -e "${TMPDIR}/fs_build_chroot:shared_dirs:is_under" ] && continue
                                        case $fs in
                                                normal )
-                                                       masktarget=`str_regularize_df_path "$systembase/$opt_basedir/mask/$fullpath"`
+                                                       masktarget=`str_regularize_df_path "/$opt_basedir/mask/$fullpath"`
                                                        mkdir -p "$masktarget"
                                                        printf '%s\t%s\t%s\t%s\n' nullfs "$mp" "$fullpath" ro >> ${DBDIR}/mount_manifest.tmp
                                                        printf '%s\t%s\t%s\t%s\n' unionfs "$masktarget" "$fullpath" rw,noatime >> ${DBDIR}/mount_manifest.tmp
@@ -171,7 +223,7 @@ fs_build_chroot ()
                done < ${TMPDIR}/fs_build_chroot:directories
                grep -Ev -f "${TMPDIR}/fs_build_chroot:shared_dirs:added" "${DBDIR}/shared_dirs.lst" | while read shared_dir
                do
-                       mp_share=`realpath "$systembase$shared_dir"`
+                       mp_share=`realpath "$shared_dir"`
                        printf '%s\t%s\t%s\t%s\n' nullfs "$mp_share" "/$shared_dir" rw >> ${DBDIR}/mount_manifest.tmp
                done
                for directory in dev proc tmp 
@@ -183,18 +235,18 @@ fs_build_chroot ()
                printf '%s\t%s\t%s\t%s\n' procfs proc proc rw >> ${DBDIR}/mount_manifest.tmp
                printf '%s\t%s\t%s\t%s\n' tmpfs tmpfs tmp rw,mode=1777 >> ${DBDIR}/mount_manifest.tmp
                mkdir -p ."${PROGRAM}"
-               cd "$systembase/$opt_basedir/mask"
+               cd "/$opt_basedir/mask"
                if [ ! -e root/.cshrc ]
                then
                        tmp_cshrc=${TMPDIR}/fs_build_chroot:.cshrc
                        [ -d root ] || mkdir root
-                       if [ -e "$systembase"/root/.cshrc ]
+                       if [ -e /root/.cshrc ]
                        then
-                               cp -p "$systembase"/root/.cshrc "$tmp_cshrc"
-                               cp -p "$systembase"/root/.cshrc "root/.cshrc.bak-${APPNAME}"
-                       elif [ -e "$systembase"/usr/share/skel/dot.cshrc ]
+                               cp -p /root/.cshrc "$tmp_cshrc"
+                               cp -p /root/.cshrc "root/.cshrc.bak-${APPNAME}"
+                       elif [ -e /usr/share/skel/dot.cshrc ]
                        then
-                               cp -p "$systembase"/usr/share/skel/dot.cshrc "$tmp_cshrc"
+                               cp -p /usr/share/skel/dot.cshrc "$tmp_cshrc"
                                touch "root/.cshrc.bak-${APPNAME}"
                        else
                                cp /dev/null "$tmp_cshrc"
@@ -203,7 +255,7 @@ fs_build_chroot ()
                        echo 'set prompt="%N@[builder]%m:%~ %# "' >> $tmp_cshrc
                        mv "$tmp_cshrc" root/.cshrc
                fi
-               printf '%s\t%s\t%s\t%s\n' nullfs "$systembase/$opt_basedir"/store ".${PROGRAM}" rw >> ${DBDIR}/mount_manifest.tmp
+               printf '%s\t%s\t%s\t%s\n' nullfs "/$opt_basedir"/store ".${PROGRAM}" rw >> ${DBDIR}/mount_manifest.tmp
        )
        mv "${DBDIR}/mount_manifest.tmp" "${DBDIR}/mount_manifest"
 }
@@ -211,43 +263,57 @@ fs_build_chroot ()
 # ============= Check whether the file systems for the builder chroot environment are all mounted =============
 fs_chk_mount ()
 {
-       local systembase
-       systembase=$1
+       local systembase_target systembase_mp tmp_remains
        [ -e "${DBDIR}/mount_manifest" ] || return
-       rm -rf ${TMPDIR}/fs_chk_mount:remains
+       systembase_target=`fs_system_base_in_target` || return
+       systembase_mp=`fs_system_base_in_mp_reference`
+       tmp_remains=${TMPDIR}/fs_chk_mount:remains
+       rm -rf "$tmp_remains"
        while read srcline
        do
                type=`echo "$srcline" | cut -f 1`
                target=`echo "$srcline" | cut -f 2`
-               [ "x$type" = xnullfs -o "x$type" = xunionfs ] && target=$systembase/$target
+               [ "x$type" = xnullfs -o "x$type" = xunionfs ] && target=$systembase_target/$target
                directory=`echo "$srcline" | cut -f 3`
                opt=`echo "$srcline" | cut -f 4`
-               if ! fs_chk_mounted "$type" "$target" "$systembase/$opt_basedir/builder/$directory"
+               mp=$systembase_mp/$opt_basedir/builder/$directory
+               if ! fs_chk_mounted "$type" "$target" "$mp"
                then
-                       touch "${TMPDIR}"/fs_chk_mount:remains
-                       break
+                       printf '%s\t%s\t%s\n' "$type" "$target" "$mp" >> $tmp_remains
                fi
        done < ${DBDIR}/mount_manifest
-       [ ! -e "${TMPDIR}"/fs_chk_mount:remains ]
+       ! cat "$tmp_remains" 2> /dev/null
 }
 
 # ============= Terminate when the file systems for the builder chroot environment cannot be mounted =============
 fs_terminate_if_mount_unavailable ()
 {
-       local systembase
-       systembase=$1
-       fs_chk_mount "$systembase" && return
-       fs_chk_mount_privilege && return
+       local systembase systembase_saved
+       systembase=`fs_get_current_systembase`
+       fs_chk_mount > /dev/null && return
+       if systembase_saved=`fs_get_mounttime_systembase`
+       then
+               if [ "x$systembase" = "x$systembase_saved" ]
+               then
+                       fs_chk_mount_privilege && return
+               elif [ -n "$systembase" ]
+               then
+                       temp_terminate_process ()
+                       {
+                               message_echo "ERROR: Cannot mount because the current file systems are being mounted from inside the virtual (chroot or jail) environment."  >&2
+                               message_echo "INFO: Instead of this command, mount from inside the virtual (chroot or jail) environment."
+                       }
+                       exit 1
+               fi
+       elif fs_chk_mount_privilege
+       then
+               fs_save_mounttime_systembase "`fs_get_current_systembase`"
+               return
+       fi
        temp_terminate_process ()
        {
-               local errno basedir
-               errno=${1:-0}
+               local basedir
                [ $opt_batch_mode = yes ] && return
-               if [ $errno -ne 2 ]
-               then
-                       message_echo "Aborted by unexpected error" >&2
-                       exit
-               fi
                message_echo
                message_echo "INFO: Terminated for mounting file systems because this utility was executed at a virtual (chroot or jail) environment."
                message_echo "Execute"
@@ -274,9 +340,17 @@ fs_terminate_if_mount_unavailable ()
 # ============= Generate a custom fstab file for the builder chroot environment =============
 fs_gen_fstab ()
 {
-       local systembase
-       systembase=$1
-       [ "${DBDIR}/fstab" -nt "${DBDIR}/mount_manifest" ] && return
+       local stage systembase_target systembase_mp
+       stage=$1
+       systembase_target=`fs_system_base_in_target`
+       case $stage in
+       mount )
+               systembase_mp=`fs_system_base_in_mp_creation`
+               ;;
+       unmount )
+               systembase_mp=`fs_system_base_in_mp_reference`
+               ;;
+       esac
        fs_safeguard_basedir "$opt_basedir"
        while read srcline
        do
@@ -284,9 +358,9 @@ fs_gen_fstab ()
                target=`echo "$srcline" | cut -f 2`
                directory=`echo "$srcline" | cut -f 3`
                opt=`echo "$srcline" | cut -f 4`
-               [ "x$type" = xnullfs -o "x$type" = xunionfs ] && target=$systembase/$target
+               [ "x$type" = xnullfs -o "x$type" = xunionfs ] && target=$systembase_target/$target
                target=`str_regularize_df_path "$target"`
-               mp=`str_regularize_df_path "$systembase/$opt_basedir/builder/$directory"`
+               mp=`str_regularize_df_path "$systembase_mp/$opt_basedir/builder/$directory"`
                opt=`echo "$opt" | sed 's/[[:space:]]/\\040/g'`
                echo "$target $mp $type $opt 0 0"
        done < ${DBDIR}/mount_manifest > ${DBDIR}/fstab
@@ -295,13 +369,20 @@ fs_gen_fstab ()
 # ============= Mount the file systems for the builder chroot environment if not yet =============
 fs_mount ()
 {
-       local systembase
-       systembase=$1
+       local remining
+       if fs_chk_mount > /dev/null
+       then
+               message_echo "The builder chroot environment is already mounted."
+               return
+       fi
+       fs_terminate_if_mount_unavailable
        message_echo "Mounting the file systems for builder chroot environment."
-       fs_gen_fstab
-       if ! mount -F "${DBDIR}/fstab" -a || ! fs_chk_mount "$systembase"
+       fs_gen_fstab mount
+       if ! mount -F "${DBDIR}/fstab" -a || ! remining=`fs_chk_mount`
        then
-               message_echo "Error: Failed to mount the file systems. Some of them remain unmounted." >&2
+               message_echo "ERROR: Failed to mount the file systems. The followings remain unmounted:" >&2
+               [ $opt_batch_mode = yes ] || echo "$remining" >&2
+               cp "${DBDIR}/fstab" "${DBDIR}/fstab-mount-err"
                exit 1
        fi
        message_echo "Mounting done."
@@ -310,43 +391,50 @@ fs_mount ()
 # ============= Check whether the file systems for the builder chroot environment are all unmounted or destroyed =============
 fs_chk_unmount ()
 {
-       local systembase
-       systembase=$1
+       local systembase_target systembase_mp tmp_remains
        [ -e "${DBDIR}/mount_manifest" ] || return 0
-       rm -rf ${TMPDIR}/fs_chk_unmount:remains
+       systembase_target=`fs_system_base_in_target` || return 0
+       systembase_mp=`fs_system_base_in_mp_reference`
+       tmp_remains=${TMPDIR}/fs_chk_unmount:remains
+       rm -rf "$tmp_remains"
        tail -r "${DBDIR}/mount_manifest" | while read srcline
        do
                type=`echo "$srcline" | cut -f 1`
                target=`echo "$srcline" | cut -f 2`
-               [ "x$type" = xnullfs -o "x$type" = xunionfs ] && target=$systembase/$target
+               [ "x$type" = xnullfs -o "x$type" = xunionfs ] && target=$systembase_target/$target
                directory=`echo "$srcline" | cut -f 3`
                opt=`echo "$srcline" | cut -f 4`
-               if fs_chk_mounted "$type" "$target" "$systembase/$opt_basedir/builder/$directory"
-               then
-                       touch "${TMPDIR}"/fs_chk_unmount:remains
-                       break
-               fi
+               mp=$systembase_mp/$opt_basedir/builder/$directory
+               fs_chk_mounted "$type" "$target" "$mp" || continue
+               echo "$mp" >> $tmp_remains
        done
-       [ ! -e "${TMPDIR}"/fs_chk_unmount:remains ]
+       ! cat "$tmp_remains" 2> /dev/null
 }
 
 # ============= Terminate when the file systems for the builder chroot environment cannot be unmounted =============
 fs_terminate_if_unmount_unavailable ()
 {
-       local systembase
-       systembase=$1
-       fs_chk_unmount "$systembase" && return
-       fs_chk_unmount_privilege && return
+       local systembase systembase_saved
+       systembase=`fs_get_current_systembase`
+       systembase_saved=`fs_get_mounttime_systembase` || return 0
+       fs_chk_unmount > /dev/null && return
+       if [ "x$systembase" = "x$systembase_saved" ]
+       then
+               fs_chk_mount_privilege && return
+       elif [ -n "$systembase" ]
+       then
+               temp_terminate_process ()
+               {
+                       message_echo "ERROR: Cannot unmount because the current file systems were mounted from inside the virtual (chroot or jail) environment."  >&2
+                       message_echo "INFO: Instead of this command, unmount from inside the virtual (chroot or jail) environment."
+               }
+               exit 1
+       fi
        temp_terminate_process ()
        {
                local errno basedir
                errno=${1:-0}
                [ $opt_batch_mode = yes ] && return
-               if [ $errno -ne 3 ]
-               then
-                       message_echo "Aborted by unexpected error" >&2
-                       exit
-               fi
                message_echo
                message_echo "INFO: Terminated for unmounting file systems because this utility was executed at a virtual (chroot or jail) environment."
                message_echo "Execute"
@@ -373,17 +461,28 @@ fs_terminate_if_unmount_unavailable ()
 # ============= Unmount  file systems for the chroot environment =============
 fs_unmount ()
 {
-       local systembase
-       systembase=$1
-       [ ! -d "$systembase/$opt_basedir"/builder ] && return
-       [ -e "${DBDIR}/mount_manifest" ] || return 0
+       local systembase_access systembase_saved remining
+       systembase_access=`fs_system_base_in_mp_access`
+       ! fs_get_mounttime_systembase > /dev/null && return
+       fs_terminate_if_unmount_unavailable
+       [ ! -d "$systembase_access/$opt_basedir"/builder ] && return
+       [ ! -e "${DBDIR}/mount_manifest" ] && return
+       if fs_chk_unmount > /dev/null
+       then
+               message_echo "The builder chroot environment is already unmounted."
+               return
+       fi
        message_echo "Unmounting the file systems for builder chroot."
-       fs_gen_fstab
+       fs_gen_fstab unmount
        umount -F "${DBDIR}/fstab" -af 2> /dev/null || :
        itrial=${FS_UNMOUNT_RETIAL_MAXNUM}
        while [ $itrial -gt 0 ]
        do
-               fs_chk_unmount "$systembase" && break
+               remining=`fs_chk_unmount` && break
+               echo -n "$remining" | str_regularize_df_path_filter | while read remining_mp
+               do
+                       umount -f "$remining_mp" || :
+               done
                message_echo "(Retrying to unmount the file systems...)" >&2
                sleep ${FS_UNMOUNT_RETIAL_WAIT}
                umount -F "${DBDIR}/fstab" -af 2> /dev/null || :
@@ -394,18 +493,16 @@ fs_unmount ()
                message_echo "WARNING: Failed to unmount the file systems. Some of them remain mounted." >&2
                return 1
        fi
+       rm -f "${DBDIR}/fs_systembase"
        message_echo "Unmounting done."
 }
 
 # ============= Destroy the chroot environment =============
 fs_destroy ()
 {
-       local systembase
-       systembase=$1
        fs_chk_safety_basedir "$opt_basedir" || return 0
        [ ! -d "$opt_basedir" ] && return
-       fs_terminate_if_unmount_unavailable "$systembase"
-       fs_unmount "$systembase" || return
+       fs_unmount || return
        chflags -R noschg "$opt_basedir"
        rm -rf "$opt_basedir"
 }
index beb8383..1129bbf 100644 (file)
@@ -14,7 +14,7 @@ main_set_termination_messages_special ()
        {
                local errno
                errno=${1:-0}
-               ! fs_chk_unmount && fs_chk_mount_privilege && fs_unmount
+               ! fs_chk_unmount > /dev/null && fs_unmount
                temp_terminate_process_common "$errno"
        }
 }
index 13f6383..bf39af8 100644 (file)
@@ -127,8 +127,7 @@ fs_get_actual_mount_point_pattern ()
 {
        local mountpoint basedir mountpoint_real
        mountpoint=$1
-       fs_inspect_fs_privilege
-       basedir=`cat "${TMPDIR}"/fs_privilege/basedir 2> /dev/null || :`
+       basedir=`fs_get_system_basedir`
        if [ -e  "$mountpoint" ]
        then
                mountpoint_real=`realpath "$mountpoint"`
@@ -156,7 +155,7 @@ fs_get_descendant_mount_info ()
        local mountpoint mountpoint_real_regexp basedir
        mountpoint=$1
        mountpoint_real_regexp=`fs_get_actual_mount_point_pattern "$mountpoint"` || return
-       basedir=`cat "${TMPDIR}"/fs_privilege/basedir 2> /dev/null || :`
+       basedir=`fs_get_system_basedir`
        basedir_ptn=`str_escape_regexp "$basedir"`
        df | sed 1d | grep -E "%[[:space:]]+$mountpoint_real_regexp\/" | while read fs data
        do
@@ -206,18 +205,14 @@ fs_chk_mounted ()
        target=`str_regularize_df_path "$2"`
        mountpoint=`str_regularize_df_path "$3"`
        target_ptn=`str_escape_regexp "$target"`
-       mountpoint_real_regexp=`fs_get_actual_mount_point_pattern "$mountpoint"` || return
-       basedir=`cat "${TMPDIR}"/fs_privilege/basedir 2> /dev/null || :`
-       basedir_target_ptn=`str_regularize_df_path "$basedir/$target" | str_escape_regexp_filter`
+       mountpoint_real_regexp=`str_escape_regexp "$mountpoint"`
        tmpsrc=`df | sed 1d | grep -E "%[[:space:]]+$mountpoint_real_regexp$"`
        case $type in
                nullfs )
                        echo "$tmpsrc" | grep -qE "^${target_ptn}[[:space:]]" && return
-                       echo "$tmpsrc" | grep -qE "^${basedir_target_ptn}[[:space:]]" && return
                        ;;
                unionfs )
                        echo "$tmpsrc" | grep -qE "^<above>:${target_ptn}[[:space:]]" && return
-                       echo "$tmpsrc" | grep -qE "^<above>:${basedir_target_ptn}[[:space:]]" && return
                        ;;
                devfs | fdescfs | procfs | linprocfs | tmpfs )
                        echo "$tmpsrc" | grep -q "^$type" && return
index c30750d..51c08f7 100644 (file)
@@ -12,7 +12,7 @@ main_set_version ()
        MYVERSION=4.1.0
        COMPATIBLE_VERSIONS='^(4\.[0-1]\.[0-9])$'
        # Template for development versions
-       MYVERSION=4.0.0+toward_4.1.0_20180729205008
+       MYVERSION=4.0.0+toward_4.1.0_20180731214446
        COMPATIBLE_VERSIONS='^(4\.[0-1]\.[0-9]]|4\.[0]\.[0]+(|\+toward_4\.[0-1]\.[0-9]+_[0-9]+))$'
 }
 
index e93d5d5..93add18 100644 (file)
@@ -1111,6 +1111,8 @@ Configuration file of \fBportupgrade\fR(1).
 .PP
 [IMPROVED] It is changed to unlock in all error termination.
 .PP
+[IMPROVED] Inside- and outside-parent jail/chroot mounting/unmounting operations by \fBportsreinstall\-chroot\fR(8) and \fBportsreinstall\-chroot\-mount\fR(8) are now safely protected each other.
+.PP
 [IMPROVED] The message at the exit from \fBportsreinstall\-chroot\fR(8) builder chroot environment is modified to be less shocking.
 .PP
 [BUG FIX] \fBreset\fR command discarded the information of the initially installed packages.
index 319dd16..f5ee4a8 100755 (executable)
@@ -63,6 +63,7 @@ misc_init_vardefs
 temp_trap_init
 main_load_conf
 database_maintain_reset_execflag
+fs_save_current_systembase "${SYSTEMBASE}"
 
 # ==================================================
 # ========= PARSING OPTIONS AND ARGUMENTS ==========