diff --git a/bin/jchroot b/bin/jchroot index 83dc10f..2ed810f 100755 --- a/bin/jchroot +++ b/bin/jchroot @@ -52,6 +52,8 @@ chroot_setup() { chroot_add_mount tmp "$1/tmp" -t tmpfs -o mode=1777,atime,nodev,nosuid && mkdir -p "$1/$HOME" && chroot_add_mount $HOME "$1/$HOME" --bind + + mkdir -p "$1/run/lock" } chroot_teardown() { diff --git a/lib/core.sh b/lib/core.sh index af2989b..e2295c1 100644 --- a/lib/core.sh +++ b/lib/core.sh @@ -88,7 +88,7 @@ ID="id -u" # List of executables that are run in the host OS: PROOT_COMPAT="${JUNEST_HOME}/opt/proot/proot-${ARCH}" CHROOT=${JUNEST_BASE}/bin/jchroot -CLASSIC_CHROOT=${JUNEST_HOME}/usr/bin/chroot +CLASSIC_CHROOT="chroot" WGET="wget --no-check-certificate" CURL="curl -L -J -O -k" TAR=tar @@ -122,7 +122,7 @@ function download_cmd(){ } function chroot_cmd(){ - $CHROOT $@ || chroot $@ || $LD_EXEC ${JUNEST_HOME}/usr/bin/chroot $@ + $CHROOT "$@" || $CLASSIC_CHROOT "$@" || $LD_EXEC ${JUNEST_HOME}/usr/bin/chroot "$@" } ################################# MAIN FUNCTIONS ############################## @@ -187,32 +187,20 @@ function setup_env_from_file(){ builtin cd $ORIGIN_WD } - function run_env_as_root(){ local uid=$UID [ -z $SUDO_UID ] || uid=$SUDO_UID:$SUDO_GID local main_cmd="${SH[@]}" [ "$1" != "" ] && main_cmd="$(insert_quotes_on_spaces "$@")" - local cmd="mkdir -p ${JUNEST_HOME}/${HOME} && mkdir -p /run/lock && ${main_cmd}" trap - QUIT EXIT ABRT KILL TERM INT trap "[ -z $uid ] || chown_cmd -R ${uid} ${JUNEST_HOME}; rm_cmd -r ${JUNEST_HOME}/etc/mtab" EXIT QUIT ABRT KILL TERM INT [ ! -e ${JUNEST_HOME}/etc/mtab ] && ln_cmd -s /proc/self/mounts ${JUNEST_HOME}/etc/mtab - if ${CHROOT} $JUNEST_HOME ${TRUE} 1> /dev/null - then - JUNEST_ENV=1 ${CHROOT} $JUNEST_HOME "${SH[@]}" "-c" "${cmd}" - local ret=$? - elif ${CLASSIC_CHROOT} $JUNEST_HOME ${TRUE} 1> /dev/null - then - warn "Warning: The executable arch-chroot does not work, falling back to classic chroot" - JUNEST_ENV=1 ${CLASSIC_CHROOT} $JUNEST_HOME "${SH[@]}" "-c" "${cmd}" - local ret=$? - else - die "Error: Chroot does not work" - fi + JUNEST_ENV=1 chroot_cmd "$JUNEST_HOME" "${SH[@]}" "-c" "${main_cmd}" + local ret=$? # The ownership of the files is assigned to the real user [ -z $uid ] || chown_cmd -R ${uid} ${JUNEST_HOME} diff --git a/tests/test_core.sh b/tests/test_core.sh index 84ed818..7c3e45f 100755 --- a/tests/test_core.sh +++ b/tests/test_core.sh @@ -218,6 +218,23 @@ function test_run_env_as_classic_root(){ assertEquals 0 $? } +function test_run_env_as_junest_root(){ + [ $SKIP_ROOT_TESTS -eq 1 ] && return + + install_mini_env + CHROOT="sudo unknowncommand" + CLASSIC_CHROOT="sudo unknowncommand" + LD_EXEC="sudo $LD_EXEC" + CHOWN="sudo $CHOWN" + + local output=$(run_env_as_root pwd 2> /dev/null) + assertEquals "/" "$output" + run_env_as_root [ -e /run/lock ] 2> /dev/null + assertEquals 0 $? + run_env_as_root [ -e $HOME ] 2> /dev/null + assertEquals 0 $? +} + function test_run_env_as_user(){ install_mini_env local output=$(run_env_as_user "-k 3.10" "/usr/bin/mkdir" "-v" "/newdir2" | awk -F: '{print $1}')