Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 14 Nov 2000 22:54:50 +1100 (EST)
From:      Bruce Evans <bde@zeta.org.au>
To:        "John W. De Boskey" <jwd@FreeBSD.ORG>
Cc:        Current List <freebsd-current@FreeBSD.ORG>
Subject:   Re: getty bug when run by hand
Message-ID:  <Pine.BSF.4.21.0011142131130.2565-100000@besplex.bde.org>
In-Reply-To: <20001113190020.A98362@FreeBSD.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On Mon, 13 Nov 2000, John W. De Boskey wrote:

>    When the following command is run as root:
> 
> /usr/obj/usr/src/libexec/getty/getty std.38400 ttyd1
> 
>    the call to login_tty() fails in the opentty() function:
> 
>         else {
>                 login_tty(i);
>                 return 1;
>         }
> 
>    However, the return code is not checked. File descripters 0,
> 1, and 2 are not modified to point at ttyd1, and the getty then
> proceeds to run on the current terminal session.
> 
>    At a minimum, I'd like to commit the following patch. It would
> have helped avoid some frustrating moments...
> 
> ===================================================================
> RCS file: /home/ncvs/src/libexec/getty/main.c,v
> retrieving revision 1.31
> diff -u -r1.31 main.c
> --- main.c      2000/10/10 01:53:00     1.31
> +++ main.c      2000/11/14 02:25:31
> @@ -444,7 +444,10 @@
>                 return 0;
>         }
>         else {
> -               login_tty(i);
> +               if (login_tty(i) < 0) {
> +                       syslog(LOG_ERR, "login_tty %s: %m", ttyn);
> +                       return 0;
> +               }
>                 return 1;
>         }
>  }

This needs a "close(i);" for the error case.

>    This of course then leads to the question of why the 
> TIOCSCTTY ioctl call failes. From the above change:
> 
> Nov 13 17:25:47 mail getty[1236]: login_tty /dev/ttyd1: Operation not
> permitted

This is because the process isn't a session leader.  It isn't a session
leader because the setsid() call before the ioctl failed (and it wasn't
a session leader before that).  The result of the setsid() is ignored,
which is correct if setsid() failed due to the process already being a
session leader, but obfuscates the error otherwise.  setsid() fails
because the process is a process group leader.  This is the normal
environment for processes started from shells.  Session, process group
and controlling terminal stuff is all set up for normal job control, and
is difficult of impossible to change except in a new process.

getty works when it is started from init because init doesn't do much
setup for getty.  It only sets up a controlling terminal for running
/etc/rc and for single user mode...

Bruce



To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-current" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.4.21.0011142131130.2565-100000>