From: "Linux Activists" <linux-activists@Niksula.hut.fi>
Subject: Linux-Activists - SERIAL Channel digest. 93-11-22-23:16
X-Mn-Key: SERIAL
Message-Id: <93Dec23.032823eet.67972-2@niksula.hut.fi>
Date: Thu, 23 Dec 1993 03:28:17 +0200

----------------------------------------------------------------------

From: julian@uhunix.uhcc.Hawaii.Edu (Julian Cowley)
Subject: patch for getty_ps 2.0.7b
Date: Wed, 22 Dec 1993 21:47:02 +0200


Now that Ted's latest patches have been released, here comes a
much-needed patch for getty_ps-2.0.7b.  The patch fixes a problem
with vhangup() and makes sure the initial termios are set.

Please try this out, especially those of you with dial-in
lines.  The plan is for this patch to be sent to c.o.l.a. when
pl15 is announced.  Report any problems to this list (I know
there isn't very much time left for testing).

IMPORTANT: although this patch should work with older kernels,
please install the Ted's latest serial patches before you try it.

Changes:

1. Made sure vhangup() is called correctly before the line is
   opened for initialization and for logging in.  This call is
   necessary to make sure no rogue programs are waiting on the
   line.
2. Now calls TIOCSCTTY to make sure no race conditions exist when
   obtaining the controlling tty.
3. Fixed a bug where the initial termios were not set for some
   lines (those without an INIT or WAITCHAR command).  Especially
   important for serial lines, since the kernel's initial termios
   has CLOCAL set.  This means that serial lines wouldn't block
   when open was called, causing the issue banner to be read as
   the login name.

diff -u --recursive getty_ps.orig/main.c getty_ps/main.c
--- getty_ps.orig/main.c	Tue Apr 20 06:51:44 1993
+++ getty_ps/main.c	Wed Dec 22 08:41:15 1993
@@ -499,7 +499,30 @@
 /* now, the init device is opened ONLY if INIT or WAITCHAR is requested
 */
 
+/* HACK: always done now, since the initial termios weren't being set and
+   vhangup() needs to be called.  */
+
-	if((init) || (waitchar)) {
+	if (1) {
+		debug3(D_RUN, "calling vhangup on %s\n", initdevname);
+		while ((fd = open(initdevname, O_RDWR | O_NONBLOCK)) < 0 &&
+		       errno == EBUSY)
+			sleep(30);
+		if (fd < 0) {
+			logerr("cannot open init line");
+			exit(FAIL);
+		}
+		ioctl(fd, TIOCSCTTY, 1); /* guarantee the controlling tty */
+		ioctl(fd, TCGETS, &termio);
+		if (NoHangUp)
+			termio.c_cflag &= ~HUPCL;
+		else
+			termio.c_cflag |= HUPCL;
+		ioctl(fd, TCSETS, &termio);
+		signal(SIGHUP, SIG_IGN);
+		vhangup();
+		signal(SIGHUP, shangup);
+		close(fd);
+
 		debug3(D_RUN, "opening init line: %s\n", initdevname);
 		while(((fd = open(initdevname, O_RDWR | O_NDELAY)) < 0) &&
 		  (errno == EBUSY)) sleep(30);
@@ -525,6 +548,7 @@
 		setbuf(stderr, (char *) NULL);
 
 		gtab = gtabvalue(GtabId, G_FORCE);
+		/* handled by vhangup() in >= 0.99pl15, but just in case... */
 		if(! NoHangUp) {
 			(void) ioctl(STDIN, TCGETS, &termio);
 			termio.c_cflag &= ~CBAUD;
@@ -598,7 +622,7 @@
 		}
 	}
 
-	if((init) || (waitchar)) {
+	if (1) {
 		(void) close(0);
 		(void) close(1);
 		(void) close(2);
@@ -702,6 +726,7 @@
 		logerr("cannot open connect line");
 		exit(FAIL);
 	}
+	ioctl(fd, TIOCSCTTY, 1); /* guarantee the controlling tty */
 	if(fd != 0) {
 		logerr("cannot open connect stdin");
 		exit(FAIL);



------------------------------
