diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2014-12-11 15:33:07 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2014-12-11 15:34:02 +0100 |
commit | acb8be721768b54075a51d1859d390904a0f1f6c (patch) | |
tree | 46b4cb8e116c3d7003df891f4bb2f4e75f3ec2eb | |
parent | d598a8d4e655b095c741f0cf73e139b3c9524da1 (diff) | |
download | busybox-w32-acb8be721768b54075a51d1859d390904a0f1f6c.tar.gz busybox-w32-acb8be721768b54075a51d1859d390904a0f1f6c.tar.bz2 busybox-w32-acb8be721768b54075a51d1859d390904a0f1f6c.zip |
tar: fix "tar -cJ" ignoring -J option. closes 7706
function old new delta
tar_main 895 938 +43
vfork_compressor 206 191 -15
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 43/-15) Total: 28 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | archival/tar.c | 66 |
1 files changed, 28 insertions, 38 deletions
diff --git a/archival/tar.c b/archival/tar.c index 5bd473aac..e116bd287 100644 --- a/archival/tar.c +++ b/archival/tar.c | |||
@@ -160,13 +160,6 @@ | |||
160 | #define block_buf bb_common_bufsiz1 | 160 | #define block_buf bb_common_bufsiz1 |
161 | 161 | ||
162 | 162 | ||
163 | #if !ENABLE_FEATURE_SEAMLESS_GZ && !ENABLE_FEATURE_SEAMLESS_BZ2 | ||
164 | /* Do not pass gzip flag to writeTarFile() */ | ||
165 | #define writeTarFile(tar_fd, verboseFlag, recurseFlags, include, exclude, gzip) \ | ||
166 | writeTarFile(tar_fd, verboseFlag, recurseFlags, include, exclude) | ||
167 | #endif | ||
168 | |||
169 | |||
170 | #if ENABLE_FEATURE_TAR_CREATE | 163 | #if ENABLE_FEATURE_TAR_CREATE |
171 | 164 | ||
172 | /* | 165 | /* |
@@ -621,21 +614,12 @@ static int FAST_FUNC writeFileToTarball(const char *fileName, struct stat *statb | |||
621 | return TRUE; | 614 | return TRUE; |
622 | } | 615 | } |
623 | 616 | ||
624 | #if ENABLE_FEATURE_SEAMLESS_GZ || ENABLE_FEATURE_SEAMLESS_BZ2 | 617 | #if SEAMLESS_COMPRESSION |
625 | # if !(ENABLE_FEATURE_SEAMLESS_GZ && ENABLE_FEATURE_SEAMLESS_BZ2) | ||
626 | # define vfork_compressor(tar_fd, gzip) vfork_compressor(tar_fd) | ||
627 | # endif | ||
628 | /* Don't inline: vfork scares gcc and pessimizes code */ | 618 | /* Don't inline: vfork scares gcc and pessimizes code */ |
629 | static void NOINLINE vfork_compressor(int tar_fd, int gzip) | 619 | static void NOINLINE vfork_compressor(int tar_fd, const char *gzip) |
630 | { | 620 | { |
631 | pid_t gzipPid; | 621 | pid_t gzipPid; |
632 | # if ENABLE_FEATURE_SEAMLESS_GZ && ENABLE_FEATURE_SEAMLESS_BZ2 | 622 | |
633 | const char *zip_exec = (gzip == 1) ? "gzip" : "bzip2"; | ||
634 | # elif ENABLE_FEATURE_SEAMLESS_GZ | ||
635 | const char *zip_exec = "gzip"; | ||
636 | # else /* only ENABLE_FEATURE_SEAMLESS_BZ2 */ | ||
637 | const char *zip_exec = "bzip2"; | ||
638 | # endif | ||
639 | // On Linux, vfork never unpauses parent early, although standard | 623 | // On Linux, vfork never unpauses parent early, although standard |
640 | // allows for that. Do we want to waste bytes checking for it? | 624 | // allows for that. Do we want to waste bytes checking for it? |
641 | # define WAIT_FOR_CHILD 0 | 625 | # define WAIT_FOR_CHILD 0 |
@@ -649,11 +633,6 @@ static void NOINLINE vfork_compressor(int tar_fd, int gzip) | |||
649 | 633 | ||
650 | signal(SIGPIPE, SIG_IGN); /* we only want EPIPE on errors */ | 634 | signal(SIGPIPE, SIG_IGN); /* we only want EPIPE on errors */ |
651 | 635 | ||
652 | # if defined(__GNUC__) && __GNUC__ | ||
653 | /* Avoid vfork clobbering */ | ||
654 | (void) &zip_exec; | ||
655 | # endif | ||
656 | |||
657 | gzipPid = xvfork(); | 636 | gzipPid = xvfork(); |
658 | 637 | ||
659 | if (gzipPid == 0) { | 638 | if (gzipPid == 0) { |
@@ -669,7 +648,7 @@ static void NOINLINE vfork_compressor(int tar_fd, int gzip) | |||
669 | xmove_fd(gzipDataPipe.rd, 0); | 648 | xmove_fd(gzipDataPipe.rd, 0); |
670 | xmove_fd(tar_fd, 1); | 649 | xmove_fd(tar_fd, 1); |
671 | /* exec gzip/bzip2 program/applet */ | 650 | /* exec gzip/bzip2 program/applet */ |
672 | BB_EXECLP(zip_exec, zip_exec, "-f", (char *)0); | 651 | BB_EXECLP(gzip, gzip, "-f", (char *)0); |
673 | vfork_exec_errno = errno; | 652 | vfork_exec_errno = errno; |
674 | _exit(EXIT_FAILURE); | 653 | _exit(EXIT_FAILURE); |
675 | } | 654 | } |
@@ -692,16 +671,21 @@ static void NOINLINE vfork_compressor(int tar_fd, int gzip) | |||
692 | # endif | 671 | # endif |
693 | if (vfork_exec_errno) { | 672 | if (vfork_exec_errno) { |
694 | errno = vfork_exec_errno; | 673 | errno = vfork_exec_errno; |
695 | bb_perror_msg_and_die("can't execute '%s'", zip_exec); | 674 | bb_perror_msg_and_die("can't execute '%s'", gzip); |
696 | } | 675 | } |
697 | } | 676 | } |
698 | #endif /* ENABLE_FEATURE_SEAMLESS_GZ || ENABLE_FEATURE_SEAMLESS_BZ2 */ | 677 | #endif /* SEAMLESS_COMPRESSION */ |
699 | 678 | ||
700 | 679 | ||
680 | #if !SEAMLESS_COMPRESSION | ||
681 | /* Do not pass gzip flag to writeTarFile() */ | ||
682 | #define writeTarFile(tar_fd, verboseFlag, recurseFlags, include, exclude, gzip) \ | ||
683 | writeTarFile(tar_fd, verboseFlag, recurseFlags, include, exclude) | ||
684 | #endif | ||
701 | /* gcc 4.2.1 inlines it, making code bigger */ | 685 | /* gcc 4.2.1 inlines it, making code bigger */ |
702 | static NOINLINE int writeTarFile(int tar_fd, int verboseFlag, | 686 | static NOINLINE int writeTarFile(int tar_fd, int verboseFlag, |
703 | int recurseFlags, const llist_t *include, | 687 | int recurseFlags, const llist_t *include, |
704 | const llist_t *exclude, int gzip) | 688 | const llist_t *exclude, const char *gzip) |
705 | { | 689 | { |
706 | int errorFlag = FALSE; | 690 | int errorFlag = FALSE; |
707 | struct TarBallInfo tbInfo; | 691 | struct TarBallInfo tbInfo; |
@@ -714,7 +698,7 @@ static NOINLINE int writeTarFile(int tar_fd, int verboseFlag, | |||
714 | * can avoid including the tarball into itself.... */ | 698 | * can avoid including the tarball into itself.... */ |
715 | xfstat(tbInfo.tarFd, &tbInfo.tarFileStatBuf, "can't stat tar file"); | 699 | xfstat(tbInfo.tarFd, &tbInfo.tarFileStatBuf, "can't stat tar file"); |
716 | 700 | ||
717 | #if ENABLE_FEATURE_SEAMLESS_GZ || ENABLE_FEATURE_SEAMLESS_BZ2 | 701 | #if SEAMLESS_COMPRESSION |
718 | if (gzip) | 702 | if (gzip) |
719 | vfork_compressor(tbInfo.tarFd, gzip); | 703 | vfork_compressor(tbInfo.tarFd, gzip); |
720 | #endif | 704 | #endif |
@@ -749,7 +733,7 @@ static NOINLINE int writeTarFile(int tar_fd, int verboseFlag, | |||
749 | if (errorFlag) | 733 | if (errorFlag) |
750 | bb_error_msg("error exit delayed from previous errors"); | 734 | bb_error_msg("error exit delayed from previous errors"); |
751 | 735 | ||
752 | #if ENABLE_FEATURE_SEAMLESS_GZ || ENABLE_FEATURE_SEAMLESS_BZ2 | 736 | #if SEAMLESS_COMPRESSION |
753 | if (gzip) { | 737 | if (gzip) { |
754 | int status; | 738 | int status; |
755 | if (safe_waitpid(-1, &status, 0) == -1) | 739 | if (safe_waitpid(-1, &status, 0) == -1) |
@@ -764,7 +748,7 @@ static NOINLINE int writeTarFile(int tar_fd, int verboseFlag, | |||
764 | #else | 748 | #else |
765 | int writeTarFile(int tar_fd, int verboseFlag, | 749 | int writeTarFile(int tar_fd, int verboseFlag, |
766 | int recurseFlags, const llist_t *include, | 750 | int recurseFlags, const llist_t *include, |
767 | const llist_t *exclude, int gzip); | 751 | const llist_t *exclude, const char *gzip); |
768 | #endif /* FEATURE_TAR_CREATE */ | 752 | #endif /* FEATURE_TAR_CREATE */ |
769 | 753 | ||
770 | #if ENABLE_FEATURE_TAR_FROM | 754 | #if ENABLE_FEATURE_TAR_FROM |
@@ -1149,18 +1133,24 @@ int tar_main(int argc UNUSED_PARAM, char **argv) | |||
1149 | if (base_dir) | 1133 | if (base_dir) |
1150 | xchdir(base_dir); | 1134 | xchdir(base_dir); |
1151 | 1135 | ||
1152 | //if (SEAMLESS_COMPRESSION || OPT_COMPRESS) | 1136 | //if (SEAMLESS_COMPRESSION) |
1153 | // /* We need to know whether child (gzip/bzip/etc) exits abnormally */ | 1137 | // /* We need to know whether child (gzip/bzip/etc) exits abnormally */ |
1154 | // signal(SIGCHLD, check_errors_in_children); | 1138 | // signal(SIGCHLD, check_errors_in_children); |
1155 | 1139 | ||
1156 | /* Create an archive */ | 1140 | /* Create an archive */ |
1157 | if (opt & OPT_CREATE) { | 1141 | if (opt & OPT_CREATE) { |
1158 | #if ENABLE_FEATURE_SEAMLESS_GZ || ENABLE_FEATURE_SEAMLESS_BZ2 | 1142 | #if SEAMLESS_COMPRESSION |
1159 | int zipMode = 0; | 1143 | const char *zipMode = NULL; |
1160 | if (ENABLE_FEATURE_SEAMLESS_GZ && (opt & OPT_GZIP)) | 1144 | if (opt & OPT_COMPRESS) |
1161 | zipMode = 1; | 1145 | zipMode = "compress"; |
1162 | if (ENABLE_FEATURE_SEAMLESS_BZ2 && (opt & OPT_BZIP2)) | 1146 | if (opt & OPT_GZIP) |
1163 | zipMode = 2; | 1147 | zipMode = "gzip"; |
1148 | if (opt & OPT_BZIP2) | ||
1149 | zipMode = "bzip2"; | ||
1150 | if (opt & OPT_LZMA) | ||
1151 | zipMode = "lzma"; | ||
1152 | if (opt & OPT_XZ) | ||
1153 | zipMode = "xz"; | ||
1164 | #endif | 1154 | #endif |
1165 | /* NB: writeTarFile() closes tar_handle->src_fd */ | 1155 | /* NB: writeTarFile() closes tar_handle->src_fd */ |
1166 | return writeTarFile(tar_handle->src_fd, verboseFlag, | 1156 | return writeTarFile(tar_handle->src_fd, verboseFlag, |