Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 14 Nov 2000 14:39:07 -0500
From:      "John W. De Boskey" <jwd@bsdwins.com>
To:        Bruce Evans <bde@zeta.org.au>
Cc:        "John W. De Boskey" <jwd@FreeBSD.ORG>, Current List <freebsd-current@FreeBSD.ORG>
Subject:   Re: getty bug when run by hand
Message-ID:  <20001114143907.A93281@bsdwins.com>
In-Reply-To: <Pine.BSF.4.21.0011142131130.2565-100000@besplex.bde.org>; from bde@zeta.org.au on Tue, Nov 14, 2000 at 10:54:50PM %2B1100
References:  <20001113190020.A98362@FreeBSD.org> <Pine.BSF.4.21.0011142131130.2565-100000@besplex.bde.org>

next in thread | previous in thread | raw e-mail | index | archive | help
----- Bruce Evans's Original Message -----
> 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

I re-written the patch to fix the error case, and to allow getty
to be run from a command line and DTRT. I have this running on
my system right now (from /etc/ttys, and from a console). I'd like
to commit this unless anyone sees any fatal mistakes I've made.

Thanks,
-John

freefall:/d/home/jwd/src/src/libexec/getty/main.c

cvs diff: Diffing .
Index: main.c
===================================================================
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 19:26:17
@@ -444,7 +444,18 @@
                return 0;
        }
        else {
-               login_tty(i);
+               if (login_tty(i) < 0) { 
+                       if (daemon(0,0) < 0) {
+                               syslog(LOG_ERR,"daemon: %m");
+                               close(i);
+                               return 0;
+                       }
+                       if (login_tty(i) < 0) {
+                               syslog(LOG_ERR, "login_tty %s: %m", ttyn);
+                               close(i);
+                               return 0;
+                       }
+               }
                return 1;
        }
 }



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?20001114143907.A93281>