https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=287615

--- Comment #17 from Jim Long <[email protected]> ---
With respect, if I may advocate in favor, the *output* is very intuitive.  Look
at not only the xargs output but the hexdump.  Multi-value parameters are
dumped with the *entire* multi-value tuple marked by a terminating NUL byte;
and the individual components of the tuple are separated by newlines.  I'm open
to seeing good ways to do
it, but it seems that trying to stay the "CSV" course yields to more headaches
about having to quote values that contain commas, or quote marks.  If it would
help grease
the skids for acceptance, I would gladly consider adding newline-escapes to
multi-value parameter dumps, so that multi-value variables can also be
represented unambiguously.

Using my sysutils/jail-info extension of this feature:

# cat << \EOF > /etc/jail.conf.d/test.conf:
test {
    host.hostname       = "test.example.edu";

    linux.osname = "\\Backslash\\ in OS name # pipe=>| Jim's torture test
with newlines, spaces,  unmatched       \"quotes        and     tabs.";

    interface           = 'public';

    ip4.addr            = vlan3|192.168.1.50/32;
    ip4.addr            += "private|192.168.1.95-99/32";
    ip4.addr            += "172.16.1.95/32";
    allow.raw_sockets   = 1;

    mount  = '/filesystem-a     "$path/mnt/path with spaces"    nullfs  ro     
0       0';
    mount += '/filesystem-b     $path/mnt/b                     nullfs  ro     
0       0';
    mount += '/filesystem-c     "$path/mnt/path with    tabs"                  
nullfs  ro      0       0';
    mount += '/filesystem-d     $path/mnt/d                     nullfs  ro     
0       0';
    mount += '/filesystem-e     $path/mnt/e                     nullfs  ro     
0       0';
}
EOF
# cat << \EOF > test.sh
nm='test'

unset mount
jail-info "${nm}" mount
echo
eval $(jail-info "${nm}" mount)
printf '%s\n\n' "$mount"

unset mounts
readarray -t mounts <<< "$mount"
printf '%d mounts found.\n\n' ${#mounts[@]}

for k in ${!mounts[@]}
do
  printf 'Mount #%d is:\n  %s\n\n' $((k+1)) "${mounts[k]}"
  eval set -- ${mounts[k]}
  printf '  filesystem %s (type %s) will be mounted at %s.\n\n' "$1" "$3" "$2"
done


eval ip_list="$(jail-info -n "${nm}" ip4.addr)"

unset ip_list
ip_list="$( jail-info -n "${nm}" ip4.addr interface )"
eval set -- $ip_list
interface="$2"
ip_list="$1"
printf 'data from "%s":\n\n' "jail-info -n ${nm} ip4.addr interface"
printf '$1="%s"\n\n' "$ip_list"
printf '$2="%s"\n\n' "$interface"

unset ips
#echo "$ip_list"
readarray -t ips <<< $ip_list
printf '%d ips loaded into array.\n\n' ${#ips[@]}

printf 'default interface is %s\n\n' "$interface"

for k in ${!ips[@]}
do

  printf 'IP #%d is:\n  %s\n\n' $((k+1)) "${ips[k]}"

  one_ip="${ips[k]}"
  one_if="${one_ip%%|*}"    # strip off trailing "|whatever"

# if the above didn't strip anything off, then there is no interface prefix
  [[ "$one_if" == "$one_ip" ]] && one_if="$interface"

  printf '  IP %s will be present on interface "%s".\n\n' \
    "${one_ip##*|}" "${one_if}"

done
EOF
# chmod 755 test.sh
# ./test.sh 
mount=$'/filesystem-a\t"$path/mnt/path with
spaces"\tnullfs\tro\t0\t0\n/filesystem-b\t$path/mnt/b\t\t\tnullfs\tro\t0\t0\n/filesystem-c\t"$path/mnt/path\twith\ttabs"\t\t\tnullfs\tro\t0\t0\n/filesystem-d\t$path/mnt/d\t\t\tnullfs\tro\t0\t0\n/filesystem-e\t$path/mnt/e\t\t\tnullfs\tro\t0\t0'

/filesystem-a   "$path/mnt/path with spaces"    nullfs  ro  0   0
/filesystem-b   $path/mnt/b         nullfs  ro  0   0
/filesystem-c   "$path/mnt/path with    tabs"           nullfs  ro  0   0
/filesystem-d   $path/mnt/d         nullfs  ro  0   0
/filesystem-e   $path/mnt/e         nullfs  ro  0   0

5 mounts found.

Mount #1 is:
  /filesystem-a "$path/mnt/path with spaces"    nullfs  ro  0   0

  filesystem /filesystem-a (type nullfs) will be mounted at /mnt/path with
spaces.

Mount #2 is:
  /filesystem-b $path/mnt/b         nullfs  ro  0   0

  filesystem /filesystem-b (type nullfs) will be mounted at /mnt/b.

Mount #3 is:
  /filesystem-c "$path/mnt/path with    tabs"           nullfs  ro  0   0

  filesystem /filesystem-c (type nullfs) will be mounted at /mnt/path with
tabs.

Mount #4 is:
  /filesystem-d $path/mnt/d         nullfs  ro  0   0

  filesystem /filesystem-d (type nullfs) will be mounted at /mnt/d.

Mount #5 is:
  /filesystem-e $path/mnt/e         nullfs  ro  0   0

  filesystem /filesystem-e (type nullfs) will be mounted at /mnt/e.

data from "jail-info -n test ip4.addr interface":

$1="vlan3|192.168.1.50/32
private|192.168.1.95-99/32
172.16.1.95/32"

$2="public"

3 ips loaded into array.

default interface is public

IP #1 is:
  vlan3|192.168.1.50/32

  IP 192.168.1.50/32 will be present on interface "vlan3".

IP #2 is:
  private|192.168.1.95-99/32

  IP 192.168.1.95-99/32 will be present on interface "private".

IP #3 is:
  172.16.1.95/32

  IP 172.16.1.95/32 will be present on interface "public".


This shows how jail-info can help the administrator parse the jail.conf(5)
hierarchy using NUL-terminated output from jail(8).

In a perfect world, I would have written a generalized output module, similar
to "pkg-info --raw-format=..." but I didn't have that much chutzpah. :)

-- 
You are receiving this mail because:
You are the assignee for the bug.

Reply via email to