From: Tim Kientzle Date: Sat, 5 Nov 2011 23:34:57 +0000 (-0400) Subject: Mask SIGPIPE for libarchive test, tar, and cpio. X-Git-Tag: v3.0.0a~24 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6fa664e048bd225a80515aecc5f3e6275569121d;p=thirdparty%2Flibarchive.git Mask SIGPIPE for libarchive test, tar, and cpio. As reported at: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=641265 The SIGPIPE occurs when feeding data through a decompression program; the external program may see an end-of-data marker and exit before we've finished feeding it all of the data. (This happens when the data has garbage padding at the end.) We want to catch and ignore the EPIPE since we can still read the data coming out of the decompression program. SVN-Revision: 3751 --- diff --git a/cpio/cpio.c b/cpio/cpio.c index 6a09412c4..ff5a1c600 100644 --- a/cpio/cpio.c +++ b/cpio/cpio.c @@ -56,6 +56,9 @@ __FBSDID("$FreeBSD: src/usr.bin/cpio/cpio.c,v 1.15 2008/12/06 07:30:40 kientzle #ifdef HAVE_PWD_H #include #endif +#ifdef HAVE_SIGNAL_H +#include +#endif #ifdef HAVE_STDARG_H #include #endif @@ -136,6 +139,16 @@ main(int argc, char *argv[]) cpio->buff = buff; cpio->buff_size = sizeof(buff); +#if defined(HAVE_SIGACTION) && defined(SIGPIPE) + { /* Ignore SIGPIPE signals. */ + struct sigaction sa; + sigemptyset(&sa.sa_mask); + sa.sa_flags = 0; + sa.sa_handler = SIG_IGN; + sigaction(SIGPIPE, &sa, NULL); + } +#endif + /* Need lafe_progname before calling lafe_warnc. */ if (*argv == NULL) lafe_progname = "bsdcpio"; diff --git a/libarchive/test/main.c b/libarchive/test/main.c index 18ea1dbc5..94fa77094 100644 --- a/libarchive/test/main.c +++ b/libarchive/test/main.c @@ -33,6 +33,9 @@ #endif #include #include +#ifdef HAVE_SIGNAL_H +#include +#endif #include #include @@ -2342,6 +2345,16 @@ main(int argc, char **argv) } #endif +#if !defined(_WIN32) && defined(SIGPIPE) + { /* Ignore SIGPIPE signals */ + struct sigaction sa; + sa.sa_handler = SIG_IGN; + sigemptyset(&sa.sa_mask); + sa.sa_flags = 0; + sigaction(SIGPIPE, &sa, NULL); + } +#endif + /* * Create a temp directory for the following tests. * Include the time the tests started as part of the name, diff --git a/tar/bsdtar.c b/tar/bsdtar.c index 6576b2f08..a55b7dcf0 100644 --- a/tar/bsdtar.c +++ b/tar/bsdtar.c @@ -153,8 +153,8 @@ main(int argc, char **argv) bsdtar->uid = -1; option_o = 0; -#if defined(HAVE_SIGACTION) && (defined(SIGINFO) || defined(SIGUSR1)) - { /* Catch SIGINFO and SIGUSR1, if they exist. */ +#if defined(HAVE_SIGACTION) + { /* Set up signal handling. */ struct sigaction sa; sa.sa_handler = siginfo_handler; sigemptyset(&sa.sa_mask); @@ -167,6 +167,11 @@ main(int argc, char **argv) /* ... and treat SIGUSR1 the same way as SIGINFO. */ if (sigaction(SIGUSR1, &sa, NULL)) lafe_errc(1, errno, "sigaction(SIGUSR1) failed"); +#endif +#ifdef SIGPIPE + /* Ignore SIGPIPE signals. */ + sa.sa_handler = SIG_IGN; + sigaction(SIGPIPE, &sa, NULL); #endif } #endif