summaryrefslogtreecommitdiffstats
path: root/bin/isolated-functions.sh
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2010-08-23 17:57:48 -0700
committerZac Medico <zmedico@gentoo.org>2010-08-23 17:57:48 -0700
commit0ab6f83070c9a32a24454053319c99559c2654ca (patch)
tree02691a5ce6da1bfeb67761571f46c47e2b4161a1 /bin/isolated-functions.sh
parent3359e0116b4e592b28ac0f24fed6a1e2eabe6bf6 (diff)
downloadportage-0ab6f83070c9a32a24454053319c99559c2654ca.tar.gz
portage-0ab6f83070c9a32a24454053319c99559c2654ca.tar.bz2
portage-0ab6f83070c9a32a24454053319c99559c2654ca.zip
Handle SIGPIPE when unpack() extracts tar files through a pipe (bug #309001).
When checking ${PIPESTATUS[@]} for extraction of tar files in unpack(), use a new assert_sigpipe_ok() function which behaves the same as the existing assert() function except that it tolerates pipe writers being killed by SIGPIPE.
Diffstat (limited to 'bin/isolated-functions.sh')
-rw-r--r--bin/isolated-functions.sh26
1 files changed, 26 insertions, 0 deletions
diff --git a/bin/isolated-functions.sh b/bin/isolated-functions.sh
index 53312dba8..a490f27c0 100644
--- a/bin/isolated-functions.sh
+++ b/bin/isolated-functions.sh
@@ -15,6 +15,32 @@ assert() {
done
}
+assert_sigpipe_ok() {
+ # When extracting a tar file like this:
+ #
+ # bzip2 -dc foo.tar.bz2 | tar xof -
+ #
+ # For some tar files (see bug #309001), tar will
+ # close its stdin pipe when the decompressor still has
+ # remaining data to be written to its stdout pipe. This
+ # causes the decompressor to be killed by SIGPIPE. In
+ # this case, we want to ignore pipe writers killed by
+ # SIGPIPE, and trust the exit status of tar. We refer
+ # to the bash manual section "3.7.5 Exit Status"
+ # which says, "When a command terminates on a fatal
+ # signal whose number is N, Bash uses the value 128+N
+ # as the exit status."
+
+ local x pipestatus=${PIPESTATUS[*]}
+ for x in $pipestatus ; do
+ # Allow SIGPIPE through (128 + 13)
+ [[ $x -ne 0 && $x -ne 141 ]] && die "$@"
+ done
+
+ # Require normal success for the last process (tar).
+ [[ $x -eq 0 ]] || die "$@"
+}
+
shopt -s extdebug
# dump_trace([number of funcs on stack to skip],