Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/bin/pax wait for compression program to finish before exiting.



details:   https://anonhg.NetBSD.org/src/rev/7889235d934d
branches:  trunk
changeset: 552085:7889235d934d
user:      grant <grant%NetBSD.org@localhost>
date:      Thu Sep 18 09:18:24 2003 +0000

description:
wait for compression program to finish before exiting.

fix races condition resulting in a zero length archive after pax
exits.

patch from OpenBSD, provided by Joerg Sonnenberger in PR bin/22740.

diffstat:

 bin/pax/ar_io.c |  15 +++++++++------
 1 files changed, 9 insertions(+), 6 deletions(-)

diffs (51 lines):

diff -r eab43f6eb7a9 -r 7889235d934d bin/pax/ar_io.c
--- a/bin/pax/ar_io.c   Thu Sep 18 09:16:27 2003 +0000
+++ b/bin/pax/ar_io.c   Thu Sep 18 09:18:24 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ar_io.c,v 1.36 2003/08/07 09:05:19 agc Exp $   */
+/*     $NetBSD: ar_io.c,v 1.37 2003/09/18 09:18:24 grant Exp $ */
 
 /*-
  * Copyright (c) 1992, 1993
@@ -72,7 +72,7 @@
 #if 0
 static char sccsid[] = "@(#)ar_io.c    8.2 (Berkeley) 4/18/94";
 #else
-__RCSID("$NetBSD: ar_io.c,v 1.36 2003/08/07 09:05:19 agc Exp $");
+__RCSID("$NetBSD: ar_io.c,v 1.37 2003/09/18 09:18:24 grant Exp $");
 #endif
 #endif /* not lint */
 
@@ -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)
@@ -431,6 +430,10 @@
 #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);
                vfpart = 0;



Home | Main Index | Thread Index | Old Index