# HG changeset patch # User Franz Glasner # Date 1725480503 -7200 # Node ID 07a916bd830c273eece8d61fff9fef3044f18c73 # Parent c3db1ec91f023b05e921c8ff0d52c43415bbd5a4 common.subr: _get_jail_from_path() now works with spaces in path values. If textproc/jq is installed then spaces in jail names are allowed also. diff -r c3db1ec91f02 -r 07a916bd830c share/local-bsdtools/common.subr --- a/share/local-bsdtools/common.subr Wed Sep 04 21:53:43 2024 +0200 +++ b/share/local-bsdtools/common.subr Wed Sep 04 22:08:23 2024 +0200 @@ -299,28 +299,45 @@ #: 3: no running jail found #: _get_jail_from_path() { - local _location - - local _name _path _dying + local _location - _location="${1-}" - [ -z "${_location}" ] && { echo "ERROR: no mountpoint given" 1>&2; return 1; } + local _name _path _dying + _location="${1-}" + [ -z "${_location}" ] && { echo "ERROR: no mountpoint given" 1>&2; return 1; } - jls -d name path dying \ - | { - while IFS=' '$'\t' read -r _name _path _dying ; do - if [ "${_path}" = "${_location}" ]; then - if [ "${_dying}" != "false" ]; then - echo "Jail \`${_name}' is currently dying" 1>&2 - return 2 - fi - echo "${_name}" - return 0 - fi - done - return 3 - } + if [ -x "${JQ}" ]; then + jls --libxo=json,no-locale -d dying name path \ + | LC_ALL=C "${JQ}" -r $'.["jail-information"].jail[] | [.dying, .name, .path] | @tsv ' \ + | { # ' + while IFS=' '$'\t' read -r _dying _name _path ; do + if [ "${_path}" = "${_location}" ]; then + if [ "${_dying}" != "false" ]; then + echo "Jail \`${_name}' is currently dying" 1>&2 + return 2 + fi + echo "${_name}" + return 0 + fi + done + return 3 + } + else + jls -d name dying path \ + | { + while IFS=' '$'\t' read -r _name _dying _path ; do + if [ "${_path}" = "${_location}" ]; then + if [ "${_dying}" != "false" ]; then + echo "Jail \`${_name}' is currently dying" 1>&2 + return 2 + fi + echo "${_name}" + return 0 + fi + done + return 3 + } + fi }