aboutsummaryrefslogtreecommitdiff
path: root/archival/tar.c
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2014-12-14 14:20:56 +0000
committerRon Yorston <rmy@pobox.com>2014-12-14 14:20:56 +0000
commit6d6d18d45c145899fce3a39553771cf0af671f30 (patch)
tree1936d18cbf61b9e0989464aad0a11c52cbeff7b7 /archival/tar.c
parent0c204dc07b718244c360e0b84df66ce0a012e14f (diff)
parentacb8be721768b54075a51d1859d390904a0f1f6c (diff)
downloadbusybox-w32-6d6d18d45c145899fce3a39553771cf0af671f30.tar.gz
busybox-w32-6d6d18d45c145899fce3a39553771cf0af671f30.tar.bz2
busybox-w32-6d6d18d45c145899fce3a39553771cf0af671f30.zip
Merge branch 'busybox' into merge
Conflicts: archival/libarchive/open_transformer.c libbb/lineedit.c miscutils/man.c
Diffstat (limited to 'archival/tar.c')
-rw-r--r--archival/tar.c70
1 files changed, 30 insertions, 40 deletions
diff --git a/archival/tar.c b/archival/tar.c
index 63d844a3a..e00ed26a8 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/*
@@ -623,21 +616,12 @@ static int FAST_FUNC writeFileToTarball(const char *fileName, struct stat *statb
623 return TRUE; 616 return TRUE;
624} 617}
625 618
626#if ENABLE_FEATURE_SEAMLESS_GZ || ENABLE_FEATURE_SEAMLESS_BZ2 619#if SEAMLESS_COMPRESSION
627# if !(ENABLE_FEATURE_SEAMLESS_GZ && ENABLE_FEATURE_SEAMLESS_BZ2)
628# define vfork_compressor(tar_fd, gzip) vfork_compressor(tar_fd)
629# endif
630/* Don't inline: vfork scares gcc and pessimizes code */ 620/* Don't inline: vfork scares gcc and pessimizes code */
631static void NOINLINE vfork_compressor(int tar_fd, int gzip) 621static void NOINLINE vfork_compressor(int tar_fd, const char *gzip)
632{ 622{
633 pid_t gzipPid; 623 pid_t gzipPid;
634# if ENABLE_FEATURE_SEAMLESS_GZ && ENABLE_FEATURE_SEAMLESS_BZ2 624
635 const char *zip_exec = (gzip == 1) ? "gzip" : "bzip2";
636# elif ENABLE_FEATURE_SEAMLESS_GZ
637 const char *zip_exec = "gzip";
638# else /* only ENABLE_FEATURE_SEAMLESS_BZ2 */
639 const char *zip_exec = "bzip2";
640# endif
641 // On Linux, vfork never unpauses parent early, although standard 625 // On Linux, vfork never unpauses parent early, although standard
642 // allows for that. Do we want to waste bytes checking for it? 626 // allows for that. Do we want to waste bytes checking for it?
643# define WAIT_FOR_CHILD 0 627# define WAIT_FOR_CHILD 0
@@ -651,11 +635,6 @@ static void NOINLINE vfork_compressor(int tar_fd, int gzip)
651 635
652 signal(SIGPIPE, SIG_IGN); /* we only want EPIPE on errors */ 636 signal(SIGPIPE, SIG_IGN); /* we only want EPIPE on errors */
653 637
654# if defined(__GNUC__) && __GNUC__
655 /* Avoid vfork clobbering */
656 (void) &zip_exec;
657# endif
658
659 gzipPid = xvfork(); 638 gzipPid = xvfork();
660 639
661 if (gzipPid == 0) { 640 if (gzipPid == 0) {
@@ -671,7 +650,7 @@ static void NOINLINE vfork_compressor(int tar_fd, int gzip)
671 xmove_fd(gzipDataPipe.rd, 0); 650 xmove_fd(gzipDataPipe.rd, 0);
672 xmove_fd(tar_fd, 1); 651 xmove_fd(tar_fd, 1);
673 /* exec gzip/bzip2 program/applet */ 652 /* exec gzip/bzip2 program/applet */
674 BB_EXECLP(zip_exec, zip_exec, "-f", (char *)0); 653 BB_EXECLP(gzip, gzip, "-f", (char *)0);
675 vfork_exec_errno = errno; 654 vfork_exec_errno = errno;
676 _exit(EXIT_FAILURE); 655 _exit(EXIT_FAILURE);
677 } 656 }
@@ -694,16 +673,21 @@ static void NOINLINE vfork_compressor(int tar_fd, int gzip)
694# endif 673# endif
695 if (vfork_exec_errno) { 674 if (vfork_exec_errno) {
696 errno = vfork_exec_errno; 675 errno = vfork_exec_errno;
697 bb_perror_msg_and_die("can't execute '%s'", zip_exec); 676 bb_perror_msg_and_die("can't execute '%s'", gzip);
698 } 677 }
699} 678}
700#endif /* ENABLE_FEATURE_SEAMLESS_GZ || ENABLE_FEATURE_SEAMLESS_BZ2 */ 679#endif /* SEAMLESS_COMPRESSION */
701 680
702 681
682#if !SEAMLESS_COMPRESSION
683/* Do not pass gzip flag to writeTarFile() */
684#define writeTarFile(tar_fd, verboseFlag, recurseFlags, include, exclude, gzip) \
685 writeTarFile(tar_fd, verboseFlag, recurseFlags, include, exclude)
686#endif
703/* gcc 4.2.1 inlines it, making code bigger */ 687/* gcc 4.2.1 inlines it, making code bigger */
704static NOINLINE int writeTarFile(int tar_fd, int verboseFlag, 688static NOINLINE int writeTarFile(int tar_fd, int verboseFlag,
705 int recurseFlags, const llist_t *include, 689 int recurseFlags, const llist_t *include,
706 const llist_t *exclude, int gzip) 690 const llist_t *exclude, const char *gzip)
707{ 691{
708 int errorFlag = FALSE; 692 int errorFlag = FALSE;
709 struct TarBallInfo tbInfo; 693 struct TarBallInfo tbInfo;
@@ -716,7 +700,7 @@ static NOINLINE int writeTarFile(int tar_fd, int verboseFlag,
716 * can avoid including the tarball into itself.... */ 700 * can avoid including the tarball into itself.... */
717 xfstat(tbInfo.tarFd, &tbInfo.tarFileStatBuf, "can't stat tar file"); 701 xfstat(tbInfo.tarFd, &tbInfo.tarFileStatBuf, "can't stat tar file");
718 702
719#if ENABLE_FEATURE_SEAMLESS_GZ || ENABLE_FEATURE_SEAMLESS_BZ2 703#if SEAMLESS_COMPRESSION
720 if (gzip) 704 if (gzip)
721 vfork_compressor(tbInfo.tarFd, gzip); 705 vfork_compressor(tbInfo.tarFd, gzip);
722#endif 706#endif
@@ -751,7 +735,7 @@ static NOINLINE int writeTarFile(int tar_fd, int verboseFlag,
751 if (errorFlag) 735 if (errorFlag)
752 bb_error_msg("error exit delayed from previous errors"); 736 bb_error_msg("error exit delayed from previous errors");
753 737
754#if ENABLE_FEATURE_SEAMLESS_GZ || ENABLE_FEATURE_SEAMLESS_BZ2 738#if SEAMLESS_COMPRESSION
755 if (gzip) { 739 if (gzip) {
756 int status; 740 int status;
757 if (safe_waitpid(-1, &status, 0) == -1) 741 if (safe_waitpid(-1, &status, 0) == -1)
@@ -766,7 +750,7 @@ static NOINLINE int writeTarFile(int tar_fd, int verboseFlag,
766#else 750#else
767int writeTarFile(int tar_fd, int verboseFlag, 751int writeTarFile(int tar_fd, int verboseFlag,
768 int recurseFlags, const llist_t *include, 752 int recurseFlags, const llist_t *include,
769 const llist_t *exclude, int gzip); 753 const llist_t *exclude, const char *gzip);
770#endif /* FEATURE_TAR_CREATE */ 754#endif /* FEATURE_TAR_CREATE */
771 755
772#if ENABLE_FEATURE_TAR_FROM 756#if ENABLE_FEATURE_TAR_FROM
@@ -1151,18 +1135,24 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
1151 if (base_dir) 1135 if (base_dir)
1152 xchdir(base_dir); 1136 xchdir(base_dir);
1153 1137
1154 //if (SEAMLESS_COMPRESSION || OPT_COMPRESS) 1138 //if (SEAMLESS_COMPRESSION)
1155 // /* We need to know whether child (gzip/bzip/etc) exits abnormally */ 1139 // /* We need to know whether child (gzip/bzip/etc) exits abnormally */
1156 // signal(SIGCHLD, check_errors_in_children); 1140 // signal(SIGCHLD, check_errors_in_children);
1157 1141
1158 /* Create an archive */ 1142 /* Create an archive */
1159 if (opt & OPT_CREATE) { 1143 if (opt & OPT_CREATE) {
1160#if ENABLE_FEATURE_SEAMLESS_GZ || ENABLE_FEATURE_SEAMLESS_BZ2 1144#if SEAMLESS_COMPRESSION
1161 int zipMode = 0; 1145 const char *zipMode = NULL;
1162 if (ENABLE_FEATURE_SEAMLESS_GZ && (opt & OPT_GZIP)) 1146 if (opt & OPT_COMPRESS)
1163 zipMode = 1; 1147 zipMode = "compress";
1164 if (ENABLE_FEATURE_SEAMLESS_BZ2 && (opt & OPT_BZIP2)) 1148 if (opt & OPT_GZIP)
1165 zipMode = 2; 1149 zipMode = "gzip";
1150 if (opt & OPT_BZIP2)
1151 zipMode = "bzip2";
1152 if (opt & OPT_LZMA)
1153 zipMode = "lzma";
1154 if (opt & OPT_XZ)
1155 zipMode = "xz";
1166#endif 1156#endif
1167 /* NB: writeTarFile() closes tar_handle->src_fd */ 1157 /* NB: writeTarFile() closes tar_handle->src_fd */
1168 return writeTarFile(tar_handle->src_fd, verboseFlag, 1158 return writeTarFile(tar_handle->src_fd, verboseFlag,
@@ -1173,7 +1163,7 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
1173 } 1163 }
1174 1164
1175 if (opt & OPT_ANY_COMPRESS) { 1165 if (opt & OPT_ANY_COMPRESS) {
1176 USE_FOR_MMU(IF_DESKTOP(long long) int FAST_FUNC (*xformer)(transformer_aux_data_t *aux, int src_fd, int dst_fd);) 1166 USE_FOR_MMU(IF_DESKTOP(long long) int FAST_FUNC (*xformer)(transformer_state_t *xstate);)
1177 USE_FOR_NOMMU(const char *xformer_prog;) 1167 USE_FOR_NOMMU(const char *xformer_prog;)
1178 1168
1179 if (opt & OPT_COMPRESS) 1169 if (opt & OPT_COMPRESS)
@@ -1192,7 +1182,7 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
1192 USE_FOR_MMU(xformer = unpack_xz_stream;) 1182 USE_FOR_MMU(xformer = unpack_xz_stream;)
1193 USE_FOR_NOMMU(xformer_prog = "unxz";) 1183 USE_FOR_NOMMU(xformer_prog = "unxz";)
1194 1184
1195 open_transformer_with_sig(tar_handle->src_fd, xformer, xformer_prog); 1185 fork_transformer_with_sig(tar_handle->src_fd, xformer, xformer_prog);
1196 /* Can't lseek over pipes */ 1186 /* Can't lseek over pipes */
1197 tar_handle->seek = seek_by_read; 1187 tar_handle->seek = seek_by_read;
1198 /*tar_handle->offset = 0; - already is */ 1188 /*tar_handle->offset = 0; - already is */