2006-07-03 01:17:05 +05:30
|
|
|
/* vi: set sw=4 ts=4: */
|
2003-11-16 04:49:05 +05:30
|
|
|
/*
|
2006-04-03 03:20:01 +05:30
|
|
|
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
2003-11-16 04:49:05 +05:30
|
|
|
*/
|
|
|
|
|
|
|
|
#include "libbb.h"
|
2006-04-03 03:20:01 +05:30
|
|
|
#include "unarchive.h"
|
|
|
|
|
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
|
|
|
|
* in include/unarchive.h. On NOMMU, transformer is removed.
|
2007-09-05 17:18:32 +05:30
|
|
|
*/
|
2006-10-01 21:25:11 +05:30
|
|
|
int open_transformer(int src_fd,
|
2007-09-05 17:18:32 +05:30
|
|
|
USE_DESKTOP(long long) int (*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
|
|
|
{
|
|
|
|
int fd_pipe[2];
|
|
|
|
int pid;
|
|
|
|
|
2007-05-26 22:14:20 +05:30
|
|
|
xpipe(fd_pipe);
|
2003-11-16 04:49:05 +05:30
|
|
|
|
2007-09-05 17:18:32 +05:30
|
|
|
#if BB_MMU
|
2003-11-16 04:49:05 +05:30
|
|
|
pid = fork();
|
2007-09-05 17:18:32 +05:30
|
|
|
#else
|
|
|
|
pid = vfork();
|
|
|
|
#endif
|
|
|
|
if (pid == -1)
|
2006-10-14 07:53:43 +05:30
|
|
|
bb_perror_msg_and_die("fork failed");
|
2003-11-16 04:49:05 +05:30
|
|
|
|
|
|
|
if (pid == 0) {
|
|
|
|
/* child process */
|
2008-01-29 04:15:43 +05:30
|
|
|
close(fd_pipe[0]); /* 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
|
2006-10-14 07:53:43 +05:30
|
|
|
transformer(src_fd, fd_pipe[1]);
|
2007-09-05 01:03:22 +05:30
|
|
|
if (ENABLE_FEATURE_CLEAN_UP) {
|
|
|
|
close(fd_pipe[1]); /* Send EOF */
|
|
|
|
close(src_fd);
|
|
|
|
}
|
2006-10-14 07:53:43 +05:30
|
|
|
exit(0);
|
2007-09-05 17:18:32 +05:30
|
|
|
#else
|
2007-11-12 07:43:12 +05:30
|
|
|
{
|
|
|
|
char *argv[4];
|
|
|
|
xmove_fd(src_fd, 0);
|
|
|
|
xmove_fd(fd_pipe[1], 1);
|
|
|
|
argv[0] = (char*)transform_prog;
|
|
|
|
argv[1] = (char*)"-cf";
|
|
|
|
argv[2] = (char*)"-";
|
|
|
|
argv[3] = NULL;
|
|
|
|
BB_EXECVP(transform_prog, argv);
|
|
|
|
bb_perror_msg_and_die("exec failed");
|
|
|
|
}
|
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 */
|
2003-11-19 03:01:19 +05:30
|
|
|
close(fd_pipe[1]); /* Don't want to write to the child */
|
2003-11-16 04:49:05 +05:30
|
|
|
|
2006-10-01 21:25:11 +05:30
|
|
|
return fd_pipe[0];
|
2003-11-16 04:49:05 +05:30
|
|
|
}
|