From bd2a2cc6a118bfee88126778b973d683e810d5f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Siglen?= Date: Thu, 10 Jul 2025 10:22:29 +0200 Subject: [PATCH] dbginfo.sh: Enhance logging on timeout triggered MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Rework command type selection and timeout trigger. Add log entry when the timeout stopps a command or a non "zero" rc happens. Reviewed-by: Mario Held Reviewed-by: Michael Storzer Signed-off-by: Jörn Siglen Signed-off-by: Jan Höppner --- scripts/dbginfo.sh | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/scripts/dbginfo.sh b/scripts/dbginfo.sh index 548f5894..096a1c00 100755 --- a/scripts/dbginfo.sh +++ b/scripts/dbginfo.sh @@ -1372,17 +1372,18 @@ call_run_command() { # extract the raw_command and set cmd_type, as some shell might split into # several lines restrict the cmd echo to the first line only local raw_cmd=$(echo "${cmd}" | head -1 | sed -ne 's/^\([^[:space:]]*\).*$/\1/p') - local cmd_type=$(type ${raw_cmd} | cut -d' ' -sf4,5) + local cmd_type=$(type -t ${raw_cmd}) echo "#######################################################" >> "${logfile}" - echo "${USER}@${SYSTEMHOSTNAME:-localhost}> ${cmd}" >> "${logfile}" + echo "${SYSTEMHOSTNAME:-localhost}> ${cmd}" >> "${logfile}" # check calling command type - if [ "X${cmd_type}" = "Xshell builtin" ]; then - # command is a builtin (no use of timeout possible) + if [ "X${cmd_type}" = "Xbuiltin" ]; then + # command is a builtin (use of timeout not possible) eval "${cmd}" >> ${logfile} 2>&1 rc=$? - elif [ "X${cmd_type}" != "Xnot found" ]; then + elif [ "X${cmd_type}" != "X" ]; then + # command was found and has a type if [ "x${TIMEOUT_OK}" = "xYES" ]; then eval timeout -k ${TOKS} ${TOS} "${cmd}" >> ${logfile} 2>&1 @@ -1393,18 +1394,23 @@ call_run_command() { rc=$? fi else - echo "${SCRIPTNAME}: Warning: Command \"${raw_cmd}\" not available" >> "${logfile}" + echo "Command \"${raw_cmd}\" not available" >> "${logfile}" echo >> "${logfile}" return 1 fi - # log a warning on rc not 0 and define return - if [ ${rc} ]; then + # add return code or new line and log a warning if rc is not 0 and define return + if [ ${rc} -eq 0 ]; then echo >> "${logfile}" return 0 + elif [ "x${TIMEOUT_OK}" = "xYES" ] && [ ${rc} -eq 124 ]; then + echo "Warning: \"${cmd}\" cancelled by timeout" + echo "-> command cancelled by timeout" >> "${logfile}" + return 1 else echo "${SCRIPTNAME}: Warning: Command \"${cmd}\" failed" >> "${logfile}" - echo >> "${logfile}" + echo "rc=${rc}" >> "${logfile}" + echo "Warning: Command \"${cmd}\" ended with ${rc}" return 1 fi }