From cd7001f7055c3fc2d6298ab9e3befe91e951c652 Mon Sep 17 00:00:00 2001 From: Denis Vlasenko Date: Mon, 9 Apr 2007 21:32:30 +0000 Subject: factor out NOFORK/NOEXEC code from find. Use it for xargs too. --- findutils/xargs.c | 35 ++++++++++------------------------- 1 file changed, 10 insertions(+), 25 deletions(-) (limited to 'findutils/xargs.c') 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; } -- cgit v1.2.3