etc/functions: Fix SINK_LOG blank lines, add more dev doc

Add examples for capturing stderr or both stdout+stderr.

Trace blank lines with LOG like non-blank lines.

Signed-off-by: Jonathon Hall <jonathon.hall@puri.sm>
Signed-off-by: Thierry Laurion <insurgo@riseup.net>
This commit is contained in:
Jonathon Hall 2024-12-20 16:54:06 -05:00 committed by Thierry Laurion
parent 283553956f
commit 516f7b6924
No known key found for this signature in database
GPG Key ID: 9A53E1BB3FF00461

View File

@ -402,6 +402,15 @@ mask_param() {
#
# For example:
# ls /boot/vmlinux* | SINK_LOG "/boot kernels"
#
# To capture stderr:
# cryptsetup open /dev/sda1 media-crypt 2> >(SINK_LOG "LUKS unlock sda1 errors")
# (Note: the space between '>' is necessary in '2> >(SINK_LOG ...)')
#
# To capture both:
# tpm reset > >(SINK_LOG "tpm reset") 2>&1
# (Note: 2>&1 must follow the stdout redirection, and space between '>' is
# necessary)
SINK_LOG() {
local name="$1"
local line haveblank
@ -413,7 +422,7 @@ SINK_LOG() {
cat
echo
) | while IFS= read -r line; do
[[ -n "$haveblank" ]] && DEBUG "$name: " # Emit buffered blank line
[[ -n "$haveblank" ]] && LOG "$name: " # Emit buffered blank line
if [[ -z "$line" ]]; then
haveblank=y
else