From a08980ca4e0b321fd1c177179dfc42af53617c76 Mon Sep 17 00:00:00 2001 From: Marc Espie Date: Wed, 4 Aug 1999 17:13:25 +0000 Subject: Kill gzip subprocess correctly instead of letting it get a SIGPIPE when using pax -n to list/extract. --- bin/pax/ar_io.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) (limited to 'bin/pax') diff --git a/bin/pax/ar_io.c b/bin/pax/ar_io.c index 6afe997e246..c95c41de9c9 100644 --- a/bin/pax/ar_io.c +++ b/bin/pax/ar_io.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ar_io.c,v 1.18 1998/09/20 02:22:21 millert Exp $ */ +/* $OpenBSD: ar_io.c,v 1.19 1999/08/04 17:13:24 espie Exp $ */ /* $NetBSD: ar_io.c,v 1.5 1996/03/26 23:54:13 mrg Exp $ */ /*- @@ -42,7 +42,7 @@ #if 0 static char sccsid[] = "@(#)ar_io.c 8.2 (Berkeley) 4/18/94"; #else -static char rcsid[] = "$OpenBSD: ar_io.c,v 1.18 1998/09/20 02:22:21 millert Exp $"; +static char rcsid[] = "$OpenBSD: ar_io.c,v 1.19 1999/08/04 17:13:24 espie Exp $"; #endif #endif /* not lint */ @@ -52,6 +52,7 @@ static char rcsid[] = "$OpenBSD: ar_io.c,v 1.18 1998/09/20 02:22:21 millert Exp #include #include #include +#include #include #include #include @@ -87,6 +88,7 @@ static int wr_trail = 1; /* trailer was rewritten in append */ static int can_unlnk = 0; /* do we unlink null archives? */ char *arcname; /* printable name of archive */ char *gzip_program; /* name of gzip program */ +static pid_t zpid = -1; /* pid of child process */ static int get_phys __P((void)); extern sigset_t s_mask; @@ -347,6 +349,16 @@ ar_close() can_unlnk = 0; } + /* + * for a quick extract/list, pax frequently exits before the child + * process is done + */ + if ((act == LIST || act == EXTRACT) && nflag && zpid > 0) { + int status; + kill(zpid, SIGINT); + waitpid(zpid, &status, 0); + } + (void)close(arfd); if (vflag && (artyp == ISTAPE)) { @@ -1316,18 +1328,17 @@ ar_start_gzip(fd) int fd; #endif { - pid_t pid; int fds[2]; char *gzip_flags; if (pipe(fds) < 0) err(1, "could not pipe"); - pid = fork(); - if (pid < 0) + zpid = fork(); + if (zpid < 0) err(1, "could not fork"); /* parent */ - if (pid) { + if (zpid) { switch (act) { case ARCHIVE: dup2(fds[1], fd); -- cgit v1.2.3