lkml.org 
[lkml]   [1999]   [Oct]   [26]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: file descritor 255 is always associated with /dev/tty[?] ?
On Tue, Oct 26, 1999 at 07:18:51PM +0530, SK wrote:
> Hi,
> I am running linux kernel 2.2.9.
> I have noticed that the file descriptor 255 (apart from fd 0, 1 and 2)
> of a process is always associated with the controlling terminal device of
> the process i.e /dev/tty[?] (current->files->fd[255] is not NULL). This is
> the case with the shell (bash) process and since other processes are
> forked by shell, this fd is inherited. I looked at the kernel sources and
> bash source to see who sets this fd 255 but could not find. Can someone
> please mail me (or give links to references) why this is set, who sets it,
> and when?


This is a bash bug. (It exists at version 2.03, propably earlier.)
I will cook up a bashbug report.

Lets look for possible places:

[bash-2.03]$ egrep dup2 *.c
execute_cmd.c: dup2 (fd, 0);
execute_cmd.c: if (dup2 (pipe_in, 0) < 0)
execute_cmd.c: if (dup2 (pipe_out, 1) < 0)
execute_cmd.c: if (dup2 (1, 2) < 0)
general.c: if (nfds && fd != nfds && (script_fd = dup2 (fd, nfds)) != -1)
input.c:/* This is the buffered stream analogue of dup2(fd1, fd2). The
redir.c: if ((fd != redirector) && (dup2 (fd, redirector) < 0))
redir.c: if (dup2 (1, 2) < 0)
redir.c: if (fd != redirector && dup2 (fd, redirector) < 0)
redir.c: /* This is correct. 2>&1 means dup2 (1, 2); */
redir.c: if (dup2 (redir_fd, redirector) < 0)
redir.c: /* First duplicate the close-on-exec state of redirectee. dup2
shell.c: dup2 (fd, 0);
subst.c: if (dup2 (fd, open_for_read_in_child ? 0 : 1) < 0)
subst.c: if (dup2 (fildes[1], 1) < 0)

Which of those ?
There are possibilities within redir.c, and general.c,
but I would bet virtual drink on that general.c being
the problem spot..

The code in there does not set close-on-exec flag for that fd.
( dup2() does clear close-on-exec flag for the new instance
of the fd.. )

> Thanks,
> Sushil.

/Matti Aarnio <matti.aarnio@sonera.fi>

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2005-03-22 13:54    [W:3.536 / U:0.028 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site