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
This commit is contained in:
Tim J. Robbins 2003-01-27 07:41:12 +00:00
parent 9d492cddac
commit c57bc2b10e
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=109927

View File

@ -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;