From 2e669d86b414e365c7d91bf358642ca717676fac Mon Sep 17 00:00:00 2001 From: timwa0669 Date: Sat, 5 Oct 2024 13:24:31 +0800 Subject: [PATCH] init: separate 'mount --rbind -o rslave ...' into 'mount --rbind ...' and 'mount --make-rslave ...' On some legacy distros like Ubuntu 18.04.6, the mount executable does not support '-o rslave'. So we use '--make-rslave' instead. --- distrobox-init | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/distrobox-init b/distrobox-init index b6bc6364b3..ea22e653e9 100755 --- a/distrobox-init +++ b/distrobox-init @@ -388,12 +388,18 @@ mount_bind() fi # Add mountflags if needed, if no are specified, use rslave as default. - if [ "${mount_flags}" = "" ]; then - mount_flags="rslave" - fi # bind mount source_dir to target_dir, return error if not successful - if ! mount --rbind -o "${mount_flags}" "${source_dir}" "${target_dir}"; then - printf "Warning: failed to bind mount %s to %s\n" "${source_dir}" "${target_dir}" + if [ "${mount_flags}" = "" ]; then + if ! mount --rbind "${source_dir}" "${target_dir}"; then + printf "Warning: failed to bind mount %s to %s\n" "${source_dir}" "${target_dir}" + return 1 + fi + if ! mount --make-rslave "${target_dir}"; then + printf "Warning: failed to make rslave to %s\n" "${target_dir}" + return 1 + fi + elif ! mount --rbind -o "${mount_flags}" "${source_dir}" "${target_dir}"; then + printf "Warning: failed to bind mount %s to %s using option %s\n" "${source_dir}" "${target_dir}" "${mount_flags}" return 1 fi