summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Orgis2020-08-28 15:08:57 +0200
committerThomas Orgis2021-02-26 11:29:41 +0100
commitd4faf47101a6f1ee7c354813624968e3a6d671df (patch)
tree569cc6b2dfd22d293cadf474da5a636183b7f768
parente691f5d0ec91988e5e7b0acd987a0e5f43de0f73 (diff)
libmisc: more robust debugging of parallel work
This prints out the whole debugging line on one go to reduce interference of printouts from multiple sorcery processes (subshells for cast passes). Debugging is a nightmare when data within a line is already interleaved! This is still not proper, but we don't want to bring things to a crawl by i/o locking. An alternative might be to write output to per-process files. But then, we also should implement timestamps in the output. Pro-tip: use ts from moreutils in a tail -f | ts configuration to put them on closely after the fact. Also, to actually tell the differing subshells of the cast process apart, the variable $$ is not enough. Bash offers an alternative. This is used with $$ as fallback now. We may want to check what to do for other shells that we want to be able to run sorcery properly.
-rwxr-xr-xvar/lib/sorcery/modules/libmisc12
1 files changed, 9 insertions, 3 deletions
diff --git a/var/lib/sorcery/modules/libmisc b/var/lib/sorcery/modules/libmisc
index 8eba9850..b2bc2c06 100755
--- a/var/lib/sorcery/modules/libmisc
+++ b/var/lib/sorcery/modules/libmisc
@@ -230,12 +230,18 @@ debug() {
debugVar=${debugVar//[^a-zA-Z0-9_]/_}
local i
if [[ ${!debugVar} != "no" ]] ; then
- echo -n "$1($$): " >>$DEBUG
+ # Construct line and print out in one go, to lessen interference from
+ # parallel work, and some strange interference between printouts of one
+ # and the same process that I do not understand (yet, or ever).
+ # In ( ... ) subshells, $$ still refers to the mother shell, trying
+ # the bashism with fallback to be able to tell apart parallel cast passes
+ # three and four.
+ local line="$1(${BASHPID:-$$}):"
shift
for i in "$@" ; do
- echo -n " \"$i\"" >>$DEBUG
+ line="$line \"$i\""
done
- echo >>$DEBUG
+ printf "%s\n" "$line" >>$DEBUG
fi
true