From 4b96698e96185a444323322c58e8aed8ce5fc7a3 Mon Sep 17 00:00:00 2001 From: "Andrew J. Hesford" Date: Sat, 7 Jan 2023 00:08:46 -0500 Subject: xchroot: mount and shell fixes - Only try to launch shells that are executable - Make bind mounts slaves to avoid back-propagating unmounts Closes: #276 [via git-merge-pr] --- xchroot | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/xchroot b/xchroot index f6d7954..bca68d8 100755 --- a/xchroot +++ b/xchroot @@ -17,21 +17,23 @@ CHROOT=$1; shift [ -d "$CHROOT/proc" ] || fail 'no /proc in chroot' [ -d "$CHROOT/sys" ] || fail 'no /sys in chroot' -mount --rbind /dev "$CHROOT/dev" -mount --rbind /proc "$CHROOT/proc" -mount --rbind /sys "$CHROOT/sys" +for _fs in dev proc sys; do + mount --rbind "/$_fs" "$CHROOT/$_fs" + mount --make-rslave "$CHROOT/$_fs" +done + touch "$CHROOT/etc/resolv.conf" mount --bind /etc/resolv.conf "$CHROOT/etc/resolv.conf" cleanup() { - umount -R "$CHROOT/dev" "$CHROOT/etc/resolv.conf" "$CHROOT/proc" "$CHROOT/sys" + umount -R "$CHROOT/dev" "$CHROOT/proc" "$CHROOT/sys" "$CHROOT/etc/resolv.conf" } trap cleanup EXIT INT -if [ -f "$CHROOT/$SHELL" ]; then +if [ -x "$CHROOT/$SHELL" ]; then INNER_SHELL="$SHELL" -elif [ -f "$CHROOT/bin/bash" ]; then +elif [ -x "$CHROOT/bin/bash" ]; then INNER_SHELL="/bin/bash" else INNER_SHELL="/bin/sh" -- cgit 1.4.1