Merge pull request 'fix: stdbuf cannot exec shell functions — buffer inside decode_stream [#355]' (#1) from fix/stdbuf-function-pipeline into main

This commit was merged in pull request #1.
This commit is contained in:
2026-09-03 02:54:59 +00:00
+5 -2
View File
@@ -61,7 +61,10 @@ usage() {
# behavior); Enter on an empty buffer emits nothing (defensive fix).
# ---------------------------------------------------------------------------
decode_stream() { # decode_stream <width> — od -t u1 records on stdin -> IDs
awk -v w="$1" '
# stdbuf exec's binaries only — it can NEVER wrap this function, so
# line-buffering happens here inside (piped awk block-buffers otherwise).
# shellcheck disable=SC2016 # awk program is single-quoted by design; '"$SELF"' re-opens quotes deliberately
stdbuf -oL awk -v w="$1" '
{
if (NF != w) { next }
ti = w - 7; ci = w - 5; vi = w - 3
@@ -143,7 +146,7 @@ stream_device() {
log "listening on $dev (record width $WIDTH)"
# stdbuf: od/awk block-buffer when piped; scans must not lag behind
stdbuf -oL od -v -A n -t u1 -w"$WIDTH" "$dev" 2>/dev/null \
| stdbuf -oL decode_stream "$WIDTH" \
| decode_stream "$WIDTH" \
| while read -r bid; do
process_scan "$bid"
done