bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: check_dev_tty - What does it do?


From: Stephane Chazelas
Subject: Re: check_dev_tty - What does it do?
Date: Fri, 23 Jun 2006 11:01:28 +0100
User-agent: mutt-ng/devel-r562 (Linux)

On Fri, Jun 23, 2006 at 02:54:04PM +1200, John Carter wrote:
> 
> Here is the bash-3.1 code from general.c for check_dev_tty.
> 
> It is invoked shortly after main...
> 
> void
> check_dev_tty ()
> {
>   int tty_fd;
>   char *tty;
> 
>   tty_fd = open ("/dev/tty", O_RDWR|O_NONBLOCK);
> 
>   if (tty_fd < 0)
>     {
>       tty = (char *)ttyname (fileno (stdin));
>       if (tty == 0)
>       return;
>       tty_fd = open (tty, O_RDWR|O_NONBLOCK);
>     }
>   close (tty_fd);
> }
> 
> It seems to open and close /dev/tty and return nothing.
> 
> This seems very strange to me.
> 
> Why is it doing this?
[...]

A rough guess:

It may be that, if bash is the session leader and no session is
attached to the terminal open on stdin, the open would attach
the terminal to the session. Bash would become the controlling
process.

I guess it might happen when you boot Linux with init=/bin/bash
for instance.

It may not be the reason for it, though. And I'm not sure it is
right for bash to do so.

-- 
Stephane




reply via email to

[Prev in Thread] Current Thread [Next in Thread]