diff --git a/addon/addon/server.tcl b/addon/addon/server.tcl index 682b52f..c1fa117 100755 --- a/addon/addon/server.tcl +++ b/addon/addon/server.tcl @@ -34,10 +34,10 @@ proc handle_connection { channelId clientAddress clientPort } { if { [file exists /proc/net/tcp6] == 1 } { puts $channelId "<<>>" - puts $channelId "[exec /usr/local/addons/check_mk_agent/timeout -s 1 10 cat /proc/net/tcp /proc/net/tcp6 2>/dev/null | awk { /:/ { c[$4]++; } END { for (x in c) { print x, c[x]; } } }]" + puts $channelId "[exec /usr/local/addons/check_mk_agent/timeout -s 1 -t 10 cat /proc/net/tcp /proc/net/tcp6 2>/dev/null | awk { /:/ { c[$4]++; } END { for (x in c) { print x, c[x]; } } }]" } else { puts $channelId "<<>>" - puts $channelId "[exec /usr/local/addons/check_mk_agent/timeout -s 1 10 cat /proc/net/tcp 2>/dev/null | awk { /:/ { c[$4]++; } END { for (x in c) { print x, c[x]; } } }]" + puts $channelId "[exec /usr/local/addons/check_mk_agent/timeout -s 1 -t 10 cat /proc/net/tcp 2>/dev/null | awk { /:/ { c[$4]++; } END { for (x in c) { print x, c[x]; } } }]" } puts $channelId "<<>>" @@ -67,10 +67,10 @@ proc handle_connection { channelId clientAddress clientPort } { if { [file exists /bin/stat] == 1 } { puts $channelId "<<>>" - puts $channelId [exec sh -c {sed -n '/ nfs4\? /s/[^ ]* \([^ ]*\) .*/\1/p' >>" - puts $channelId [exec sh -c {sed -n '/ cifs\? /s/[^ ]* \([^ ]*\) .*/\1/p' >>" @@ -82,12 +82,12 @@ proc handle_connection { channelId clientAddress clientPort } { if { [file exists /usr/bin/ntpq] == 1 } { puts $channelId "<<>>" - puts $channelId "[exec /usr/local/addons/check_mk_agent/timeout 5 /usr/bin/ntpq -np | sed -e 1,2d -e {s/^\(.\)/\1 /} -e {s/^ /%/}]" + puts $channelId "[exec /usr/local/addons/check_mk_agent/timeout -t 5 /usr/bin/ntpq -np | sed -e 1,2d -e {s/^\(.\)/\1 /} -e {s/^ /%/}]" } if { [file exists /usr/bin/chronyc] == 1 } { puts $channelId "<<>>" - puts $channelId "[exec /usr/local/addons/check_mk_agent/timeout 5 /usr/bin/chronyc -n tracking]" + puts $channelId "[exec /usr/local/addons/check_mk_agent/timeout -t 5 /usr/bin/chronyc -n tracking]" } puts $channelId "<<>>" diff --git a/addon/addon/timeout b/addon/addon/timeout new file mode 100755 index 0000000..67a8869 --- /dev/null +++ b/addon/addon/timeout @@ -0,0 +1,53 @@ +#!/bin/sh +# +# wrapper script to either directly call /usr/bin/timeout or to simply +# call an own shell-based implementation. This script is CCU2, CCU3 and +# RaspberryMatic compatible. +# +# Copyright (c) 2019 Jens Maus +# Apache 2.0 License applies. +# + +# if a BusyBox timeout command is already present we use that +# one. Instead we use shell functionality to replicate the same +# functionality in terminating commands after a certain amount +# of time. +if [[ -n "$(type -p timeout 2>&1)" ]]; then + timeout "$@" + exit $? +else + # default values + maxtime=10 + signal=SIGTERM + + # Options + O=$(getopt -- :t:s: "$@") || exit 1 + eval set -- "${O}" + while true; do + case "${1}" in + -t) maxtime=${2}; shift 2;; + -s) signal=${2}; shift 2;; + --) shift; break;; + *) exit 1;; + esac + done + + # lets sleep first + sleep "${maxtime}" & + SPID=${!} + + # execute the actual command + ("$@"; RETVAL=$?; kill ${SPID}; exit ${RETVAL}) & + CPID=${!} + wait %1 + SLEEPRETVAL=$? + if [[ ${SLEEPRETVAL} -eq 0 ]] && kill -${signal} ${CPID} >/dev/null 2>&1 ; then + RETVAL=143 + #(sleep 1; kill -9 ${CPID} >/dev/null 2>&1)& + wait %2 + else + wait %2 + RETVAL=$? + fi + exit $RETVAL +fi diff --git a/addon/addon/timeout-ccu2 b/addon/addon/timeout-ccu2 deleted file mode 100755 index 2c3afe2..0000000 Binary files a/addon/addon/timeout-ccu2 and /dev/null differ diff --git a/addon/addon/timeout-ccu3 b/addon/addon/timeout-ccu3 deleted file mode 100755 index 8502339..0000000 Binary files a/addon/addon/timeout-ccu3 and /dev/null differ diff --git a/addon/rc.d/check_mk_agent b/addon/rc.d/check_mk_agent index 3d2ab2d..9db6fff 100755 --- a/addon/rc.d/check_mk_agent +++ b/addon/rc.d/check_mk_agent @@ -8,12 +8,6 @@ RCDDIR=/usr/local/etc/config/rc.d case "$1" in ""|start) - rm -f /usr/local/addons/${ADDONNAME}/timeout 2>/dev/null - if [ "$(uname -m)" == "armv5tejl" ]; then - ln -s /usr/local/addons/${ADDONNAME}/timeout-ccu2 /usr/local/addons/${ADDONNAME}/timeout - else - ln -s /usr/local/addons/${ADDONNAME}/timeout-ccu3 /usr/local/addons/${ADDONNAME}/timeout - fi tclsh $ADDONDIR/server.tcl & ;;