From owner-freebsd-current Tue Nov 14 11:39:23 2000 Delivered-To: freebsd-current@freebsd.org Received: from bsdone.bsdwins.com (www.bsdwins.com [192.58.184.33]) by hub.freebsd.org (Postfix) with ESMTP id 79F1E37B479; Tue, 14 Nov 2000 11:39:18 -0800 (PST) Received: (from jwd@localhost) by bsdone.bsdwins.com (8.11.0/8.11.0) id eAEJd7b93400; Tue, 14 Nov 2000 14:39:07 -0500 (EST) (envelope-from jwd) Date: Tue, 14 Nov 2000 14:39:07 -0500 From: "John W. De Boskey" To: Bruce Evans Cc: "John W. De Boskey" , Current List Subject: Re: getty bug when run by hand Message-ID: <20001114143907.A93281@bsdwins.com> References: <20001113190020.A98362@FreeBSD.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i In-Reply-To: ; from bde@zeta.org.au on Tue, Nov 14, 2000 at 10:54:50PM +1100 Sender: owner-freebsd-current@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG ----- 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