summaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
authortjr <tjr@FreeBSD.org>2003-01-27 07:41:12 +0000
committertjr <tjr@FreeBSD.org>2003-01-27 07:41:12 +0000
commit29dbde6d3caa85ddb2740feeaa69026a03e98a8a (patch)
treef29f2a606c3c8df580b1591856c41dda5ee4c3b0 /bin
parent273be50650cbddcef59f940fadc3ee725fb05a27 (diff)
downloadFreeBSD-src-29dbde6d3caa85ddb2740feeaa69026a03e98a8a.zip
FreeBSD-src-29dbde6d3caa85ddb2740feeaa69026a03e98a8a.tar.gz
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
Diffstat (limited to 'bin')
-rw-r--r--bin/sh/jobs.c15
1 files changed, 14 insertions, 1 deletions
diff --git a/bin/sh/jobs.c b/bin/sh/jobs.c
index cdd921b..0c1518d 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;
OpenPOWER on IntegriCloud