Subject: bin/22740: bin/pax doesn't for compressor before exiting
To: None <gnats-bugs@gnats.NetBSD.org>
From: None <joerg@britannica.bec.de>
List: netbsd-bugs
Date: 09/10/2003 16:16:14
>Number:         22740
>Category:       bin
>Synopsis:       bin/pax doesn't for compressor before exiting
>Confidential:   no
>Severity:       serious
>Priority:       low
>Responsible:    bin-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Sep 10 16:17:00 UTC 2003
>Closed-Date:
>Last-Modified:
>Originator:     Joerg Sonnenberger
>Release:        current
>Organization:
>Environment:
any NetBSD using pax
>Description:
If pax utilizes a compressor in creation mode, e.g. if called as "tar -xzf", it doesn't wait for it to finish. Therefore a race between the exit of pax and a program manipulating the archive afterwards exist.
>How-To-Repeat:
mkdir /tmp/bla
tar czf /tmp/bla.tar.gz /tmp/bla && ls -l /tmp/bla.tar.gz

There is a chance of ls showing an empty file.
>Fix:
This patch is from OpenBSD.

--- ar_io.c.orig	Wed Sep 10 18:06:30 2003
+++ ar_io.c	Wed Sep 10 18:08:35 2003
@@ -383,6 +383,8 @@
 void
 ar_close(void)
 {
+	int status;
+
 	if (arfd < 0) {
 		did_io = io_ok = flcnt = 0;
 		return;
@@ -418,11 +420,8 @@
 	 * for a quick extract/list, pax frequently exits before the child
 	 * process is done
 	 */
-	if ((act == LIST || act == EXTRACT) && nflag && zpid > 0) {
-		int status;
+	if ((act == LIST || act == EXTRACT) && nflag && zpid > 0)
 		kill(zpid, SIGINT);
-		waitpid(zpid, &status, 0);
-	}
 
 #ifdef SUPPORT_RMT
 	if (artyp == ISRMT)
@@ -430,6 +429,10 @@
 	else
 #endif /* SUPPORT_RMT */
 		(void)close(arfd);
+
+	/* Do not exit before child to ensure data integrity */
+	if (zpid > 0)
+		waitpid(zpid, &status, 0);
 
 	if (vflag && (artyp == ISTAPE)) {
 		(void)fputs("done.\n", listf);

>Release-Note:
>Audit-Trail:
>Unformatted: