make.sh: Create a timer co-process

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
This commit is contained in:
Michael Tremer
2024-07-05 13:37:15 +00:00
parent dfb583fee3
commit 9d9c7cef74

45
make.sh
View File

@@ -358,6 +358,45 @@ print_build_summary() {
print_status DONE
}
# Launches a timer process as a co-process
launch_timer() {
# Do nothing if the timer is already running
if [ -n "${TIMER_PID}" ]; then
return 0
fi
# Launch the co-process
coproc TIMER { "${0}" "__timer" "$$"; }
# Register the signal handlers
trap "__timer_event" SIGUSR1
trap "terminate_timer" EXIT
}
# Terminates a previously launched timer
terminate_timer() {
if [ -n "${TIMER_PID}" ]; then
kill -TERM "${TIMER_PID}"
fi
}
# The timer main loop
__timer() {
local pid="${1}"
# Send SIGUSR1 to the main process once a second
while sleep 1; do
kill -USR1 "${pid}"
done
return 0
}
# Called when the timer triggers
__timer_event() {
: # TODO
}
exiterror() {
# Dump logfile
if [ -n "${LOGFILE}" ] && [ -e "${LOGFILE}" ]; then
@@ -778,6 +817,9 @@ run_command() {
# Store the start time
local t="${SECONDS}"
# Launch the timer
launch_timer
# Run the command and pipe all output to the logfile
if ! "${command[@]}" >> "${LOGFILE}" 2>&1 </dev/null; then
r="$?"
@@ -2333,6 +2375,9 @@ check-manualpages)
print_status FAIL
fi
;;
__timer)
__timer "${2}" || exit $?
;;
*)
echo "Usage: $0 [OPTIONS] {build|check-manualpages|clean|downloadsrc|find-dependencies|gettoolchain|lang|shell|toolchain|update-contributors|uploadsrc}"
cat doc/make.sh-usage