comparison sbin/fjail @ 202:6b7a084ddf1d

Replace all calls to "zfs get" to "zfs list -o". This is to get rid of some "read" calls.
author Franz Glasner <fzglas.hg@dom66.de>
date Sun, 21 Aug 2022 12:08:59 +0200
parents 687210f46b8f
children eb95c986cc59
comparison
equal deleted inserted replaced
201:687210f46b8f 202:6b7a084ddf1d
133 # 133 #
134 command_datasets() { 134 command_datasets() {
135 # parent ZFS dataset -- child ZFS dataset name 135 # parent ZFS dataset -- child ZFS dataset name
136 local _pds _cds 136 local _pds _cds
137 # and its mount point 137 # and its mount point
138 local _pmp _get _dummy 138 local _pmp _get
139 # full name of the dataset 139 # full name of the dataset
140 local _ds 140 local _ds
141 # dynamic ZFS options -- create cache for freebsd-update -- use a more tiny layout 141 # dynamic ZFS options -- create cache for freebsd-update -- use a more tiny layout
142 local _zfsopts _fbsdupdate _tiny 142 local _zfsopts _fbsdupdate _tiny
143 143
172 _pds="$1" 172 _pds="$1"
173 if [ -z "${_pds}" ]; then 173 if [ -z "${_pds}" ]; then
174 echo "ERROR: no parent dataset given" >&2 174 echo "ERROR: no parent dataset given" >&2
175 return 2 175 return 2
176 fi 176 fi
177 _get=$(zfs get -H mountpoint "${_pds}" 2>/dev/null) || { echo "ERROR: dataset \`${_pds}' does not exist" >&2; return 1; } 177 _pmp=$(zfs list -H -o mountpoint "${_pds}" 2>/dev/null) || { echo "ERROR: dataset \`${_pds}' does not exist" >&2; return 1; }
178 IFS=$'\t' read _dummy _dummy _pmp _dummy <<EOF
179 ${_get}
180 EOF
181 case "${_pmp}" in 178 case "${_pmp}" in
182 none) 179 none)
183 echo "ERROR: dataset \`${_pds}' has no mountpoint" >&2 180 echo "ERROR: dataset \`${_pds}' has no mountpoint" >&2
184 return 1 181 return 1
185 ;; 182 ;;
196 echo "ERROR: no child dataset given" >&2 193 echo "ERROR: no child dataset given" >&2
197 return 2 194 return 2
198 fi 195 fi
199 _ds="${_pds}/${_cds}" 196 _ds="${_pds}/${_cds}"
200 echo "Resulting new root dataset is \`${_ds}' at mountpoint \`${_pmp}/${_cds}'" 197 echo "Resulting new root dataset is \`${_ds}' at mountpoint \`${_pmp}/${_cds}'"
201 if zfs get -H mountpoint "${_ds}" >/dev/null 2>/dev/null; then 198 if zfs list -H -o mountpoint "${_ds}" >/dev/null 2>/dev/null; then
202 echo "ERROR: dataset \`${_ds}' does already exist" >&2 199 echo "ERROR: dataset \`${_ds}' does already exist" >&2
203 return 1 200 return 1
204 fi 201 fi
205 202
206 # 203 #
497 # make it writeable temporarily if it is mounted read-only: 494 # make it writeable temporarily if it is mounted read-only:
498 # 495 #
499 _vestatus="" 496 _vestatus=""
500 _veds="$(_get_dataset_for_varempty "${_mp}")" 497 _veds="$(_get_dataset_for_varempty "${_mp}")"
501 if [ $? -eq 0 ]; then 498 if [ $? -eq 0 ]; then
502 _get=$(zfs get -H readonly ${_veds} 2>/dev/null) || { echo "ERROR: cannot determine readonly status of ${_mp}/var/empty" >&2; return 1; } 499 _vestatus=$(zfs list -H -o readonly ${_veds} 2>/dev/null) || { echo "ERROR: cannot determine readonly status of ${_mp}/var/empty" >&2; return 1; }
503 IFS=$'\t' read _dummy _dummy _vestatus _dummy <<EOF
504 ${_get}
505 EOF
506 if [ "${_vestatus}" = "on" ]; then 500 if [ "${_vestatus}" = "on" ]; then
507 zfs set readonly=off ${_veds} 1> /dev/null || { echo "ERROR: cannot reset readonly-status of ${_mp}/var/empty" >&2; return 1; } 501 zfs set readonly=off ${_veds} 1> /dev/null || { echo "ERROR: cannot reset readonly-status of ${_mp}/var/empty" >&2; return 1; }
508 fi 502 fi
509 fi 503 fi
510 # Set the access rights and the file flags as given in mtree 504 # Set the access rights and the file flags as given in mtree