From add8e44e4f15f56650b0848b508ec0980160adaf Mon Sep 17 00:00:00 2001 From: Thomas Oettli Date: Fri, 1 Nov 2024 20:24:14 +0100 Subject: [PATCH] validate reception of ENDOFDATA from data gathering functions --- snmpd-oid-daemon.sh | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/snmpd-oid-daemon.sh b/snmpd-oid-daemon.sh index 97c885e..f72506f 100755 --- a/snmpd-oid-daemon.sh +++ b/snmpd-oid-daemon.sh @@ -575,9 +575,21 @@ while :; do ((next_update+=delay)) timetable[$func]=$next_update $first_run && echo "starting $func (refresh every $delay seconds)" >&$LOG - echo "executing $func, scheduled next refresh at $(date -d @$next_update)" >&$DEBUGLOG - # execute data gathering function and pipe its output to main - $func >&$DATAIN + echo "gathering: executing $func" + data=$($func) + rc=$? + echo "gathering: $func exited (rc=$rc), schedule next refresh at $(date -d @$next_update)" >&$DEBUGLOG + # pipe gathered data to main + while read -r line; do + echo "gathering: received: $line" + last_line=$line + done <<< "$data" + if [ "$last_line" != "ENDOFDATA" ]; then + echo "gathering: $func did not return ENDOFDATA, skipping data" >&2 + continue + fi + echo "gathering: sending data update to main" + echo "$data" >&$DATAIN fi done