diff options
author | des <des@FreeBSD.org> | 2002-03-09 22:08:14 +0000 |
---|---|---|
committer | des <des@FreeBSD.org> | 2002-03-09 22:08:14 +0000 |
commit | 652d870eb8a60cc6778e5714b4ae61fbf1394004 (patch) | |
tree | 0d4590753c77495e6c7159ddba65f69a9665291d /usr.bin/xargs/xargs.c | |
parent | 32b4a85d20db65d58c01d4f0978aa4b6109e7cc7 (diff) | |
download | FreeBSD-src-652d870eb8a60cc6778e5714b4ae61fbf1394004.zip FreeBSD-src-652d870eb8a60cc6778e5714b4ae61fbf1394004.tar.gz |
Change back to using vfork() now that execvp() is vfork()-safe. If execvp()
fails, errno is saved to a volatile variable that the parent later inspects.
PR: bin/34898
Submitted by: Tim J. Robbins <tim@robbins.dropbear.id.au>
MFC after: 1 week
Diffstat (limited to 'usr.bin/xargs/xargs.c')
-rw-r--r-- | usr.bin/xargs/xargs.c | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/usr.bin/xargs/xargs.c b/usr.bin/xargs/xargs.c index 5d3eaa4..1785cc2 100644 --- a/usr.bin/xargs/xargs.c +++ b/usr.bin/xargs/xargs.c @@ -53,6 +53,7 @@ __FBSDID("$FreeBSD$"); #include <sys/wait.h> #include <err.h> +#include <errno.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -297,7 +298,7 @@ void run(argv) char **argv; { - volatile int noinvoke; + volatile int childerr; char **p; pid_t pid; int status; @@ -309,22 +310,24 @@ run(argv) (void)fprintf(stderr, "\n"); (void)fflush(stderr); } - noinvoke = 0; - switch(pid = fork()) { + childerr = 0; + switch(pid = vfork()) { case -1: - err(1, "fork"); + err(1, "vfork"); case 0: execvp(argv[0], argv); - warn("%s", argv[0]); - noinvoke = 1; + childerr = errno; _exit(1); } pid = waitpid(pid, &status, 0); if (pid == -1) err(1, "waitpid"); /* If we couldn't invoke the utility, exit 127. */ - if (noinvoke) + if (childerr != 0) { + errno = childerr; + warn("%s", argv[0]); exit(127); + } /* If utility signaled or exited with a value of 255, exit 1-125. */ if (WIFSIGNALED(status) || WEXITSTATUS(status) == 255) exit(1); |