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
|
|
|
/*
|
|
|
|
* On MMU machine, the transform_prog and ... are stripped
|
|
|
|
* by a macro in include/unarchive.h. On NOMMU, transformer is stripped.
|
|
|
|
*/
|
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),
|
|
|
|
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) {
|
2007-09-05 17:18:32 +05:30
|
|
|
#if !BB_MMU
|
|
|
|
va_list ap;
|
|
|
|
#endif
|
2003-11-16 04:49:05 +05:30
|
|
|
/* child process */
|
2006-10-14 07:53:43 +05:30
|
|
|
close(fd_pipe[0]); /* We don't wan't to read from the parent */
|
|
|
|
// 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
|
|
|
|
xmove_fd(src_fd, 0);
|
|
|
|
xmove_fd(fd_pipe[1], 1);
|
|
|
|
va_start(ap, transform_prog);
|
2007-09-09 16:50:55 +05:30
|
|
|
/* hoping that va_list -> char** on our CPU is working... */
|
|
|
|
BB_EXECVP(transform_prog, (void*)ap);
|
|
|
|
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
|
|
|
}
|