mirror of
https://github.com/fsquillace/junest.git
synced 2026-01-23 02:34:30 +00:00
Groot: Do not umount directories that are not mountpoint
This commit is contained in:
parent
b9e34d3e96
commit
137788a98a
2 changed files with 41 additions and 7 deletions
|
|
@ -43,7 +43,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}.* ]]
|
||||
if [[ $mp =~ ^${normalized_chrootdir}.* ]] && $MOUNTPOINT -q "$mp"
|
||||
then
|
||||
$UMOUNT $mp || final_res=$?
|
||||
fi
|
||||
|
|
|
|||
|
|
@ -41,6 +41,9 @@ function init_mocks() {
|
|||
# As default suppose the mountpoint does not exist
|
||||
return 1
|
||||
}
|
||||
function mountpoint_mock() {
|
||||
echo "mountpoint($@)"
|
||||
}
|
||||
function mount() {
|
||||
echo "mount($@)"
|
||||
}
|
||||
|
|
@ -74,9 +77,6 @@ function test_groot_no_directory(){
|
|||
assertCommandFailOnStatus $NOT_EXISTING_FILE main no-directory
|
||||
}
|
||||
function test_groot_mountpoint_exist(){
|
||||
mountpoint_mock() {
|
||||
echo "mountpoint($@)"
|
||||
}
|
||||
MOUNTPOINT=mountpoint_mock
|
||||
assertCommandSuccess main chrootdir
|
||||
assertEquals "$(echo -e "check_and_trap(chroot_teardown QUIT EXIT ABRT KILL TERM INT)\nmountpoint(-q chrootdir)\nchroot(chrootdir)")" "$(cat $STDOUTF)"
|
||||
|
|
@ -138,17 +138,23 @@ function test_groot_with_bind_no_umount(){
|
|||
assertEquals "$(echo -e "mountpoint(-q chrootdir)\nmount(--bind chrootdir chrootdir)\nchroot(chrootdir)")" "$(cat $STDOUTF)"
|
||||
}
|
||||
function test_groot_with_chroot_teardown(){
|
||||
MOUNTPOINT=mountpoint_mock
|
||||
echo -e "1 /home/mychroot/dev\n1 /home/mychroot/proc/fs1\n1 /home/mychroot\n1 /home/mychroot-no/dev\n1 /home/mychroot/dev/shm\n1 /home/mychroot/proc\n" > ./mounts
|
||||
MOUNTS_FILE=./mounts
|
||||
CHROOTDIR=/home/mychroot assertCommandSuccess chroot_teardown
|
||||
assertEquals "$(echo -e "umount(/home/mychroot/proc/fs1)
|
||||
assertEquals "$(echo -e "mountpoint(-q /home/mychroot/proc/fs1)
|
||||
umount(/home/mychroot/proc/fs1)
|
||||
mountpoint(-q /home/mychroot/proc)
|
||||
umount(/home/mychroot/proc)
|
||||
mountpoint(-q /home/mychroot/dev/shm)
|
||||
umount(/home/mychroot/dev/shm)
|
||||
mountpoint(-q /home/mychroot/dev)
|
||||
umount(/home/mychroot/dev)
|
||||
umount(/home/mychroot)")" "$(cat $STDOUTF)"
|
||||
}
|
||||
|
||||
function test_groot_with_chroot_teardown_umount_failure(){
|
||||
MOUNTPOINT=mountpoint_mock
|
||||
function umount() {
|
||||
echo "umount($@)"
|
||||
[[ "$1" == "/home/mychroot/dev/shm" ]] && return 128
|
||||
|
|
@ -158,19 +164,47 @@ function test_groot_with_chroot_teardown_umount_failure(){
|
|||
echo -e "1 /home/mychroot/dev\n1 /home/mychroot/proc/fs1\n1 /home/mychroot\n1 /home/mychroot-no/dev\n1 /home/mychroot/dev/shm\n1 /home/mychroot/proc\n" > ./mounts
|
||||
MOUNTS_FILE=./mounts
|
||||
CHROOTDIR=/home/mychroot assertCommandFailOnStatus 128 chroot_teardown
|
||||
assertEquals "$(echo -e "umount(/home/mychroot/proc/fs1)
|
||||
assertEquals "$(echo -e "mountpoint(-q /home/mychroot/proc/fs1)
|
||||
umount(/home/mychroot/proc/fs1)
|
||||
mountpoint(-q /home/mychroot/proc)
|
||||
umount(/home/mychroot/proc)
|
||||
mountpoint(-q /home/mychroot/dev/shm)
|
||||
umount(/home/mychroot/dev/shm)
|
||||
mountpoint(-q /home/mychroot/dev)
|
||||
umount(/home/mychroot/dev)
|
||||
umount(/home/mychroot)")" "$(cat $STDOUTF)"
|
||||
}
|
||||
function test_groot_with_chroot_teardown_with_trailing_slash(){
|
||||
MOUNTPOINT=mountpoint_mock
|
||||
echo -e "1 /home/mychroot/dev\n1 /home/mychroot/proc/fs1\n1 /home/mychroot\n1 /home/mychroot-no/dev\n1 /home/mychroot/dev/shm\n1 /home/mychroot/proc\n" > ./mounts
|
||||
MOUNTS_FILE=./mounts
|
||||
CHROOTDIR=/home/mychroot assertCommandSuccess chroot_teardown
|
||||
assertEquals "$(echo -e "umount(/home/mychroot/proc/fs1)
|
||||
assertEquals "$(echo -e "mountpoint(-q /home/mychroot/proc/fs1)
|
||||
umount(/home/mychroot/proc/fs1)
|
||||
mountpoint(-q /home/mychroot/proc)
|
||||
umount(/home/mychroot/proc)
|
||||
mountpoint(-q /home/mychroot/dev/shm)
|
||||
umount(/home/mychroot/dev/shm)
|
||||
mountpoint(-q /home/mychroot/dev)
|
||||
umount(/home/mychroot/dev)
|
||||
umount(/home/mychroot)")" "$(cat $STDOUTF)"
|
||||
}
|
||||
function test_groot_with_chroot_teardown_mountpoint_failure(){
|
||||
mountpoint_mock() {
|
||||
echo "mountpoint($@)"
|
||||
[[ $2 == "/home/mychroot/dev/shm" ]] && return 128
|
||||
return 0
|
||||
}
|
||||
MOUNTPOINT=mountpoint_mock
|
||||
echo -e "1 /home/mychroot/dev\n1 /home/mychroot/proc/fs1\n1 /home/mychroot\n1 /home/mychroot-no/dev\n1 /home/mychroot/dev/shm\n1 /home/mychroot/proc\n" > ./mounts
|
||||
MOUNTS_FILE=./mounts
|
||||
CHROOTDIR=/home/mychroot assertCommandSuccess chroot_teardown
|
||||
assertEquals "$(echo -e "mountpoint(-q /home/mychroot/proc/fs1)
|
||||
umount(/home/mychroot/proc/fs1)
|
||||
mountpoint(-q /home/mychroot/proc)
|
||||
umount(/home/mychroot/proc)
|
||||
mountpoint(-q /home/mychroot/dev/shm)
|
||||
mountpoint(-q /home/mychroot/dev)
|
||||
umount(/home/mychroot/dev)
|
||||
umount(/home/mychroot)")" "$(cat $STDOUTF)"
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue