Subject: bin/20645: tar creation with "z" or "Z" option may delay in writing
To: None <gnats-bugs@gnats.netbsd.org>
From: None <kazuhito_tsuburaya@hotmail.com>
List: netbsd-bugs
Date: 03/10/2003 01:14:38
>Number:         20645
>Category:       bin
>Synopsis:       tar creation with "z" or "Z" option may delay in writing
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    bin-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon Mar 10 01:15:00 PST 2003
>Closed-Date:
>Last-Modified:
>Originator:     Kazuhito Tsuburaya
>Release:        NetBSD 1.6P
>Organization:
>Environment:
NetBSD zama.japan 1.6P NetBSD 1.6P (GENERIC-J) #0: Thu Mar 6 13:49:51 JST 2003 root@zama.japan:/usr/src/sys/arch/i386/compile/GENERIC-J i386
>Description:
tar creation with "z" or "Z" option may delay in writing to the  archve, therefore the immediate reading of the archive may cause "gzip: stdin: unexpected end of file" error.

I think the reason might be that the parent pax as ustar process dose not wait  enough for the execlp'ed child gzip/compress process
to finish writing to the archive.  


>How-To-Repeat:
For example, like this.

  tar czf foo.tar.gz /bin; tar tzf foo.tar.gz > /dev/null

may cause "gzip: stdin: unexpected end of file" error.

  tar czf foo.tar.gz /bin; cp foo.tar.gz foo2.tar.gz

foo2.tar.gz may be broken frequently and different in size 
from foo.tar.gz.

  tar czf - /bin | tar ztf - > /dev/null

is OK.

>Fix:
I am sorry I don't know the fix, but here are my workarounds for this problem.

    tar czf foo.tar.gz something_not_so_small
    sleep XX
    tar xzf foo.tar.gz > /dev/null

or

    tar cf foo.tar something_not_so_small
    gzip -f foo.tar

or
    tar cf - something_not_so_small | gzip -c - > foo.tar.gz

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