# HG changeset patch # User Franz Glasner # Date 1715672814 -7200 # Node ID 5194d87e0b4b40c792f1689f135304d9179080a6 # Parent d5591ebc303def6c52412e4cea077f15a60e36c7 Move "_get_mounts_at_directory()" into common.subr diff -r d5591ebc303d -r 5194d87e0b4b sbin/ftjail --- a/sbin/ftjail Fri May 10 13:42:10 2024 +0200 +++ b/sbin/ftjail Tue May 14 09:46:54 2024 +0200 @@ -65,52 +65,6 @@ umask 0022 -#: -#: Search for mounts and sub-mounts at a given directory. -#: -#: The output is sorted by the mountpoint. -#: -#: Args: -#: $1: the directory where to start for mounts and sub-mounts -#: -#: Output (stdout): -#: The sorted list (lines) of mounts in :manpage:`fstab(5)` format. -#: This list may be empty. -#: -#: Exit: -#: 1: on fatal errors (usage et al.) -#: -#: Important: -#: The input directory **must** be an absolute path. -#: -_get_mounts_at_directory() { - local _directory - - local _fstab - - _directory=${1-} - case "${_directory}" in - */) - echo "ERROR: a trailing slash in directory name given" 1>&2; - exit 1; - ;; - /*) - : - ;; - '') - echo "ERROR: no directory given" 1>&2; - exit 1; - ;; - *) - echo "ERROR: directory must be an absolute path" 1>&2; - exit 1; - ;; - esac - _fstab="$(mount -p | awk -v pa1="^${_directory}\$" -v pa2="^${_directory}/" '($2 ~ pa1) || ($2 ~ pa2 ) { print; }' | sort -k3)" - echo "${_fstab}" -} - - # # PARENT-BASE NAME DRY-RUN # diff -r d5591ebc303d -r 5194d87e0b4b share/local-bsdtools/common.subr --- a/share/local-bsdtools/common.subr Fri May 10 13:42:10 2024 +0200 +++ b/share/local-bsdtools/common.subr Tue May 14 09:46:54 2024 +0200 @@ -184,3 +184,49 @@ return 3 } } + + +#: +#: Search for mounts and sub-mounts at a given directory. +#: +#: The output is sorted by the mountpoint. +#: +#: Args: +#: $1: the directory where to start for mounts and sub-mounts +#: +#: Output (stdout): +#: The sorted list (lines) of mounts in :manpage:`fstab(5)` format. +#: This list may be empty. +#: +#: Exit: +#: 1: on fatal errors (usage et al.) +#: +#: Important: +#: The input directory **must** be an absolute path. +#: +_get_mounts_at_directory() { + local _directory + + local _fstab + + _directory=${1-} + case "${_directory}" in + */) + echo "ERROR: a trailing slash in directory name given" 1>&2; + exit 1; + ;; + /*) + : + ;; + '') + echo "ERROR: no directory given" 1>&2; + exit 1; + ;; + *) + echo "ERROR: directory must be an absolute path" 1>&2; + exit 1; + ;; + esac + _fstab="$(mount -p | awk -v pa1="^${_directory}\$" -v pa2="^${_directory}/" '($2 ~ pa1) || ($2 ~ pa2 ) { print; }' | sort -k3)" + echo "${_fstab}" +}