From 0ab6f83070c9a32a24454053319c99559c2654ca Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Mon, 23 Aug 2010 17:57:48 -0700 Subject: 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. --- bin/isolated-functions.sh | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'bin/isolated-functions.sh') 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], -- cgit v1.2.3-1-g7c22