----- 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 [EMAIL PROTECTED]
with "unsubscribe freebsd-current" in the body of the message