Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 26 Oct 2008 15:14:31 GMT
From:      Ed Schouten <ed@FreeBSD.org>
To:        Perforce Change Reviews <perforce@FreeBSD.org>
Subject:   PERFORCE change 151957 for review
Message-ID:  <200810261514.m9QFEV1k074113@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=151957

Change 151957 by ed@ed_mekker on 2008/10/26 15:13:40

	Don't hardcode "ttyv0" in TTY selection.
	
	I've introduced a new function that is called from our low-level
	console code. This function is called each time the first entry
	in cn_devlist is changed. Each time /dev/console is being
	opened, it will iterate the list of TTY's on the system to look
	up the TTY by that name.
	
	It is not possible to perform the lookup when cn_devlist
	changes, because cn_devlist is already being filled very early
	during boot.

Affected files ...

.. //depot/projects/mpsafetty/sys/kern/tty.c#60 edit
.. //depot/projects/mpsafetty/sys/kern/tty_cons.c#6 edit
.. //depot/projects/mpsafetty/sys/sys/tty.h#23 edit

Differences ...

==== //depot/projects/mpsafetty/sys/kern/tty.c#60 (text+ko) ====

@@ -74,7 +74,8 @@
 static unsigned int tty_list_count = 0;
 
 /* Character device of /dev/console. */
-static struct cdev *dev_console;
+static struct cdev	*dev_console;
+static const char	*dev_console_filename;
 
 /*
  * Flags that are supported and stored by this implementation.
@@ -1126,10 +1127,6 @@
 			dev->si_drv2 = &tp->t_termios_lock_out;
 		}
 	}
-
-	/* XXX: console hardcoding! */
-	if (strcmp(tty_devname(tp), "ttyv0") == 0)
-		dev_console->si_drv1 = tp;
 }
 
 /*
@@ -1756,10 +1753,20 @@
 static int
 ttyconsdev_open(struct cdev *dev, int oflags, int devtype, struct thread *td)
 {
-	struct tty *tp = dev->si_drv1;
+	struct tty *tp;
+
+	/* Look up corresponding TTY by device name. */
+	sx_slock(&tty_list_sx);
+	TAILQ_FOREACH(tp, &tty_list, t_list) {
+		if (strcmp(dev_console_filename, tty_devname(tp)) == 0) {
+			dev_console->si_drv1 = tp;
+			break;
+		}
+	}
+	sx_sunlock(&tty_list_sx);
 
-	/* /dev/console without associated TTY. */
-	if (tp == NULL)
+	/* Still no TTY associated by that name. */
+	if (dev_console->si_drv1 == NULL)
 		return (ENXIO);
 	
 	return (ttydev_open(dev, oflags, devtype, td));
@@ -1802,6 +1809,13 @@
 
 SYSINIT(tty, SI_SUB_DRIVERS, SI_ORDER_FIRST, ttyconsdev_init, NULL);
 
+void
+ttyconsdev_select(const char *name)
+{
+
+	dev_console_filename = name;
+}
+
 #include "opt_ddb.h"
 #ifdef DDB
 #include <ddb/ddb.h>

==== //depot/projects/mpsafetty/sys/kern/tty_cons.c#6 (text+ko) ====

@@ -186,6 +186,8 @@
 		printf("WARNING: console at %p has no name\n", cn);
 	}
 	STAILQ_INSERT_TAIL(&cn_devlist, cnd, cnd_next);
+	if (STAILQ_FIRST(&cn_devlist) == cnd)
+		ttyconsdev_select(cnd->cnd_cn->cn_name);
 
 	/* Add device to the active mask. */
 	cnavailable(cn, (cn->cn_flags & CN_FLAG_NOAVAIL) == 0);
@@ -236,6 +238,7 @@
 			return;
 		STAILQ_REMOVE(&cn_devlist, cnd, cn_device, cnd_next);
 		STAILQ_INSERT_HEAD(&cn_devlist, cnd, cnd_next);
+		ttyconsdev_select(cnd->cnd_cn->cn_name);
 		return;
 	}
 }

==== //depot/projects/mpsafetty/sys/sys/tty.h#23 (text+ko) ====

@@ -192,6 +192,9 @@
 /* Status line printing. */
 void	tty_info(struct tty *tp);
 
+/* /dev/console selection. */
+void	ttyconsdev_select(const char *name);
+
 /* Pseudo-terminal hooks. */
 int	pts_alloc_external(int fd, struct thread *td, struct file *fp,
     struct cdev *dev, const char *name);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200810261514.m9QFEV1k074113>