diff options
author | Andrew J. Hesford <ajh@sideband.org> | 2023-01-07 00:08:46 -0500 |
---|---|---|
committer | Leah Neukirchen <leah@vuxu.org> | 2023-01-07 17:07:29 +0100 |
commit | 4b96698e96185a444323322c58e8aed8ce5fc7a3 (patch) | |
tree | 6f82b076b3df32c58929803c0bb1feaa25d29bcd | |
parent | d8b58617b9d6cb8fe51b2906ae647f86f7792d2e (diff) | |
download | xtools-4b96698e96185a444323322c58e8aed8ce5fc7a3.tar.gz xtools-4b96698e96185a444323322c58e8aed8ce5fc7a3.tar.xz xtools-4b96698e96185a444323322c58e8aed8ce5fc7a3.zip |
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]
-rwxr-xr-x | xchroot | 14 |
1 files 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" |