Mirror of git://git.busybox.net/busybox with our patches on top
Source
xxxxxxxxxx
static xlist_t *process0_stdin(xlist_t * list_arg, const char *eof_str ATTRIBUTE_UNUSED,
/* vi: set sw=4 ts=4: */
/*
* Mini xargs implementation for busybox
* Options are supported: "-prtx -n max_arg -s max_chars -e[ouf_str]"
*
* (C) 2002,2003 by Vladimir Oleynik <dzo@simtreas.ru>
*
* Special thanks
* - Mark Whitley and Glenn McGrath for stimulus to rewrite :)
* - Mike Rendell <michael@cs.mun.ca>
* and David MacKenzie <djm@gnu.ai.mit.edu>.
*
* Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
*
* xargs is described in the Single Unix Specification v3 at
* http://www.opengroup.org/onlinepubs/007904975/utilities/xargs.html
*
*/
/* COMPAT: SYSV version defaults size (and has a max value of) to 470.
We try to make it as large as possible. */
/*
This function has special algorithm.
Don't use fork and include to main!
*/
static int xargs_exec(char *const *args)
{
pid_t p;
volatile int exec_errno = 0; /* shared vfork stack */
int status;
p = vfork();
if (p < 0)
bb_perror_msg_and_die("vfork");
if (p == 0) {
/* vfork -- child */
execvp(args[0], args);
exec_errno = errno; /* set error to shared stack */
_exit(1);
}
/* vfork -- parent */
while (wait(&status) == (pid_t) -1)
if (errno != EINTR)
break;
if (exec_errno) {
errno = exec_errno;
bb_perror_msg("%s", args[0]);
return exec_errno == ENOENT ? 127 : 126;
}
if (WEXITSTATUS(status) == 255) {
bb_error_msg("%s: exited with status 255; aborting", args[0]);
return 124;
}
if (WIFSTOPPED(status)) {
bb_error_msg("%s: stopped by signal %d",
args[0], WSTOPSIG(status));
return 125;
}
if (WIFSIGNALED(status)) {
bb_error_msg("%s: terminated by signal %d",
args[0], WTERMSIG(status));
return 125;
}
if (WEXITSTATUS(status))
return 123;