mirror of
https://github.com/fsquillace/junest.git
synced 2026-01-23 02:34:30 +00:00
Replace mountpoint command by checking mounts file
`mountpoint` does not detect some directory. By checking directly from `/proc/self/mounts` groot can be more reliable and portable.
This commit is contained in:
parent
137788a98a
commit
bd0e9fbbcc
3 changed files with 42 additions and 50 deletions
14
bin/groot
14
bin/groot
|
|
@ -16,7 +16,6 @@ CHROOTCMD=${CHROOTCMD:-chroot}
|
|||
SHELL="/bin/sh"
|
||||
MOUNT=mount
|
||||
UMOUNT=umount
|
||||
MOUNTPOINT=mountpoint
|
||||
MKDIR=mkdir
|
||||
TOUCH=touch
|
||||
CUT=cut
|
||||
|
|
@ -35,6 +34,15 @@ source "${JUNEST_BASE}/lib/utils/utils.sh"
|
|||
|
||||
################################ MAIN FUNCTIONS ###########################
|
||||
|
||||
function is_mountpoint() {
|
||||
local mountpoint="$1"
|
||||
for mp in $($CAT $MOUNTS_FILE | $CUT -f2 -d' ' | $SORT -r | $UNIQ)
|
||||
do
|
||||
[[ $mp == $mountpoint ]] && return 0
|
||||
done
|
||||
return 1
|
||||
}
|
||||
|
||||
function chroot_teardown() {
|
||||
# Remove all mounts starting from the most nested ones.
|
||||
# Suffix the CHROOTDIR with / to avoid umounting directories not belonging
|
||||
|
|
@ -43,7 +51,7 @@ function chroot_teardown() {
|
|||
local final_res=0
|
||||
for mp in $($CAT $MOUNTS_FILE | $CUT -f2 -d' ' | $SORT -r | $UNIQ)
|
||||
do
|
||||
if [[ $mp =~ ^${normalized_chrootdir}.* ]] && $MOUNTPOINT -q "$mp"
|
||||
if [[ $mp =~ ^${normalized_chrootdir}.* ]] && is_mountpoint "$mp"
|
||||
then
|
||||
$UMOUNT $mp || final_res=$?
|
||||
fi
|
||||
|
|
@ -66,7 +74,7 @@ function chroot_maybe_add_mount() {
|
|||
function chroot_setup() {
|
||||
$OPT_NO_UMOUNT || check_and_trap 'chroot_teardown' QUIT EXIT ABRT KILL TERM INT
|
||||
|
||||
if ! chroot_maybe_add_mount "! $MOUNTPOINT -q '$CHROOTDIR'" --bind "$CHROOTDIR" "$CHROOTDIR"
|
||||
if ! chroot_maybe_add_mount "! is_mountpoint '$CHROOTDIR'" --bind "$CHROOTDIR" "$CHROOTDIR"
|
||||
then
|
||||
warn "Failed mount of directories. $CHROOTDIR is already a mountpoint. Skipping it..."
|
||||
return 0
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue