From d9b14c457aded9848eed09f105fda0eff8615c34 Mon Sep 17 00:00:00 2001 From: Tobias Waldekranz Date: Wed, 5 Jun 2024 11:00:59 +0200 Subject: [PATCH] confd: dagger: Detect failing scripts When timestamping of scripts was added, we unfortunately started to record the exitstatus of `ts(1)`, rather than the script itself. Refactor the metadata collection to use `time(1)` instead, which will propagate the inferior's exitcode. This will also allow us to collect other parameters in the future. --- src/confd/bin/dagger | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/src/confd/bin/dagger b/src/confd/bin/dagger index 516d83fb..e1fa0fff 100755 --- a/src/confd/bin/dagger +++ b/src/confd/bin/dagger @@ -2,6 +2,11 @@ set -e +# We can't use bash's time, as it prints the timing information of the +# entire pipeline, meaning we can't redirect it to the log file. +TIME=$(which time) +TIMEFMT="\"time\": { \"real\": %e, \"user\": %U, \"sys\": %S }," + inform() { local level="$1" @@ -35,6 +40,7 @@ action_exec() local actdir="$2/action/$1" local orderfile="$actdir/order" local code=0 + local meta= generate_order "$2" @@ -50,9 +56,29 @@ action_exec() for node in $order; do for work in $(find "$actdir/$node" -type f -executable 2>/dev/null | sort); do - $work | ts >>"$work.log" 2>&1 || code=$? - echo "[exit:$code]" | ts >>"$work.log" + meta=$work-meta.json + cat >$meta <>"$work.log" 2>&1 || code=$? + + echo -ne "\t" >>$meta + # busybox's time(1) will happily write "Command exited + # with non-zero status" and similar messages to the + # output, even when -f is used. Work around that by only + # grabbing the last line, which holds the requested + # output. + tail -n1 $meta.time >>$meta + + cat >>$meta <