Blob Blame History Raw
From 09ad4fa60fcff4c66be70bde84080b1eb8aa78c8 Mon Sep 17 00:00:00 2001
From: Takashi Iwai <tiwai@suse.de>
Date: Thu, 22 Nov 2018 21:22:42 +0100
Subject: [PATCH] tty: Don't return -EAGAIN in blocking read
Patch-mainline: No, testing
References: bsc#1116040

The recent change makes ops->read() returning with -EAGAIN when ldisc
is being changed.  This surprises programs reading the device in
blocking mode; e.g. "cat /dev/console" running on VT aborts when VT is
switched.

Basically we shouldn't abort the read but need to retry with
re-locking when the device is opened in blocking mode.

Signed-off-by: Takashi Iwai <tiwai@suse.de>

---
 drivers/tty/tty_io.c |    3 +++
 1 file changed, 3 insertions(+)

--- a/drivers/tty/tty_io.c
+++ b/drivers/tty/tty_io.c
@@ -796,6 +796,7 @@ static ssize_t tty_read(struct file *fil
 
 	/* We want to wait for the line discipline to sort out in this
 	   situation */
+ again:
 	ld = tty_ldisc_ref_wait(tty);
 	if (!ld)
 		return hung_up_tty_read(file, buf, count, ppos);
@@ -804,6 +805,8 @@ static ssize_t tty_read(struct file *fil
 	else
 		i = -EIO;
 	tty_ldisc_deref(ld);
+	if (i == -EAGAIN && !(file->f_flags & O_NONBLOCK))
+		goto again;
 
 	if (i > 0)
 		tty_update_time(&inode->i_atime);