Browse Source

Shuffle FDs

Can't use FD 3 in log_loop since it collides with FD 3 output from codearchiver; FD 42 should be safe.

Further, since all log(_loop) output goes to stderr, the order of redirections on codearchiver is important, and the redirection of stderr must come last so that the subshells from out and 3 get the original stderr.
master
JustAnotherArchivist 1 year ago
parent
commit
46f80a357b
1 changed files with 3 additions and 3 deletions
  1. +3
    -3
      codearchiver-bot

+ 3
- 3
codearchiver-bot View File

@@ -28,7 +28,7 @@ function log {
function log_loop {
prefix="$1"
# If the output does not end with a LF, add one. Then replace CRLF with LF and replace remaining CR with LF.
{ lastchar="$(tee /dev/fd/3 | tail -c 1 | xxd -p)"; if [[ "${lastchar}" != '0a' ]]; then printf '\n'; fi } 3>&1 |
{ lastchar="$(tee /dev/fd/42 | tail -c 1 | xxd -p)"; if [[ "${lastchar}" != '0a' ]]; then printf '\n'; fi } 42>&1 |
sed -u 's,\r$,,; s,\r,\n,g' |
while IFS= read -r line; do log "${prefix}${line}"; done
}
@@ -177,9 +177,9 @@ function taint_block {

timeout --signal=INT "${timeout}" \
codearchiver --verbose --write-artefacts-fd-3 "${url}" \
3> >(tee "${artefactsname}" | log_loop "Artefact from codearchiver ${singlejobid}: ") \
> >(log_loop "codearchiver ${singlejobid} out: ") \
2> >(tee "${logname}" | grep -Fv -e ' INFO ' | log_loop "codearchiver ${singlejobid} err: ") \
3> >(tee "${artefactsname}" | log_loop "Artefact from codearchiver ${singlejobid}: ")
2> >(tee "${logname}" | grep -Fv -e ' INFO ' | log_loop "codearchiver ${singlejobid} err: ")
status="$?"
log "codearchiver ${url} finished with status code ${status}"
#TODO Integrate this into the pipe from codearchiver above to avoid rereading the entire log file


Loading…
Cancel
Save