fix(doorman): stdbuf cannot exec shell functions — buffer inside decode_stream [#355]

Deployment rehearsal on ultix-field 2026-09-02 caught it live: the
listener showed active but decode_stream never ran (stdbuf exec's
binaries only). Line-buffering moved inside decode_stream; the od
stage keeps its own stdbuf.

Rehearsal note: https://projects.knownelement.com/issues/355
This commit is contained in:
2026-09-02 21:45:44 -05:00
parent 92956a9ae4
commit f6357418e9
+5 -2
View File
@@ -61,7 +61,10 @@ usage() {
# behavior); Enter on an empty buffer emits nothing (defensive fix). # behavior); Enter on an empty buffer emits nothing (defensive fix).
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
decode_stream() { # decode_stream <width> — od -t u1 records on stdin -> IDs 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 } if (NF != w) { next }
ti = w - 7; ci = w - 5; vi = w - 3 ti = w - 7; ci = w - 5; vi = w - 3
@@ -143,7 +146,7 @@ stream_device() {
log "listening on $dev (record width $WIDTH)" log "listening on $dev (record width $WIDTH)"
# stdbuf: od/awk block-buffer when piped; scans must not lag behind # 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 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 | while read -r bid; do
process_scan "$bid" process_scan "$bid"
done done