aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGlenn L McGrath <bug1@ihug.co.nz>2002-11-19 08:22:03 +0000
committerGlenn L McGrath <bug1@ihug.co.nz>2002-11-19 08:22:03 +0000
commita0d395eac9c7f8c6db288df5b345146a7da4977b (patch)
treea9738dfb95c7945f8c065436e0f96d54ae5354c4
parentae01fa99e1726ecc0b69d66c1bbdbf72694e969e (diff)
downloadbusybox-w32-a0d395eac9c7f8c6db288df5b345146a7da4977b.tar.gz
busybox-w32-a0d395eac9c7f8c6db288df5b345146a7da4977b.tar.bz2
busybox-w32-a0d395eac9c7f8c6db288df5b345146a7da4977b.zip
Use read_gz, remove fork() woohoo!
-rw-r--r--archival/libunarchive/get_header_tar_gz.c53
1 files changed, 9 insertions, 44 deletions
diff --git a/archival/libunarchive/get_header_tar_gz.c b/archival/libunarchive/get_header_tar_gz.c
index f77b775d3..a4355d24c 100644
--- a/archival/libunarchive/get_header_tar_gz.c
+++ b/archival/libunarchive/get_header_tar_gz.c
@@ -14,25 +14,15 @@
14 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 14 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
15 */ 15 */
16 16
17#include <sys/types.h>
18#include <signal.h>
19#include <stdio.h>
20#include <stdlib.h> 17#include <stdlib.h>
21#include <string.h> 18
22#include <unistd.h>
23#include "libbb.h" 19#include "libbb.h"
24#include "unarchive.h" 20#include "unarchive.h"
25 21
26extern char get_header_tar_gz(archive_handle_t *archive_handle) 22extern char get_header_tar_gz(archive_handle_t *archive_handle)
27{ 23{
28 int fd_pipe[2];
29 int pid;
30 unsigned char magic[2]; 24 unsigned char magic[2];
31 25
32 /* Cant lseek over pipe's */
33 archive_handle->read = read;
34 archive_handle->seek = seek_by_char;
35
36 archive_xread_all(archive_handle, &magic, 2); 26 archive_xread_all(archive_handle, &magic, 2);
37 if ((magic[0] != 0x1f) || (magic[1] != 0x8b)) { 27 if ((magic[0] != 0x1f) || (magic[1] != 0x8b)) {
38 error_msg_and_die("Invalid gzip magic"); 28 error_msg_and_die("Invalid gzip magic");
@@ -40,45 +30,20 @@ extern char get_header_tar_gz(archive_handle_t *archive_handle)
40 30
41 check_header_gzip(archive_handle->src_fd); 31 check_header_gzip(archive_handle->src_fd);
42 32
43 if (pipe(fd_pipe) != 0) { 33 GZ_gzReadOpen(archive_handle->src_fd, 0, 0);
44 error_msg_and_die("Can't create pipe");
45 }
46 34
47 pid = fork(); 35 archive_handle->read = read_gz;
48 if (pid == -1) { 36 archive_handle->seek = seek_by_char;
49 error_msg_and_die("Fork failed\n");
50 }
51
52 if (pid == 0) {
53 /* child process */
54 close(fd_pipe[0]); /* We don't wan't to read from the pipe */
55 inflate(archive_handle->src_fd, fd_pipe[1]);
56 check_trailer_gzip(archive_handle->src_fd);
57 close(fd_pipe[1]); /* Send EOF */
58 exit(0);
59 /* notreached */
60 }
61 /* parent process */
62 close(fd_pipe[1]); /* Don't want to write down the pipe */
63 close(archive_handle->src_fd);
64
65 archive_handle->src_fd = fd_pipe[0];
66 37
67 archive_handle->offset = 0; 38 archive_handle->offset = 0;
68 while (get_header_tar(archive_handle) == EXIT_SUCCESS); 39 while (get_header_tar(archive_handle) == EXIT_SUCCESS);
69 40
70 if (kill(pid, SIGTERM) == -1) { 41 /* Cleanup */
71 error_msg_and_die("Couldnt kill gunzip process"); 42 GZ_gzReadClose();
72 }
73
74 /* I dont think this is needed */
75#if 0
76 if (waitpid(pid, NULL, 0) == -1) {
77 error_msg("Couldnt wait ?");
78 }
79#endif
80 43
81 /* Can only do one file at a time */ 44 check_trailer_gzip(archive_handle->src_fd);
45
46 /* Can only do one tar.bz2 per archive */
82 return(EXIT_FAILURE); 47 return(EXIT_FAILURE);
83} 48}
84 49