Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 3 Oct 2012 13:51:03 +0000 (UTC)
From:      Ed Schouten <ed@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r241161 - head/sys/kern
Message-ID:  <201210031351.q93Dp35B038584@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: ed
Date: Wed Oct  3 13:51:03 2012
New Revision: 241161
URL: http://svn.freebsd.org/changeset/base/241161

Log:
  Fix faulty error code handling in read(2) on TTYs.
  
  When performing a non-blocking read(2), on a TTY while no data is
  available, we should return EAGAIN. But if there's a modem disconnect,
  we should return 0. Right now we only return 0 when doing a blocking
  read, which is wrong.
  
  MFC after:	1 month

Modified:
  head/sys/kern/tty_ttydisc.c

Modified: head/sys/kern/tty_ttydisc.c
==============================================================================
--- head/sys/kern/tty_ttydisc.c	Wed Oct  3 12:43:26 2012	(r241160)
+++ head/sys/kern/tty_ttydisc.c	Wed Oct  3 13:51:03 2012	(r241161)
@@ -149,10 +149,10 @@ ttydisc_read_canonical(struct tty *tp, s
 
 		/* No more data. */
 		if (clen == 0) {
-			if (ioflag & IO_NDELAY)
-				return (EWOULDBLOCK);
-			else if (tp->t_flags & TF_ZOMBIE)
+			if (tp->t_flags & TF_ZOMBIE)
 				return (0);
+			else if (ioflag & IO_NDELAY)
+				return (EWOULDBLOCK);
 
 			error = tty_wait(tp, &tp->t_inwait);
 			if (error)
@@ -200,10 +200,10 @@ ttydisc_read_raw_no_timer(struct tty *tp
 			return (0);
 
 		/* We have to wait for more. */
-		if (ioflag & IO_NDELAY)
-			return (EWOULDBLOCK);
-		else if (tp->t_flags & TF_ZOMBIE)
+		if (tp->t_flags & TF_ZOMBIE)
 			return (0);
+		else if (ioflag & IO_NDELAY)
+			return (EWOULDBLOCK);
 
 		error = tty_wait(tp, &tp->t_inwait);
 		if (error)
@@ -248,10 +248,10 @@ ttydisc_read_raw_read_timer(struct tty *
 		 * We have to wait for more. If the timer expires, we
 		 * should return a 0-byte read.
 		 */
-		if (ioflag & IO_NDELAY)
-			return (EWOULDBLOCK);
-		else if (tp->t_flags & TF_ZOMBIE)
+		if (tp->t_flags & TF_ZOMBIE)
 			return (0);
+		else if (ioflag & IO_NDELAY)
+			return (EWOULDBLOCK);
 
 		error = tty_timedwait(tp, &tp->t_inwait, hz);
 		if (error)
@@ -293,10 +293,10 @@ ttydisc_read_raw_interbyte_timer(struct 
 			break;
 
 		/* We have to wait for more. */
-		if (ioflag & IO_NDELAY)
-			return (EWOULDBLOCK);
-		else if (tp->t_flags & TF_ZOMBIE)
+		if (tp->t_flags & TF_ZOMBIE)
 			return (0);
+		else if (ioflag & IO_NDELAY)
+			return (EWOULDBLOCK);
 
 		error = tty_wait(tp, &tp->t_inwait);
 		if (error)



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