Subject: bin/20275: progress(1) does not wait for termination of all children
To: None <gnats-bugs@gnats.netbsd.org>
From: None <shin@netbsd.org>
List: netbsd-bugs
Date: 02/10/2003 15:59:45
>Number:         20275
>Category:       bin
>Synopsis:       progress(1) does not wait for termination of all children
>Confidential:   no
>Severity:       critical
>Priority:       high
>Responsible:    bin-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sun Feb 09 23:00:00 PST 2003
>Closed-Date:
>Last-Modified:
>Originator:     Takao Shinohara
>Release:        NetBSD 1.6N
>Organization:
>Environment:
System: NetBSD misato 1.6N NetBSD 1.6N (GENERIC) #5: Sun Feb 9 00:11:08 JST 2003 shin@shinji:/u/src/current/obj/sys/arch/hpcmips/compile.hpcmips/GENERIC hpcmips
Architecture: mipsel
Machine: hpcmips
>Description:
	progress(1) sometimes causes premature termination of child process.
>How-To-Repeat:
	perform system installation with sysinst and enable progress bar.

	scenario:
	1) sysinst invokes progress(1)
	   progress -zf /mnt2/base.tgz pax -rpe -O
	2) progress(1) issues wait(2)
	3) progress(1) get status of gzip termination
	4) progress(1) exits
	5) (still running)pax get SIGHUP and terminates

>Fix:
	how about this patch?

Index: progress.c
===================================================================
RCS file: /cvsroot/src/usr.bin/progress/progress.c,v
retrieving revision 1.5
diff -u -r1.5 progress.c
--- progress.c	2003/01/22 10:44:17	1.5
+++ progress.c	2003/02/10 06:15:01
@@ -85,6 +85,7 @@
 	static char fb_buf[BUFSIZ];
 	char *infile = NULL;
 	pid_t pid;
+	pid_t gzippid;
 	int ch, fd, outpipe[2], waitstat;
 	int lflag = 0, zflag = 0;
 	ssize_t nr, nw, off;
@@ -152,7 +153,6 @@
 	}
 	/* Pipe input through gzip -dc if -z is given */
 	if (zflag) {
-		pid_t gzippid;
 		int gzippipe[2];
 
 		if (pipe(gzippipe) < 0)
@@ -211,7 +211,9 @@
 							(unsigned) nr);
 	close(outpipe[1]);
 
-	wait(&waitstat);
+	if (zflag)
+		waitpid(gzippid, &waitstat, 0);
+	waitpid(pid, &waitstat, 0);
 
 	progressmeter(1);
 	return 0;
>Release-Note:
>Audit-Trail:
>Unformatted:
 	-current snapshot 2003-02-08