]> git.ipfire.org Git - people/ms/ipfire-2.x.git/commitdiff
make.sh: Create a timer co-process
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 5 Jul 2024 13:37:15 +0000 (13:37 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 8 Jul 2024 15:39:44 +0000 (15:39 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
make.sh

diff --git a/make.sh b/make.sh
index 19d94445d5b9fdb5704a284ab79daa7b4912d259..f709adcd7e5cfbc655aef83b34f321f5d42b8d9f 100755 (executable)
--- a/make.sh
+++ b/make.sh
@@ -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