1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
|
diff -urN busybox-1.7.0/archival/bbunzip.c busybox-1.7.0-targz_nommu/archival/bbunzip.c
--- busybox-1.7.0/archival/bbunzip.c 2007-08-24 11:49:45.000000000 +0100
+++ busybox-1.7.0-targz_nommu/archival/bbunzip.c 2007-09-06 17:42:02.000000000 +0100
@@ -298,7 +298,7 @@
int unlzma_main(int argc, char **argv);
int unlzma_main(int argc, char **argv)
{
- getopt32(argv, "c");
+ getopt32(argv, "cf");
argv += optind;
/* lzmacat? */
if (applet_name[4] == 'c')
diff -urN busybox-1.7.0/archival/libunarchive/Kbuild busybox-1.7.0-targz_nommu/archival/libunarchive/Kbuild
--- busybox-1.7.0/archival/libunarchive/Kbuild 2007-08-24 11:49:45.000000000 +0100
+++ busybox-1.7.0-targz_nommu/archival/libunarchive/Kbuild 2007-09-06 17:42:02.000000000 +0100
@@ -35,36 +35,34 @@
get_header_tar.o \
filter_accept_list_reassign.o
-# open_transformer uses fork(). Compile it only if absolutely necessary
lib-$(CONFIG_RPM) += open_transformer.o
-lib-$(CONFIG_FEATURE_TAR_BZIP2) += open_transformer.o
-lib-$(CONFIG_FEATURE_TAR_LZMA) += open_transformer.o
-lib-$(CONFIG_FEATURE_TAR_GZIP) += open_transformer.o
-lib-$(CONFIG_FEATURE_TAR_COMPRESS) += open_transformer.o
-lib-$(CONFIG_FEATURE_DEB_TAR_GZ) += open_transformer.o
-lib-$(CONFIG_FEATURE_DEB_TAR_BZ2) += open_transformer.o
-lib-$(CONFIG_FEATURE_DEB_TAR_LZMA) += open_transformer.o
-
-lib-$(CONFIG_AR) += get_header_ar.o unpack_ar_archive.o
-lib-$(CONFIG_BUNZIP2) += decompress_bunzip2.o
-lib-$(CONFIG_UNLZMA) += decompress_unlzma.o
-lib-$(CONFIG_CPIO) += get_header_cpio.o
-lib-$(CONFIG_DPKG) += $(DPKG_FILES)
-lib-$(CONFIG_DPKG_DEB) += $(DPKG_FILES)
-lib-$(CONFIG_FEATURE_DEB_TAR_GZ) += $(GUNZIP_FILES) get_header_tar_gz.o
-lib-$(CONFIG_FEATURE_DEB_TAR_BZ2) += decompress_bunzip2.o get_header_tar_bz2.o
-lib-$(CONFIG_FEATURE_DEB_TAR_LZMA) += decompress_unlzma.o get_header_tar_lzma.o
-lib-$(CONFIG_GUNZIP) += $(GUNZIP_FILES)
-lib-$(CONFIG_FEATURE_GUNZIP_UNCOMPRESS) += decompress_uncompress.o
-lib-$(CONFIG_RPM2CPIO) += $(GUNZIP_FILES) get_header_cpio.o
-lib-$(CONFIG_RPM) += $(GUNZIP_FILES) get_header_cpio.o
-lib-$(CONFIG_FEATURE_RPM_BZ2) += decompress_bunzip2.o
-lib-$(CONFIG_TAR) += get_header_tar.o
-lib-$(CONFIG_FEATURE_TAR_BZIP2) += decompress_bunzip2.o get_header_tar_bz2.o
-lib-$(CONFIG_FEATURE_TAR_LZMA) += decompress_unlzma.o get_header_tar_lzma.o
-lib-$(CONFIG_FEATURE_TAR_GZIP) += $(GUNZIP_FILES) get_header_tar_gz.o
-lib-$(CONFIG_FEATURE_TAR_COMPRESS) += decompress_uncompress.o
-lib-$(CONFIG_UNCOMPRESS) += decompress_uncompress.o
-lib-$(CONFIG_UNZIP) += $(GUNZIP_FILES)
-lib-$(CONFIG_FEATURE_COMPRESS_USAGE) += decompress_bunzip2.o
+lib-$(CONFIG_FEATURE_TAR_BZIP2) += open_transformer.o
+lib-$(CONFIG_FEATURE_TAR_LZMA) += open_transformer.o
+lib-$(CONFIG_FEATURE_TAR_GZIP) += open_transformer.o
+lib-$(CONFIG_FEATURE_TAR_COMPRESS) += open_transformer.o
+lib-$(CONFIG_FEATURE_DEB_TAR_GZ) += open_transformer.o
+lib-$(CONFIG_FEATURE_DEB_TAR_BZ2) += open_transformer.o
+lib-$(CONFIG_FEATURE_DEB_TAR_LZMA) += open_transformer.o
+lib-$(CONFIG_AR) += get_header_ar.o unpack_ar_archive.o
+lib-$(CONFIG_BUNZIP2) += decompress_bunzip2.o
+lib-$(CONFIG_UNLZMA) += decompress_unlzma.o
+lib-$(CONFIG_CPIO) += get_header_cpio.o
+lib-$(CONFIG_DPKG) += $(DPKG_FILES)
+lib-$(CONFIG_DPKG_DEB) += $(DPKG_FILES)
+lib-$(CONFIG_FEATURE_DEB_TAR_GZ) += $(GUNZIP_FILES) get_header_tar_gz.o
+lib-$(CONFIG_FEATURE_DEB_TAR_BZ2) += decompress_bunzip2.o get_header_tar_bz2.o
+lib-$(CONFIG_FEATURE_DEB_TAR_LZMA) += decompress_unlzma.o get_header_tar_lzma.o
+lib-$(CONFIG_GUNZIP) += $(GUNZIP_FILES)
+lib-$(CONFIG_FEATURE_GUNZIP_UNCOMPRESS) += decompress_uncompress.o
+lib-$(CONFIG_RPM2CPIO) += $(GUNZIP_FILES) get_header_cpio.o
+lib-$(CONFIG_RPM) += $(GUNZIP_FILES) get_header_cpio.o
+lib-$(CONFIG_FEATURE_RPM_BZ2) += decompress_bunzip2.o
+lib-$(CONFIG_TAR) += get_header_tar.o
+lib-$(CONFIG_FEATURE_TAR_BZIP2) += decompress_bunzip2.o get_header_tar_bz2.o
+lib-$(CONFIG_FEATURE_TAR_LZMA) += decompress_unlzma.o get_header_tar_lzma.o
+lib-$(CONFIG_FEATURE_TAR_GZIP) += $(GUNZIP_FILES) get_header_tar_gz.o
+lib-$(CONFIG_FEATURE_TAR_COMPRESS) += decompress_uncompress.o
+lib-$(CONFIG_UNCOMPRESS) += decompress_uncompress.o
+lib-$(CONFIG_UNZIP) += $(GUNZIP_FILES)
+lib-$(CONFIG_FEATURE_COMPRESS_USAGE) += decompress_bunzip2.o
diff -urN busybox-1.7.0/archival/libunarchive/get_header_tar_bz2.c busybox-1.7.0-targz_nommu/archival/libunarchive/get_header_tar_bz2.c
--- busybox-1.7.0/archival/libunarchive/get_header_tar_bz2.c 2007-08-24 11:49:45.000000000 +0100
+++ busybox-1.7.0-targz_nommu/archival/libunarchive/get_header_tar_bz2.c 2007-09-06 17:42:02.000000000 +0100
@@ -11,7 +11,7 @@
/* Can't lseek over pipes */
archive_handle->seek = seek_by_read;
- archive_handle->src_fd = open_transformer(archive_handle->src_fd, unpack_bz2_stream);
+ archive_handle->src_fd = open_transformer(archive_handle->src_fd, unpack_bz2_stream, "bunzip2", "bunzip2", "-cf", "-", NULL);
archive_handle->offset = 0;
while (get_header_tar(archive_handle) == EXIT_SUCCESS) /**/;
diff -urN busybox-1.7.0/archival/libunarchive/get_header_tar_gz.c busybox-1.7.0-targz_nommu/archival/libunarchive/get_header_tar_gz.c
--- busybox-1.7.0/archival/libunarchive/get_header_tar_gz.c 2007-08-24 11:49:45.000000000 +0100
+++ busybox-1.7.0-targz_nommu/archival/libunarchive/get_header_tar_gz.c 2007-09-06 17:42:02.000000000 +0100
@@ -8,19 +8,26 @@
char get_header_tar_gz(archive_handle_t *archive_handle)
{
+#if BB_MMU
unsigned char magic[2];
+#endif
/* Can't lseek over pipes */
archive_handle->seek = seek_by_read;
+ /* Check gzip magic only if open_transformer will invoke unpack_gz_stream (MMU case).
+ * Otherwise, it will invoke an external helper "gunzip -cf" (NOMMU case) which will
+ * need the header. */
+#if BB_MMU
xread(archive_handle->src_fd, &magic, 2);
if ((magic[0] != 0x1f) || (magic[1] != 0x8b)) {
bb_error_msg_and_die("invalid gzip magic");
}
check_header_gzip_or_die(archive_handle->src_fd);
+#endif
- archive_handle->src_fd = open_transformer(archive_handle->src_fd, unpack_gz_stream);
+ archive_handle->src_fd = open_transformer(archive_handle->src_fd, unpack_gz_stream, "gunzip", "gunzip", "-cf", "-", NULL);
archive_handle->offset = 0;
while (get_header_tar(archive_handle) == EXIT_SUCCESS) /**/;
diff -urN busybox-1.7.0/archival/libunarchive/get_header_tar_lzma.c busybox-1.7.0-targz_nommu/archival/libunarchive/get_header_tar_lzma.c
--- busybox-1.7.0/archival/libunarchive/get_header_tar_lzma.c 2007-08-24 11:49:45.000000000 +0100
+++ busybox-1.7.0-targz_nommu/archival/libunarchive/get_header_tar_lzma.c 2007-09-06 17:42:02.000000000 +0100
@@ -14,7 +14,7 @@
/* Can't lseek over pipes */
archive_handle->seek = seek_by_read;
- archive_handle->src_fd = open_transformer(archive_handle->src_fd, unpack_lzma_stream);
+ archive_handle->src_fd = open_transformer(archive_handle->src_fd, unpack_lzma_stream, "unlzma", "unlzma", "-cf", "-", NULL);
archive_handle->offset = 0;
while (get_header_tar(archive_handle) == EXIT_SUCCESS) /**/;
diff -urN busybox-1.7.0/archival/libunarchive/open_transformer.c busybox-1.7.0-targz_nommu/archival/libunarchive/open_transformer.c
--- busybox-1.7.0/archival/libunarchive/open_transformer.c 2007-08-24 11:49:45.000000000 +0100
+++ busybox-1.7.0-targz_nommu/archival/libunarchive/open_transformer.c 2007-09-05 12:28:55.000000000 +0100
@@ -7,27 +7,48 @@
#include "unarchive.h"
/* transformer(), more than meets the eye */
+/*
+ * On MMU machine, the transform_prog and ... are stripped
+ * by a macro in include/unarchive.h. On NOMMU, transformer is stripped.
+ */
int open_transformer(int src_fd,
- USE_DESKTOP(long long) int (*transformer)(int src_fd, int dst_fd))
+ USE_DESKTOP(long long) int (*transformer)(int src_fd, int dst_fd),
+ const char *transform_prog, ...)
{
int fd_pipe[2];
int pid;
xpipe(fd_pipe);
+#if BB_MMU
pid = fork();
- if (pid == -1) {
+#else
+ pid = vfork();
+#endif
+ if (pid == -1)
bb_perror_msg_and_die("fork failed");
- }
if (pid == 0) {
+#if !BB_MMU
+ va_list ap;
+#endif
/* child process */
close(fd_pipe[0]); /* We don't wan't to read from the parent */
// FIXME: error check?
+#if BB_MMU
transformer(src_fd, fd_pipe[1]);
- close(fd_pipe[1]); /* Send EOF */
- close(src_fd);
+ if (ENABLE_FEATURE_CLEAN_UP) {
+ close(fd_pipe[1]); /* Send EOF */
+ close(src_fd);
+ }
exit(0);
+#else
+ xmove_fd(src_fd, 0);
+ xmove_fd(fd_pipe[1], 1);
+ va_start(ap, transform_prog);
+ BB_EXECVP(transform_prog, ap);
+ bb_perror_and_die("exec failed");
+#endif
/* notreached */
}
diff -urN busybox-1.7.0/archival/rpm.c busybox-1.7.0-targz_nommu/archival/rpm.c
--- busybox-1.7.0/archival/rpm.c 2007-08-24 11:49:45.000000000 +0100
+++ busybox-1.7.0-targz_nommu/archival/rpm.c 2007-09-06 17:42:02.000000000 +0100
@@ -187,9 +187,15 @@
static void extract_cpio_gz(int fd)
{
- USE_DESKTOP(long long) int (*xformer)(int src_fd, int dst_fd);
archive_handle_t *archive_handle;
unsigned char magic[2];
+#if BB_MMU
+ USE_DESKTOP(long long) int (*xformer)(int src_fd, int dst_fd);
+ enum { xformer_prog = 0 };
+#else
+ enum { xformer = 0 };
+ const char *xformer_prog;
+#endif
/* Initialize */
archive_handle = init_handle();
@@ -202,11 +208,19 @@
archive_handle->offset = 0;
xread(archive_handle->src_fd, &magic, 2);
+#if BB_MMU
xformer = unpack_gz_stream;
+#else
+ xformer_prog = "gunzip";
+#endif
if ((magic[0] != 0x1f) || (magic[1] != 0x8b)) {
if (ENABLE_FEATURE_RPM_BZ2
&& (magic[0] == 0x42) && (magic[1] == 0x5a)) {
+#if BB_MMU
xformer = unpack_bz2_stream;
+#else
+ xformer_prog = "bunzip2";
+#endif
/* We can do better, need modifying unpack_bz2_stream to not require
* first 2 bytes. Not very hard to do... I mean, TODO :) */
xlseek(archive_handle->src_fd, -2, SEEK_CUR);
@@ -214,11 +228,17 @@
bb_error_msg_and_die("no gzip"
USE_FEATURE_RPM_BZ2("/bzip")
" magic");
- } else
+ } else {
check_header_gzip_or_die(archive_handle->src_fd);
+#if !BB_MMU
+ /* NOMMU version of open_transformer execs an external unzipper that should
+ * have the file position at the start of the file */
+ xlseek(archive_handle->src_fd, 0, SEEK_SET);
+#endif
+ }
xchdir("/"); /* Install RPM's to root */
- archive_handle->src_fd = open_transformer(archive_handle->src_fd, xformer);
+ archive_handle->src_fd = open_transformer(archive_handle->src_fd, xformer, xformer_prog, xformer_prog, "-cf", "-", NULL);
archive_handle->offset = 0;
while (get_header_cpio(archive_handle) == EXIT_SUCCESS)
continue;
diff -urN busybox-1.7.0/archival/tar.c busybox-1.7.0-targz_nommu/archival/tar.c
--- busybox-1.7.0/archival/tar.c 2007-08-24 11:49:45.000000000 +0100
+++ busybox-1.7.0-targz_nommu/archival/tar.c 2007-09-06 17:42:02.000000000 +0100
@@ -648,7 +648,7 @@
bb_error_msg_and_die("invalid magic");
}
- archive_handle->src_fd = open_transformer(archive_handle->src_fd, uncompress);
+ archive_handle->src_fd = open_transformer(archive_handle->src_fd, uncompress, "uncompress", "uncompress", "-cf", "-", NULL);
archive_handle->offset = 0;
while (get_header_tar(archive_handle) == EXIT_SUCCESS)
/* nothing */;
diff -urN busybox-1.7.0/include/unarchive.h busybox-1.7.0-targz_nommu/include/unarchive.h
--- busybox-1.7.0/include/unarchive.h 2007-08-24 11:49:55.000000000 +0100
+++ busybox-1.7.0-targz_nommu/include/unarchive.h 2007-09-06 17:42:02.000000000 +0100
@@ -115,7 +115,13 @@
extern USE_DESKTOP(long long) int unpack_gz_stream(int src_fd, int dst_fd);
extern USE_DESKTOP(long long) int unpack_lzma_stream(int src_fd, int dst_fd);
+#if BB_MMU
extern int open_transformer(int src_fd,
USE_DESKTOP(long long) int (*transformer)(int src_fd, int dst_fd));
+#define open_transformer(src_fd, transformer, transform_prog, ...) open_transformer(src_fd, transformer)
+#else
+extern int open_transformer(int src_fd, const char *transform_prog, ...);
+#define open_transformer(src_fd, transformer, transform_prog, ...) open_transformer(src_fd, transform_prog, __VA_ARGS__)
+#endif
#endif
|