Magellan Linux

Annotation of /trunk/mkinitrd-magellan/busybox/archival/libunarchive/open_transformer.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1123 - (hide annotations) (download)
Wed Aug 18 21:56:57 2010 UTC (13 years, 8 months ago) by niro
File MIME type: text/plain
File size: 1327 byte(s)
-updated to busybox-1.17.1
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 niro 984 IF_DESKTOP(long long) int FAST_FUNC (*transformer)(int src_fd, int dst_fd),
16 niro 816 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 1123 pid = BB_MMU ? xfork() : xvfork();
23 niro 532 if (pid == 0) {
24 niro 1123 /* Child */
25 niro 816 close(fd_pipe.rd); /* we don't want to read from the parent */
26 niro 532 // FIXME: error check?
27 niro 816 #if BB_MMU
28     transformer(fd, fd_pipe.wr);
29     if (ENABLE_FEATURE_CLEAN_UP) {
30     close(fd_pipe.wr); /* send EOF */
31     close(fd);
32     }
33     /* must be _exit! bug was actually seen here */
34     _exit(EXIT_SUCCESS);
35     #else
36     {
37     char *argv[4];
38     xmove_fd(fd, 0);
39     xmove_fd(fd_pipe.wr, 1);
40     argv[0] = (char*)transform_prog;
41     argv[1] = (char*)"-cf";
42     argv[2] = (char*)"-";
43     argv[3] = NULL;
44     BB_EXECVP(transform_prog, argv);
45 niro 984 bb_perror_msg_and_die("can't execute '%s'", transform_prog);
46 niro 816 }
47     #endif
48 niro 532 /* notreached */
49     }
50    
51     /* parent process */
52 niro 816 close(fd_pipe.wr); /* don't want to write to the child */
53     xmove_fd(fd_pipe.rd, fd);
54 niro 532 }