From: Sergey Poznyakoff Date: Wed, 14 Oct 2009 14:55:15 +0000 (+0300) Subject: Minor changes. X-Git-Url: https://git.brokenzipper.com/gitweb?a=commitdiff_plain;h=0c6c288b5360fcdb7f9b5826d05c01ade33253f0;p=chaz%2Ftar Minor changes. * src/tar.c (main): Ignore SIGPIPE. * src/system.c (sys_child_open_for_compress) (sys_child_open_for_uncompress): Reset SIGPIPE in child to default. * tests/remfiles01.at: Avoid race conditions. * tests/remfiles02.at: Likewise. --- diff --git a/src/system.c b/src/system.c index cf39dbd..ea88496 100644 --- a/src/system.c +++ b/src/system.c @@ -331,7 +331,8 @@ sys_child_open_for_compress (void) /* The new born child tar is here! */ set_program_name (_("tar (child)")); - + signal (SIGPIPE, SIG_DFL); + xdup2 (parent_pipe[PREAD], STDIN_FILENO); xclose (parent_pipe[PWRITE]); @@ -474,7 +475,8 @@ sys_child_open_for_uncompress (void) /* The newborn child tar is here! */ set_program_name (_("tar (child)")); - + signal (SIGPIPE, SIG_DFL); + xdup2 (parent_pipe[PWRITE], STDOUT_FILENO); xclose (parent_pipe[PREAD]); diff --git a/src/tar.c b/src/tar.c index 3ef9c8f..a1185f6 100644 --- a/src/tar.c +++ b/src/tar.c @@ -2556,7 +2556,7 @@ main (int argc, char **argv) obstack_init (&argv_stk); /* Ensure default behavior for some signals */ - signal (SIGPIPE, SIG_DFL); + signal (SIGPIPE, SIG_IGN); /* System V fork+wait does not work if SIGCHLD is ignored. */ signal (SIGCHLD, SIG_DFL); diff --git a/tests/remfiles01.at b/tests/remfiles01.at index 8a668a7..940fd95 100644 --- a/tests/remfiles01.at +++ b/tests/remfiles01.at @@ -40,11 +40,20 @@ chmod 0 a genfile --file b mkdir c -tar -c -f a -z --remove-files b c +# Depending on when the SIGPIPE gets delivered, the invocation below +# may finish with either +# tar: a: Cannot write: Broken pipe +# or +# tar: Child returned status 2 +tar -c -f a -z --remove-files b c 2>err +EC=$? +sed -n '/(child)/p' err >&2 +rm err find . | sort +exit $EC ], -[0], +[2], [. ./a ./b diff --git a/tests/remfiles02.at b/tests/remfiles02.at index d137433..31dc3ad 100644 --- a/tests/remfiles02.at +++ b/tests/remfiles02.at @@ -39,11 +39,14 @@ mkdir a genfile --file b mkdir c -tar -c -f a -z --remove-files b c - +tar -c -f a -z --remove-files b c 2>err +EC=$? +sed -n '/(child)/p' err >&2 +rm err find . | sort +exit $EC ], -[0], +[2], [. ./a ./b @@ -51,8 +54,6 @@ find . | sort ], [tar (child): a: Cannot open: Is a directory tar (child): Error is not recoverable: exiting now -tar: Child returned status 2 -tar: Error is not recoverable: exiting now ]) AT_CLEANUP