comparison sbin/ftjail @ 555:2fda9ab57359

Normalize the output of _get_mounts_at_directory() to use TABs as field separators only. This is a precondition for properly handling SPACE chars in datasets and/or mountpoints. BUGS: Handling of spaces not yet done.
author Franz Glasner <fzglas.hg@dom66.de>
date Wed, 11 Sep 2024 12:34:32 +0200
parents 847ae246f3cc
children a593dce19f54
comparison
equal deleted inserted replaced
554:c8348c707928 555:2fda9ab57359
963 # Check that the first item/line is a read-only ZFS mount directly 963 # Check that the first item/line is a read-only ZFS mount directly
964 # at the given directory. This must also be its configured 964 # at the given directory. This must also be its configured
965 # mountpoint in ZFS. 965 # mountpoint in ZFS.
966 # Also check that it is a clone proper. 966 # Also check that it is a clone proper.
967 # 967 #
968 IFS=' '$'\t' read -r _root_dataset _root_mountpoint _root_type _root_options _line <<EOF4tHGCSS 968 IFS=$'\t' read -r _root_dataset _root_mountpoint _root_type _root_options _line <<EOF4tHGCSS
969 ${_dir_mounts} 969 ${_dir_mounts}
970 EOF4tHGCSS 970 EOF4tHGCSS
971 [ "${_root_mountpoint}" != "${_directory}" ] && { echo "ERROR: found root mountpoint does not match given directory" 1>&2; return 1; } 971 [ "${_root_mountpoint}" != "${_directory}" ] && { echo "ERROR: found root mountpoint does not match given directory" 1>&2; return 1; }
972 [ "${_root_type}" != "zfs" ] && { echo "ERROR: root mountpoint is not from a ZFS dataset" 1>&2; return 1; } 972 [ "${_root_type}" != "zfs" ] && { echo "ERROR: root mountpoint is not from a ZFS dataset" 1>&2; return 1; }
973 _root_readonly="$(zfs list -H -o readonly "${_root_dataset}")" 973 _root_readonly="$(zfs list -H -o readonly "${_root_dataset}")"
990 # _root_origin="$(zfs list -H -o origin "${_root_dataset}")" 990 # _root_origin="$(zfs list -H -o origin "${_root_dataset}")"
991 991
992 _u_tmpdir="$(env TMPDIR=/var/tmp mktemp -d -t ftjail_${_dir_basename})" 992 _u_tmpdir="$(env TMPDIR=/var/tmp mktemp -d -t ftjail_${_dir_basename})"
993 [ -z "${_u_tmpdir}" ] && { echo "ERROR: cannot create unique temp dir" 1>&2; return 1; } 993 [ -z "${_u_tmpdir}" ] && { echo "ERROR: cannot create unique temp dir" 1>&2; return 1; }
994 _dir_fn_fstab="${_u_tmpdir}/fstab" 994 _dir_fn_fstab="${_u_tmpdir}/fstab"
995 echo -n "${_dir_mounts}" >>"${_dir_fn_fstab}" 995 #
996 # XXX FIXME: handle spaces in device and mountpoint names: replace
997 # with a literal `\040'. Note that ${_dir_mounts} is
998 # normalized already: it uses TAB characters as field
999 # separator exclusively.
1000 #
1001 printf '%s' "${_dir_mounts}" >>"${_dir_fn_fstab}"
996 _dir_fn_tldir="${_u_tmpdir}/tldirs" 1002 _dir_fn_tldir="${_u_tmpdir}/tldirs"
997 find "${_directory}" -depth 1 -type d 2>/dev/null | sort >>"${_dir_fn_tldir}" 1003 LC_ALL=C /usr/bin/find "${_directory}" -depth 1 -type d 2>/dev/null | LC_ALL=C /usr/bin/sort >>"${_dir_fn_tldir}"
998 1004
999 # Unmount in reverse order: unmount can do it for us 1005 # Unmount in reverse order: unmount can do it for us
1000 echo "Unmounting all datasets mounted at \`${_directory}'" 1006 echo "Unmounting all datasets mounted at \`${_directory}'"
1001 /sbin/umount -a -F "${_dir_fn_fstab}" -v 1007 /sbin/umount -a -F "${_dir_fn_fstab}" -v
1002 1008