From c57bc2b10ee7e8b6023271a0c576922c8d6b5cfa Mon Sep 17 00:00:00 2001 From: "Tim J. Robbins" Date: Mon, 27 Jan 2003 07:41:12 +0000 Subject: [PATCH] Ensure that the TTY file descriptor is greater than or equal to 10 so that it doesn't interfere with the user's redirections. PR: 47136 MFC after: 1 week --- bin/sh/jobs.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/bin/sh/jobs.c b/bin/sh/jobs.c index cdd921bf3618..0c1518d06599 100644 --- a/bin/sh/jobs.c +++ b/bin/sh/jobs.c @@ -126,9 +126,22 @@ setjobctl(int on) i = 0; while (i <= 2 && !isatty(i)) i++; - if (i > 2 || (ttyfd = dup(i)) < 0) + if (i > 2 || (ttyfd = fcntl(i, F_DUPFD, 10)) < 0) goto out; } + if (ttyfd < 10) { + /* + * Keep our TTY file descriptor out of the way of + * the user's redirections. + */ + if ((i = fcntl(ttyfd, F_DUPFD, 10)) < 0) { + close(ttyfd); + ttyfd = -1; + goto out; + } + close(ttyfd); + ttyfd = i; + } if (fcntl(ttyfd, F_SETFD, FD_CLOEXEC) < 0) { close(ttyfd); ttyfd = -1;