Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/kern Fix various bogus things:
details: https://anonhg.NetBSD.org/src/rev/55af97365b84
branches: trunk
changeset: 769803:55af97365b84
user: christos <christos%NetBSD.org@localhost>
date: Fri Sep 23 23:57:06 2011 +0000
description:
Fix various bogus things:
- Don't use TTYHOG - 1, you can use the last byte in the ring buffer.
- Don't put unnecessary if statements around the code. The loop invariant
is that if you reach the top of the loop, cc == 0.
- Remove cast to (void *).
- Check result of b_to_q and adjust cc.
- Explain what the TTYHOG - 2 code tried to do, and do it right.
diffstat:
sys/kern/tty_pty.c | 92 ++++++++++++++++++++++++++++-------------------------
1 files changed, 48 insertions(+), 44 deletions(-)
diffs (133 lines):
diff -r 913e6047e3ab -r 55af97365b84 sys/kern/tty_pty.c
--- a/sys/kern/tty_pty.c Fri Sep 23 23:02:23 2011 +0000
+++ b/sys/kern/tty_pty.c Fri Sep 23 23:57:06 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: tty_pty.c,v 1.129 2011/07/26 13:14:18 yamt Exp $ */
+/* $NetBSD: tty_pty.c,v 1.130 2011/09/23 23:57:06 christos Exp $ */
/*
* Copyright (c) 1982, 1986, 1989, 1993
@@ -37,7 +37,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: tty_pty.c,v 1.129 2011/07/26 13:14:18 yamt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tty_pty.c,v 1.130 2011/09/23 23:57:06 christos Exp $");
#include "opt_ptm.h"
@@ -701,30 +701,30 @@
if (pti->pt_flags & PF_REMOTE) {
if (tp->t_canq.c_cc)
goto block;
- while (uio->uio_resid > 0 && tp->t_canq.c_cc < TTYHOG - 1) {
- if (cc == 0) {
- cc = min(uio->uio_resid, BUFSIZ);
- cc = min(cc, TTYHOG - 1 - tp->t_canq.c_cc);
- cp = locbuf;
- mutex_spin_exit(&tty_lock);
- error = uiomove((void *)cp, cc, uio);
- if (error != 0)
- return error;
- mutex_spin_enter(&tty_lock);
- /* check again for safety */
- if (!ISSET(tp->t_state, TS_ISOPEN)) {
- /*
- * adjust for data copied in but not
- * written
- */
- uio->uio_resid += cc;
- error = EIO;
- goto out;
- }
+ while (uio->uio_resid > 0 && tp->t_canq.c_cc < TTYHOG) {
+ cc = min(uio->uio_resid, BUFSIZ);
+ cc = min(cc, TTYHOG - tp->t_canq.c_cc);
+ cp = locbuf;
+ mutex_spin_exit(&tty_lock);
+ error = uiomove(cp, cc, uio);
+ if (error != 0)
+ return error;
+ mutex_spin_enter(&tty_lock);
+ /* check again for safety */
+ if (!ISSET(tp->t_state, TS_ISOPEN)) {
+ /*
+ * adjust for data copied in but not
+ * written
+ */
+ uio->uio_resid += cc;
+ error = EIO;
+ goto out;
}
- if (cc)
- (void) b_to_q(cp, cc, &tp->t_canq);
- cc = 0;
+ if (cc) {
+ cc = b_to_q(cp, cc, &tp->t_outq);
+ if (cc > 0)
+ goto block;
+ }
}
(void) putc(0, &tp->t_canq);
ttwakeup(tp);
@@ -733,29 +733,34 @@
goto out;
}
while (uio->uio_resid > 0) {
- if (cc == 0) {
- cc = min(uio->uio_resid, BUFSIZ);
- cp = locbuf;
- mutex_spin_exit(&tty_lock);
- error = uiomove((void *)cp, cc, uio);
- if (error != 0)
- return error;
- mutex_spin_enter(&tty_lock);
- /* check again for safety */
- if (!ISSET(tp->t_state, TS_ISOPEN)) {
- /* adjust for data copied in but not written */
- uio->uio_resid += cc;
- error = EIO;
- goto out;
- }
+ cc = min(uio->uio_resid, BUFSIZ);
+ cp = locbuf;
+ mutex_spin_exit(&tty_lock);
+ error = uiomove(cp, cc, uio);
+ if (error != 0)
+ return error;
+ mutex_spin_enter(&tty_lock);
+ /* check again for safety */
+ if (!ISSET(tp->t_state, TS_ISOPEN)) {
+ /* adjust for data copied in but not written */
+ uio->uio_resid += cc;
+ error = EIO;
+ goto out;
}
while (cc > 0) {
- if ((tp->t_rawq.c_cc + tp->t_canq.c_cc) >= TTYHOG - 2 &&
- (tp->t_canq.c_cc > 0 || !ISSET(tp->t_lflag, ICANON))) {
+ int used = tp->t_rawq.c_cc + tp->t_canq.c_cc;
+ int canon = ISSET(tp->t_lflag, ICANON) ? 1 : 0;
+ /*
+ * We need space for 2 characters if canonical
+ * because we might need to print ^C
+ */
+ if (used >= (TTYHOG - canon) &&
+ (tp->t_canq.c_cc > 0 || !canon)) {
cv_broadcast(&tp->t_rawcv);
goto block;
}
- /* XXX - should change l_rint to be called with lock
+ /*
+ * XXX - should change l_rint to be called with lock
* see also tty.c:ttyinput_wlock()
*/
mutex_spin_exit(&tty_lock);
@@ -764,7 +769,6 @@
cnt++;
cc--;
}
- cc = 0;
}
error = 0;
goto out;
Home |
Main Index |
Thread Index |
Old Index