aboutsummaryrefslogtreecommitdiff
path: root/findutils/xargs.c
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2007-04-09 21:32:30 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2007-04-09 21:32:30 +0000
commitcd7001f7055c3fc2d6298ab9e3befe91e951c652 (patch)
treeb9509ed21e0a7af26128b796a66a3294ae4dc5b0 /findutils/xargs.c
parent1b4b2cb20e5291c319ce0c7721e64445e2749b10 (diff)
downloadbusybox-cd7001f7055c3fc2d6298ab9e3befe91e951c652.tar.gz
factor out NOFORK/NOEXEC code from find. Use it for xargs too.
Diffstat (limited to 'findutils/xargs.c')
-rw-r--r--findutils/xargs.c35
1 files changed, 10 insertions, 25 deletions
diff --git a/findutils/xargs.c b/findutils/xargs.c
index ea7c22060..b4dd9f876 100644
--- a/findutils/xargs.c
+++ b/findutils/xargs.c
@@ -48,47 +48,32 @@
This function has special algorithm.
Don't use fork and include to main!
*/
-static int xargs_exec(char *const *args)
+static int xargs_exec(char **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 */
- BB_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;
+ status = spawn_and_wait(args);
+ if (status < 0) {
bb_perror_msg("%s", args[0]);
- return exec_errno == ENOENT ? 127 : 126;
+ return errno == ENOENT ? 127 : 126;
}
- if (WEXITSTATUS(status) == 255) {
+ if (status == 255) {
bb_error_msg("%s: exited with status 255; aborting", args[0]);
return 124;
}
+/* Huh? I think we won't see this, ever. We don't wait with WUNTRACED!
if (WIFSTOPPED(status)) {
bb_error_msg("%s: stopped by signal %d",
args[0], WSTOPSIG(status));
return 125;
}
- if (WIFSIGNALED(status)) {
+*/
+ if (status >= 1000) {
bb_error_msg("%s: terminated by signal %d",
- args[0], WTERMSIG(status));
+ args[0], status - 1000);
return 125;
}
- if (WEXITSTATUS(status))
+ if (status)
return 123;
return 0;
}