workaround a bug in Bash an re-add missing debug log messages
This commit is contained in:
@@ -441,7 +441,7 @@ function return_oid() {
|
|||||||
# Main logic of the daemon.
|
# Main logic of the daemon.
|
||||||
#
|
#
|
||||||
function main() {
|
function main() {
|
||||||
local buf line cmd oid req next
|
local buf cmd oid req next
|
||||||
|
|
||||||
echo "waiting for all data gathering functions to return data" >&$LOG
|
echo "waiting for all data gathering functions to return data" >&$LOG
|
||||||
update_oid_cache true
|
update_oid_cache true
|
||||||
@@ -454,21 +454,20 @@ function main() {
|
|||||||
read -r -t 1 -u $STDIN buf
|
read -r -t 1 -u $STDIN buf
|
||||||
rc=$?
|
rc=$?
|
||||||
if (( rc == 0 )); then
|
if (( rc == 0 )); then
|
||||||
# received complete line from stdin
|
cmd+=${buf}
|
||||||
line=$buf
|
|
||||||
elif (( rc > 128 )); then
|
elif (( rc > 128 )); then
|
||||||
# read timed out, continue if no partial data received
|
# read timed out
|
||||||
[ -z "$buf" ] && continue
|
[ -z "$buf" ] && continue
|
||||||
echo "< $buf (partial line)" >&$DEBUGLOG
|
echo "< $buf (partial line)" >&$DEBUGLOG
|
||||||
line=$buf
|
cmd+=${buf}
|
||||||
# read the rest of the line
|
# to work around a bug in Bash prior to version 5.3, check if $cmd contains a complete command first before continuing reading
|
||||||
read -r -u $STDIN buf || exit 255
|
# -> bug report: https://lists.gnu.org/archive/html/bug-bash/2024-10/msg00005.html
|
||||||
line+=$buf
|
# -> bug fix: https://git.savannah.gnu.org/cgit/bash.git/diff/builtins/read.def?h=devel&id=3ed028ccec871bc8d3b198c1681374b1e37df7cd
|
||||||
|
[[ "${cmd,,}" =~ ^(ping|set|get|getnext)$ ]] || continue
|
||||||
else
|
else
|
||||||
exit 255
|
exit 255
|
||||||
fi
|
fi
|
||||||
echo "< $line" >&$DEBUGLOG
|
echo "< $cmd" >&$DEBUGLOG
|
||||||
cmd=$line
|
|
||||||
|
|
||||||
case "${cmd,,}" in
|
case "${cmd,,}" in
|
||||||
ping)
|
ping)
|
||||||
@@ -478,13 +477,16 @@ function main() {
|
|||||||
set)
|
set)
|
||||||
# we need to args here, 'oid' and 'type_and_value'
|
# we need to args here, 'oid' and 'type_and_value'
|
||||||
cmd=""
|
cmd=""
|
||||||
read -r -u $STDIN
|
read -r -u $STDIN buf
|
||||||
read -r -u $STDIN
|
echo "< $buf" >&$DEBUGLOG
|
||||||
|
read -r -u $STDIN buf
|
||||||
|
echo "< $buf" >&$DEBUGLOG
|
||||||
snmp_echo not-writable
|
snmp_echo not-writable
|
||||||
;;
|
;;
|
||||||
get)
|
get)
|
||||||
cmd=""
|
cmd=""
|
||||||
read -r -u $STDIN oid
|
read -r -u $STDIN oid
|
||||||
|
echo "< $oid" >&$DEBUGLOG
|
||||||
if [ -z "$oid" ]; then
|
if [ -z "$oid" ]; then
|
||||||
echo "received empty oid" >&2
|
echo "received empty oid" >&2
|
||||||
snmp_echo NONE
|
snmp_echo NONE
|
||||||
@@ -500,6 +502,7 @@ function main() {
|
|||||||
getnext)
|
getnext)
|
||||||
cmd=""
|
cmd=""
|
||||||
read -r -u $STDIN oid
|
read -r -u $STDIN oid
|
||||||
|
echo "< $oid" >&$DEBUGLOG
|
||||||
if [ -z "$oid" ]; then
|
if [ -z "$oid" ]; then
|
||||||
echo "received empty oid" >&2
|
echo "received empty oid" >&2
|
||||||
snmp_echo NONE
|
snmp_echo NONE
|
||||||
|
|||||||
Reference in New Issue
Block a user