diff options
author | mux <mux@FreeBSD.org> | 2003-06-13 17:05:41 +0000 |
---|---|---|
committer | mux <mux@FreeBSD.org> | 2003-06-13 17:05:41 +0000 |
commit | 56e414d2aab241f2c990d45c19bf675a78307c43 (patch) | |
tree | a8306e10fb46eeba388e57266c028ee99aa7a93c /usr.bin/xargs | |
parent | bb7ece5c437e60f0e56cc887237adef7756dd0f1 (diff) | |
download | FreeBSD-src-56e414d2aab241f2c990d45c19bf675a78307c43.zip FreeBSD-src-56e414d2aab241f2c990d45c19bf675a78307c43.tar.gz |
- Use _PATH_TTY and _PATH_DEVNULL macros.
- Don't fail if we can't open /dev/null since this can happen if
xargs is jail'ed or chroot'ed.
These fixes were submitted by Todd Miller from the OpenBSD project.
There was one problem in those fixes that broke -o, which is corrected
here and should be committed to the OpenBSD repo by Todd soon.
MFC in: 3 days
Diffstat (limited to 'usr.bin/xargs')
-rw-r--r-- | usr.bin/xargs/xargs.c | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/usr.bin/xargs/xargs.c b/usr.bin/xargs/xargs.c index 77f08eb..227d9f5 100644 --- a/usr.bin/xargs/xargs.c +++ b/usr.bin/xargs/xargs.c @@ -483,6 +483,7 @@ static void run(char **argv) { pid_t pid; + int fd; char **avec; /* @@ -521,13 +522,16 @@ exec: case -1: err(1, "vfork"); case 0: - close(0); if (oflag) { - if (open("/dev/tty", O_RDONLY) == -1) - err(1, "open /dev/tty"); + if ((fd = open(_PATH_TTY, O_RDONLY)) == -1) + err(1, "can't open /dev/tty"); } else { - if (open("/dev/null", O_RDONLY) == -1) - err(1, "open /dev/null"); + fd = open(_PATH_DEVNULL, O_RDONLY); + } + if (fd > STDIN_FILENO) { + if (dup2(fd, STDIN_FILENO) != 0) + err(1, "can't dup2 to stdin"); + close(fd); } execvp(argv[0], argv); childerr = errno; |