comparison sbin/fjail @ 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 9c3b1966ba91
children 0159c8453fa2
comparison
equal deleted inserted replaced
443:071f24359eef 444:84e43d1bd128
93 All commands with the exception of "populate" require ZFS as 93 All commands with the exception of "populate" require ZFS as
94 filesystem. 94 filesystem.
95 ' 95 '
96 96
97 97
98 _p_datadir="$(dirname "$0")"/../share/local-bsdtools
99 . "${_p_datadir}/common.subr"
100
101
98 # Reset to standard umask 102 # Reset to standard umask
99 umask 0022 103 umask 0022
100
101
102 _get_dataset_for_mountpoint() {
103 : 'Use `mount -t zfs -p` to determine the ZFS dataset for a given mountpoint.
104
105 '
106 local _mountpoint
107 local _ds _mount _rest
108
109 _mountpoint="$1"
110
111 mount -t zfs -p \
112 | {
113 while IFS=' '$'\t' read -r _ds _mount _rest ; do
114 if [ "$_mount" = "$_mountpoint" ]; then
115 echo "${_ds}"
116 return 0
117 fi
118 done
119 return 1
120 }
121 }
122
123
124 _get_dataset_for_varempty() {
125 : 'Allow special handling for <mountpoint>/var/empty which may be
126 mounted read-only.
127
128 '
129 local _mountpoint
130 local _ve_mount
131
132 _mountpoint="$1"
133
134 if [ "$_mountpoint" = '/' ]; then
135 _ve_mount='/var/empty'
136 else
137 _ve_mount="${_mountpoint}/var/empty"
138 fi
139
140 _get_dataset_for_mountpoint "${_ve_mount}"
141 }
142 104
143 105
144 #: 106 #:
145 #: Check whether a FreeBSD version at a given location matches the userland 107 #: Check whether a FreeBSD version at a given location matches the userland
146 #: version of the host where the current process run. 108 #: version of the host where the current process run.