From de72ce4aa5f01faec6d03cf1c9ed918c058b3942 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Mon, 23 Aug 2021 05:28:58 -0500 Subject: [PATCH] Avoid race condition where child process complains about nothing. Two NUL headers indicate end of archive, but some implementations add lots of extra NUL padding (because 1970s reel to reel tape). If we exit before the archiver child process has managed to write all that extra NUL padding into the pipe buffer it complains to stderr, so kill it before exiting. --- toys/posix/tar.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/toys/posix/tar.c b/toys/posix/tar.c index b4efa8da..42a18832 100644 --- a/toys/posix/tar.c +++ b/toys/posix/tar.c @@ -56,7 +56,7 @@ GLOBALS( struct double_list *incl, *excl, *seen; struct string_list *dirs; char *cwd; - int fd, ouid, ggid, hlc, warn, adev, aino, sparselen; + int fd, ouid, ggid, hlc, warn, adev, aino, sparselen, pid; long long *sparse; time_t mtt; @@ -923,7 +923,7 @@ void tar_main(void) FLAG(j) ? "bzcat" : FLAG(J) ? "xzcat" : "zcat"); // Toybox provides more decompressors than compressors, so try them first - xpopen_both(zcat ? (char *[]){zcat->str, 0} : + TT.pid = xpopen_both(zcat ? (char *[]){zcat->str, 0} : (char *[]){archiver, "-d", 0}, pipefd); if (CFG_TOYBOX_FREE) llist_traverse(zcat, free); @@ -964,6 +964,8 @@ void tar_main(void) unpack_tar(hdr); dirflush(0, 0); + // Shut up archiver about inability to write all trailing NULs to pipe buf + if (TT.pid>0) kill(TT.pid, 9); // Each time a TT.incl entry is seen it's moved to the end of the list, // with TT.seen pointing to first seen list entry. Anything between -- 2.39.2