Annotation of /trunk/mkinitrd-magellan/busybox/archival/libunarchive/open_transformer.c
Parent Directory | Revision Log
Revision 816 -
(hide annotations)
(download)
Fri Apr 24 18:33:46 2009 UTC (15 years ago) by niro
File MIME type: text/plain
File size: 1456 byte(s)
Fri Apr 24 18:33:46 2009 UTC (15 years ago) by niro
File MIME type: text/plain
File size: 1456 byte(s)
-updated to busybox-1.13.4
1 | niro | 532 | /* vi: set sw=4 ts=4: */ |
2 | /* | ||
3 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. | ||
4 | */ | ||
5 | |||
6 | #include "libbb.h" | ||
7 | #include "unarchive.h" | ||
8 | |||
9 | /* transformer(), more than meets the eye */ | ||
10 | niro | 816 | /* |
11 | * On MMU machine, the transform_prog is removed by macro magic | ||
12 | * in include/unarchive.h. On NOMMU, transformer is removed. | ||
13 | */ | ||
14 | void FAST_FUNC open_transformer(int fd, | ||
15 | USE_DESKTOP(long long) int FAST_FUNC (*transformer)(int src_fd, int dst_fd), | ||
16 | const char *transform_prog) | ||
17 | niro | 532 | { |
18 | niro | 816 | struct fd_pair fd_pipe; |
19 | niro | 532 | int pid; |
20 | |||
21 | niro | 816 | xpiped_pair(fd_pipe); |
22 | niro | 532 | |
23 | niro | 816 | #if BB_MMU |
24 | niro | 532 | pid = fork(); |
25 | niro | 816 | if (pid == -1) |
26 | bb_perror_msg_and_die("vfork" + 1); | ||
27 | #else | ||
28 | pid = vfork(); | ||
29 | if (pid == -1) | ||
30 | bb_perror_msg_and_die("vfork"); | ||
31 | #endif | ||
32 | niro | 532 | |
33 | if (pid == 0) { | ||
34 | /* child process */ | ||
35 | niro | 816 | close(fd_pipe.rd); /* we don't want to read from the parent */ |
36 | niro | 532 | // FIXME: error check? |
37 | niro | 816 | #if BB_MMU |
38 | transformer(fd, fd_pipe.wr); | ||
39 | if (ENABLE_FEATURE_CLEAN_UP) { | ||
40 | close(fd_pipe.wr); /* send EOF */ | ||
41 | close(fd); | ||
42 | } | ||
43 | /* must be _exit! bug was actually seen here */ | ||
44 | _exit(EXIT_SUCCESS); | ||
45 | #else | ||
46 | { | ||
47 | char *argv[4]; | ||
48 | xmove_fd(fd, 0); | ||
49 | xmove_fd(fd_pipe.wr, 1); | ||
50 | argv[0] = (char*)transform_prog; | ||
51 | argv[1] = (char*)"-cf"; | ||
52 | argv[2] = (char*)"-"; | ||
53 | argv[3] = NULL; | ||
54 | BB_EXECVP(transform_prog, argv); | ||
55 | bb_perror_msg_and_die("can't exec %s", transform_prog); | ||
56 | } | ||
57 | #endif | ||
58 | niro | 532 | /* notreached */ |
59 | } | ||
60 | |||
61 | /* parent process */ | ||
62 | niro | 816 | close(fd_pipe.wr); /* don't want to write to the child */ |
63 | xmove_fd(fd_pipe.rd, fd); | ||
64 | niro | 532 | } |