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