From owner-p4-projects@FreeBSD.ORG Thu Aug 21 19:45:07 2008 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id AE6D4106567C; Thu, 21 Aug 2008 19:45:07 +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 71D3D106564A for ; Thu, 21 Aug 2008 19:45:07 +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 5DCE38FC17 for ; Thu, 21 Aug 2008 19:45:07 +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 m7LJj7Ug094839 for ; Thu, 21 Aug 2008 19:45:07 GMT (envelope-from ed@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.2/8.14.1/Submit) id m7LJj7qe094837 for perforce@freebsd.org; Thu, 21 Aug 2008 19:45:07 GMT (envelope-from ed@FreeBSD.org) Date: Thu, 21 Aug 2008 19:45:07 GMT Message-Id: <200808211945.m7LJj7qe094837@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 148035 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 19:45:08 -0000 http://perforce.freebsd.org/chv.cgi?CH=148035 Change 148035 by ed@ed_flippo on 2008/08/21 19:44:34 Make snp(4) work with pts(4) created TTY's. Because we copy data unbuffered to userspace, we must fall back to a buffered approach when we've got hooks. I don't completely like this method yet, but hey, at least I've got it working for now. Affected files ... .. //depot/projects/mpsafetty/sys/kern/tty_ttydisc.c#13 edit Differences ... ==== //depot/projects/mpsafetty/sys/kern/tty_ttydisc.c#13 (text+ko) ==== @@ -79,6 +79,8 @@ #define CTL_ALNUM(c) (((c) >= '0' && (c) <= '9') || \ ((c) >= 'a' && (c) <= 'z') || ((c) >= 'A' && (c) <= 'Z')) +#define TTY_STACKBUF 256 + void ttydisc_open(struct tty *tp) { @@ -434,7 +436,7 @@ int ttydisc_write(struct tty *tp, struct uio *uio, int ioflag) { - char ob[256]; + char ob[TTY_STACKBUF]; char *obstart; int error = 0; unsigned int oblen = 0; @@ -1081,31 +1083,61 @@ return (0); len = ttyoutq_read(&tp->t_outq, buf, len); - ttydisc_wakeup_watermark(tp); - - atomic_add_long(&tty_nout, len); /* Invoke TTY hooks. XXX: ttyhook_getc_capture()? */ if (tp->t_hook != NULL && tp->t_hook->th_getc_capture != NULL) tp->t_hook->th_getc_capture(tp, buf, len); + ttydisc_wakeup_watermark(tp); + atomic_add_long(&tty_nout, len); + return (len); } int ttydisc_getc_uio(struct tty *tp, struct uio *uio) { - int error; + int error = 0; int obytes = uio->uio_resid; + size_t len; + char buf[TTY_STACKBUF]; tty_lock_assert(tp, MA_OWNED); if (tp->t_flags & TF_STOPPED) return (0); - error = ttyoutq_read_uio(&tp->t_outq, tp, uio); + /* + * When a TTY hook is attached, we cannot perform unbuffered + * copying to userspace. We just simulate it by copying data to + * a shadow buffer. + */ + if (tp->t_hook != NULL && tp->t_hook->th_getc_capture != NULL) { + while (uio->uio_resid > 0) { + /* Read to shadow buffer. */ + len = ttyoutq_read(&tp->t_outq, buf, + MIN(uio->uio_resid, sizeof buf)); + if (len == 0) + break; + + /* Process with hook. Handle sudden removal. */ + if (tp->t_hook != NULL && + tp->t_hook->th_getc_capture != NULL) + tp->t_hook->th_getc_capture(tp, buf, len); + + /* Copy to userspace. */ + tty_unlock(tp); + error = uiomove(buf, len, uio); + tty_lock(tp); + + if (error != 0) + break; + } + } else { + error = ttyoutq_read_uio(&tp->t_outq, tp, uio); + } + ttydisc_wakeup_watermark(tp); - atomic_add_long(&tty_nout, obytes - uio->uio_resid); return (error);