From owner-p4-projects@FreeBSD.ORG Sun Oct 26 15:14:32 2008 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 72BB81065675; Sun, 26 Oct 2008 15:14:32 +0000 (UTC) Delivered-To: perforce@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 36CB71065673 for ; Sun, 26 Oct 2008 15:14:32 +0000 (UTC) (envelope-from ed@FreeBSD.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id 263F78FC1B for ; Sun, 26 Oct 2008 15:14:32 +0000 (UTC) (envelope-from ed@FreeBSD.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.3/8.14.3) with ESMTP id m9QFEV0h074115 for ; Sun, 26 Oct 2008 15:14:31 GMT (envelope-from ed@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.3/8.14.3/Submit) id m9QFEV1k074113 for perforce@freebsd.org; Sun, 26 Oct 2008 15:14:31 GMT (envelope-from ed@FreeBSD.org) Date: Sun, 26 Oct 2008 15:14:31 GMT Message-Id: <200810261514.m9QFEV1k074113@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to ed@FreeBSD.org using -f From: Ed Schouten To: Perforce Change Reviews Cc: Subject: PERFORCE change 151957 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 26 Oct 2008 15:14:32 -0000 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 ==== //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);