2006-07-02 19:47:05 +00:00
|
|
|
/* vi: set sw=4 ts=4: */
|
2003-11-15 23:19:05 +00:00
|
|
|
/*
|
2006-04-02 21:50:01 +00:00
|
|
|
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
2003-11-15 23:19:05 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "libbb.h"
|
2006-04-02 21:50:01 +00:00
|
|
|
#include "unarchive.h"
|
|
|
|
|
2003-11-15 23:19:05 +00:00
|
|
|
/* transformer(), more than meets the eye */
|
2007-09-05 11:48:32 +00:00
|
|
|
/*
|
2007-11-12 02:13:12 +00:00
|
|
|
* On MMU machine, the transform_prog is removed by macro magic
|
|
|
|
* in include/unarchive.h. On NOMMU, transformer is removed.
|
2007-09-05 11:48:32 +00:00
|
|
|
*/
|
2008-07-10 17:43:01 +00:00
|
|
|
void FAST_FUNC open_transformer(int fd,
|
2009-04-21 11:09:40 +00:00
|
|
|
IF_DESKTOP(long long) int FAST_FUNC (*transformer)(int src_fd, int dst_fd),
|
2007-11-12 02:13:12 +00:00
|
|
|
const char *transform_prog)
|
2003-11-15 23:19:05 +00:00
|
|
|
{
|
2008-02-16 13:20:56 +00:00
|
|
|
struct fd_pair fd_pipe;
|
2003-11-15 23:19:05 +00:00
|
|
|
int pid;
|
|
|
|
|
2008-02-16 13:20:56 +00:00
|
|
|
xpiped_pair(fd_pipe);
|
2010-07-04 13:32:38 +00:00
|
|
|
pid = BB_MMU ? xfork() : xvfork();
|
2003-11-15 23:19:05 +00:00
|
|
|
if (pid == 0) {
|
2010-07-04 13:32:38 +00:00
|
|
|
/* Child */
|
2008-07-10 17:43:01 +00:00
|
|
|
close(fd_pipe.rd); /* we don't want to read from the parent */
|
2006-10-14 02:23:43 +00:00
|
|
|
// FIXME: error check?
|
2007-09-05 11:48:32 +00:00
|
|
|
#if BB_MMU
|
2008-07-10 17:43:01 +00:00
|
|
|
transformer(fd, fd_pipe.wr);
|
2007-09-04 19:33:22 +00:00
|
|
|
if (ENABLE_FEATURE_CLEAN_UP) {
|
2008-07-10 17:43:01 +00:00
|
|
|
close(fd_pipe.wr); /* send EOF */
|
|
|
|
close(fd);
|
2007-09-04 19:33:22 +00:00
|
|
|
}
|
2008-06-26 03:26:57 +00:00
|
|
|
/* must be _exit! bug was actually seen here */
|
|
|
|
_exit(EXIT_SUCCESS);
|
2007-09-05 11:48:32 +00:00
|
|
|
#else
|
2007-11-12 02:13:12 +00:00
|
|
|
{
|
|
|
|
char *argv[4];
|
2008-07-10 17:43:01 +00:00
|
|
|
xmove_fd(fd, 0);
|
2008-02-16 13:20:56 +00:00
|
|
|
xmove_fd(fd_pipe.wr, 1);
|
2007-11-12 02:13:12 +00:00
|
|
|
argv[0] = (char*)transform_prog;
|
|
|
|
argv[1] = (char*)"-cf";
|
|
|
|
argv[2] = (char*)"-";
|
|
|
|
argv[3] = NULL;
|
|
|
|
BB_EXECVP(transform_prog, argv);
|
2009-04-21 20:40:51 +00:00
|
|
|
bb_perror_msg_and_die("can't execute '%s'", transform_prog);
|
2007-11-12 02:13:12 +00:00
|
|
|
}
|
2007-09-05 11:48:32 +00:00
|
|
|
#endif
|
2006-10-14 02:23:43 +00:00
|
|
|
/* notreached */
|
2003-11-15 23:19:05 +00:00
|
|
|
}
|
2003-11-18 21:31:19 +00:00
|
|
|
|
2003-11-15 23:19:05 +00:00
|
|
|
/* parent process */
|
2008-07-10 17:43:01 +00:00
|
|
|
close(fd_pipe.wr); /* don't want to write to the child */
|
|
|
|
xmove_fd(fd_pipe.rd, fd);
|
2003-11-15 23:19:05 +00:00
|
|
|
}
|