From: Michael Tremer Date: Fri, 5 Jul 2024 14:01:26 +0000 (+0000) Subject: make.sh: Have the background timer update the process runtime X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=28ccd5b9fea526b395153742846ebb51010d99bd;p=people%2Fms%2Fipfire-2.x.git make.sh: Have the background timer update the process runtime Signed-off-by: Michael Tremer --- diff --git a/make.sh b/make.sh index f709adcd7..c08ebe6c5 100755 --- a/make.sh +++ b/make.sh @@ -385,8 +385,11 @@ __timer() { local pid="${1}" # Send SIGUSR1 to the main process once a second + # If the parent process has gone away, we will terminate. while sleep 1; do - kill -USR1 "${pid}" + if ! kill -USR1 "${pid}" &>/dev/null; then + break + fi done return 0 @@ -394,7 +397,16 @@ __timer() { # Called when the timer triggers __timer_event() { - : # TODO + local t + + # If we have a running process, we update the runtime + # every time this is being triggered + if [ -n "${TIMER}" ] && [ "${TIMER}" -gt 0 ]; then + # Print the runtime + print_runtime "${TIMER} - $(( SECONDS - TIMER ))" + fi + + return 0 } exiterror() { @@ -814,16 +826,40 @@ run_command() { # Return code local r=0 + # Launch the timer + launch_timer + # Store the start time local t="${SECONDS}" - # Launch the timer - launch_timer + # If we are not running in quiet mode, we set the timer + case "${quiet}" in + false) + TIMER="${t}" + ;; + esac + + # Run the command in the background and pipe all output to the logfile + { + "${command[@]}" >> "${LOGFILE}" 2>&1 > "${LOGFILE}" 2>&1 = 128, wait has been interrupted by the timer + if [ "$?" -ge 128 ]; then + continue + fi + + # Store the return code r="$?" - fi + break + done + + # Clear the timer + TIMER=0 # Show runtime and status unless quiet case "${quiet}" in