From owner-p4-projects@FreeBSD.ORG Thu Aug 21 18:11:31 2008 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id F26AB1065678; Thu, 21 Aug 2008 18:11:30 +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 B6BEA1065673 for ; Thu, 21 Aug 2008 18:11:30 +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 A36DC8FC19 for ; Thu, 21 Aug 2008 18:11:30 +0000 (UTC) (envelope-from ed@FreeBSD.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.2/8.14.2) with ESMTP id m7LIBUjM076223 for ; Thu, 21 Aug 2008 18:11:30 GMT (envelope-from ed@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.2/8.14.1/Submit) id m7LIBUCs076221 for perforce@freebsd.org; Thu, 21 Aug 2008 18:11:30 GMT (envelope-from ed@FreeBSD.org) Date: Thu, 21 Aug 2008 18:11:30 GMT Message-Id: <200808211811.m7LIBUCs076221@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 148020 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: Thu, 21 Aug 2008 18:11:31 -0000 http://perforce.freebsd.org/chv.cgi?CH=148020 Change 148020 by ed@ed_flippo on 2008/08/21 18:10:59 Finish the ttyhook interface that at least simulating user input works like it should. Also change the TTY layer to test for hooks before deallocating TTY's. Affected files ... .. //depot/projects/mpsafetty/sys/dev/snp/snp.c#5 edit .. //depot/projects/mpsafetty/sys/kern/tty.c#26 edit Differences ... ==== //depot/projects/mpsafetty/sys/dev/snp/snp.c#5 (text+ko) ==== @@ -36,6 +36,7 @@ #include #include #include +#include static struct cdev *snp_dev; static struct sx snp_register_lock; @@ -69,6 +70,13 @@ snp_dtor(void *data) { struct snp_softc *ss = data; + struct tty *tp; + + tp = ss->snp_tty; + if (tp != NULL) { + tty_lock(tp); + ttyhook_unregister(tp); + } free(ss, M_SNP); } @@ -95,8 +103,51 @@ static int snp_write(struct cdev *dev, struct uio *uio, int flag) { + struct snp_softc *ss; + struct tty *tp; + int error, len, i; + char in[8]; + + error = devfs_get_cdevpriv((void **)&ss); + if (error != 0) + return (error); + + tp = ss->snp_tty; + if (tp == NULL) + return (EIO); + + while (uio->uio_resid > 0) { + /* Read new data */ + len = imin(uio->uio_resid, sizeof in); + error = uiomove(in, len, uio); + if (error != 0) + return (error); - return (EIO); + tty_lock(tp); + + /* Driver could have abandoned the TTY in the mean time. */ + if (tty_gone(tp)) { + tty_unlock(tp); + return (ENXIO); + } + + /* + * Deliver data to the TTY. Ignore errors for now, + * because we shouldn't bail out when we're running + * close to the watermarks. + */ + if (ttydisc_can_bypass(tp)) { + ttydisc_rint_bypass(tp, in, len); + } else { + for (i = 0; i < len; i++) + ttydisc_rint(tp, in[i], 0); + } + + ttydisc_rint_done(tp); + tty_unlock(tp); + } + + return (0); } static int ==== //depot/projects/mpsafetty/sys/kern/tty.c#26 (text+ko) ==== @@ -931,7 +931,7 @@ tty_lock_assert(tp, MA_OWNED); if (tp->t_sessioncnt != 0 || - (tp->t_flags & (TF_GONE|TF_OPENED)) != TF_GONE) { + (tp->t_flags & (TF_GONE|TF_OPENED|TF_HOOK)) != TF_GONE) { /* TTY is still in use. */ tty_unlock(tp); return; @@ -1710,6 +1710,7 @@ tp->t_flags |= TF_HOOK; tp->t_hook = th; + *rtp = tp; error = 0; done3: tty_unlock(tp); @@ -1722,7 +1723,15 @@ ttyhook_unregister(struct tty *tp) { + tty_lock_assert(tp, MA_OWNED); MPASS(tp->t_flags & TF_HOOK); + + /* Disconnect the hook */ + tp->t_flags &= ~TF_HOOK; + tp->t_hook = NULL; + + /* Maybe deallocate the TTY as well */ + tty_rel_free(tp); } #include "opt_ddb.h"