summaryrefslogtreecommitdiffstats
path: root/sys/kern
diff options
context:
space:
mode:
authored <ed@FreeBSD.org>2012-10-03 13:51:03 +0000
committered <ed@FreeBSD.org>2012-10-03 13:51:03 +0000
commitb7b93e528894509ebb520c28977ed0d37e2f731a (patch)
treef9e512adb0c4505e2b1f716839cfa559d8c36289 /sys/kern
parent5b8c32a59f0fe2ee46ee9cc8b807bbd38d05f570 (diff)
downloadFreeBSD-src-b7b93e528894509ebb520c28977ed0d37e2f731a.zip
FreeBSD-src-b7b93e528894509ebb520c28977ed0d37e2f731a.tar.gz
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
Diffstat (limited to 'sys/kern')
-rw-r--r--sys/kern/tty_ttydisc.c24
1 files changed, 12 insertions, 12 deletions
diff --git a/sys/kern/tty_ttydisc.c b/sys/kern/tty_ttydisc.c
index 6d36de4..52a5df2 100644
--- a/sys/kern/tty_ttydisc.c
+++ b/sys/kern/tty_ttydisc.c
@@ -149,10 +149,10 @@ ttydisc_read_canonical(struct tty *tp, struct uio *uio, int ioflag)
/* 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, struct uio *uio, int ioflag)
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 *tp, struct uio *uio, int ioflag,
* 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 tty *tp, struct uio *uio, int ioflag)
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)
OpenPOWER on IntegriCloud