changeset 444:84e43d1bd128

Move "_get_dataset_for_mountpoint()" and "_get_dataset_for_varempty()" into common.subr
author Franz Glasner <fzglas.hg@dom66.de>
date Mon, 06 May 2024 09:14:41 +0200
parents 071f24359eef
children 0159c8453fa2
files sbin/fjail sbin/ftjail share/local-bsdtools/common.subr
diffstat 3 files changed, 47 insertions(+), 65 deletions(-) [+]
line wrap: on
line diff
--- a/sbin/fjail	Fri May 03 09:41:38 2024 +0200
+++ b/sbin/fjail	Mon May 06 09:14:41 2024 +0200
@@ -95,50 +95,12 @@
 '
 
 
-# Reset to standard umask
-umask 0022
+_p_datadir="$(dirname "$0")"/../share/local-bsdtools
+. "${_p_datadir}/common.subr"
 
 
-_get_dataset_for_mountpoint() {
-    : 'Use `mount -t zfs -p` to determine the ZFS dataset for a given mountpoint.
-
-    '
-    local _mountpoint
-    local _ds _mount _rest
-
-    _mountpoint="$1"
-
-    mount -t zfs -p \
-    | {
-        while IFS=' '$'\t' read -r _ds _mount _rest ; do
-            if [ "$_mount" = "$_mountpoint" ]; then
-                echo "${_ds}"
-                return 0
-            fi
-        done
-        return 1
-    }
-}
-
-
-_get_dataset_for_varempty() {
-    : 'Allow special handling for <mountpoint>/var/empty which may be
-    mounted read-only.
-
-    '
-    local _mountpoint
-    local _ve_mount
-
-    _mountpoint="$1"
-
-    if [ "$_mountpoint" = '/' ]; then
-        _ve_mount='/var/empty'
-    else
-        _ve_mount="${_mountpoint}/var/empty"
-    fi
-
-    _get_dataset_for_mountpoint "${_ve_mount}"
-}
+# Reset to standard umask
+umask 0022
 
 
 #:
--- a/sbin/ftjail	Fri May 03 09:41:38 2024 +0200
+++ b/sbin/ftjail	Mon May 06 09:14:41 2024 +0200
@@ -65,29 +65,6 @@
 umask 0022
 
 
-_get_dataset_for_mountpoint() {
-    : 'Use `mount -t zfs -p` to determine the ZFS dataset for a given mountpoint.
-
-    '
-    local _mountpoint
-
-    local _ds _mount _rest
-
-    _mountpoint="$1"
-
-    mount -t zfs -p \
-    | {
-        while IFS=' '$'\t' read -r _ds _mount _rest ; do
-            if [ "$_mount" = "$_mountpoint" ]; then
-                echo "${_ds}"
-                return 0
-            fi
-        done
-        return 1
-    }
-}
-
-
 #:
 #: Search for a running jail where it's "path" points to a given location
 #:
--- a/share/local-bsdtools/common.subr	Fri May 03 09:41:38 2024 +0200
+++ b/share/local-bsdtools/common.subr	Mon May 06 09:14:41 2024 +0200
@@ -72,3 +72,46 @@
     done
     echo "${_res}"
 }
+
+
+_get_dataset_for_mountpoint() {
+    : 'Use `mount -t zfs -p` to determine the ZFS dataset for a given mountpoint.
+
+    '
+    local _mountpoint
+
+    local _ds _mount _rest
+
+    _mountpoint="$1"
+
+    mount -t zfs -p \
+    | {
+        while IFS=' '$'\t' read -r _ds _mount _rest ; do
+            if [ "$_mount" = "$_mountpoint" ]; then
+                echo "${_ds}"
+                return 0
+            fi
+        done
+        return 1
+    }
+}
+
+
+_get_dataset_for_varempty() {
+    : 'Allow special handling for <mountpoint>/var/empty which may be
+    mounted read-only.
+
+    '
+    local _mountpoint
+    local _ve_mount
+
+    _mountpoint="$1"
+
+    if [ "$_mountpoint" = '/' ]; then
+        _ve_mount='/var/empty'
+    else
+        _ve_mount="${_mountpoint}/var/empty"
+    fi
+
+    _get_dataset_for_mountpoint "${_ve_mount}"
+}