[Midnightbsd-cvs] src [8371] trunk/sys: fix faulty error code handling in read(2) on TTYs.

laffer1 at midnightbsd.org laffer1 at midnightbsd.org
Sun Sep 18 15:04:32 EDT 2016


Revision: 8371
          http://svnweb.midnightbsd.org/src/?rev=8371
Author:   laffer1
Date:     2016-09-18 15:04:32 -0400 (Sun, 18 Sep 2016)
Log Message:
-----------
fix faulty error code handling in read(2) on TTYs.

Modified Paths:
--------------
    trunk/sys/kern/tty.c
    trunk/sys/kern/tty_ttydisc.c
    trunk/sys/sys/tty.h

Modified: trunk/sys/kern/tty.c
===================================================================
--- trunk/sys/kern/tty.c	2016-09-18 19:03:40 UTC (rev 8370)
+++ trunk/sys/kern/tty.c	2016-09-18 19:04:32 UTC (rev 8371)
@@ -361,7 +361,7 @@
 	return (p->p_session == tp->t_session && p->p_flag & P_CONTROLT);
 }
 
-static int
+int
 tty_wait_background(struct tty *tp, struct thread *td, int sig)
 {
 	struct proc *p = td->td_proc;
@@ -433,13 +433,6 @@
 	error = ttydev_enter(tp);
 	if (error)
 		goto done;
-
-	error = tty_wait_background(tp, curthread, SIGTTIN);
-	if (error) {
-		tty_unlock(tp);
-		goto done;
-	}
-
 	error = ttydisc_read(tp, uio, ioflag);
 	tty_unlock(tp);
 

Modified: trunk/sys/kern/tty_ttydisc.c
===================================================================
--- trunk/sys/kern/tty_ttydisc.c	2016-09-18 19:03:40 UTC (rev 8370)
+++ trunk/sys/kern/tty_ttydisc.c	2016-09-18 19:04:32 UTC (rev 8371)
@@ -126,6 +126,10 @@
 	breakc[n] = '\0';
 
 	do {
+		error = tty_wait_background(tp, curthread, SIGTTIN);
+		if (error)
+			return (error);
+
 		/*
 		 * Quite a tricky case: unlike the old TTY
 		 * implementation, this implementation copies data back
@@ -149,10 +153,10 @@
 
 		/* No more data. */
 		if (clen == 0) {
-			if (ioflag & IO_NDELAY)
+			if (tp->t_flags & TF_ZOMBIE)
+				return (0);
+			else if (ioflag & IO_NDELAY)
 				return (EWOULDBLOCK);
-			else if (tp->t_flags & TF_ZOMBIE)
-				return (0);
 
 			error = tty_wait(tp, &tp->t_inwait);
 			if (error)
@@ -192,6 +196,10 @@
 	 */
 
 	for (;;) {
+		error = tty_wait_background(tp, curthread, SIGTTIN);
+		if (error)
+			return (error);
+
 		error = ttyinq_read_uio(&tp->t_inq, tp, uio,
 		    uio->uio_resid, 0);
 		if (error)
@@ -200,10 +208,10 @@
 			return (0);
 
 		/* We have to wait for more. */
-		if (ioflag & IO_NDELAY)
+		if (tp->t_flags & TF_ZOMBIE)
+			return (0);
+		else if (ioflag & IO_NDELAY)
 			return (EWOULDBLOCK);
-		else if (tp->t_flags & TF_ZOMBIE)
-			return (0);
 
 		error = tty_wait(tp, &tp->t_inwait);
 		if (error)
@@ -229,6 +237,10 @@
 	timevaladd(&end, &now);
 
 	for (;;) {
+		error = tty_wait_background(tp, curthread, SIGTTIN);
+		if (error)
+			return (error);
+
 		error = ttyinq_read_uio(&tp->t_inq, tp, uio,
 		    uio->uio_resid, 0);
 		if (error)
@@ -248,10 +260,10 @@
 		 * We have to wait for more. If the timer expires, we
 		 * should return a 0-byte read.
 		 */
-		if (ioflag & IO_NDELAY)
+		if (tp->t_flags & TF_ZOMBIE)
+			return (0);
+		else if (ioflag & IO_NDELAY)
 			return (EWOULDBLOCK);
-		else if (tp->t_flags & TF_ZOMBIE)
-			return (0);
 
 		error = tty_timedwait(tp, &tp->t_inwait, hz);
 		if (error)
@@ -278,6 +290,10 @@
 	 */
 
 	for (;;) {
+		error = tty_wait_background(tp, curthread, SIGTTIN);
+		if (error)
+			return (error);
+
 		error = ttyinq_read_uio(&tp->t_inq, tp, uio,
 		    uio->uio_resid, 0);
 		if (error)
@@ -293,10 +309,10 @@
 			break;
 
 		/* We have to wait for more. */
-		if (ioflag & IO_NDELAY)
+		if (tp->t_flags & TF_ZOMBIE)
+			return (0);
+		else if (ioflag & IO_NDELAY)
 			return (EWOULDBLOCK);
-		else if (tp->t_flags & TF_ZOMBIE)
-			return (0);
 
 		error = tty_wait(tp, &tp->t_inwait);
 		if (error)

Modified: trunk/sys/sys/tty.h
===================================================================
--- trunk/sys/sys/tty.h	2016-09-18 19:03:40 UTC (rev 8370)
+++ trunk/sys/sys/tty.h	2016-09-18 19:04:32 UTC (rev 8371)
@@ -180,6 +180,7 @@
 void	tty_signal_pgrp(struct tty *tp, int signal);
 /* Waking up readers/writers. */
 int	tty_wait(struct tty *tp, struct cv *cv);
+int	tty_wait_background(struct tty *tp, struct thread *td, int sig);
 int	tty_timedwait(struct tty *tp, struct cv *cv, int timo);
 void	tty_wakeup(struct tty *tp, int flags);
 



More information about the Midnightbsd-cvs mailing list