linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] tty:pty: move wake_up*() after tty_vhangup() in pty_close()
@ 2023-01-27  7:20 Yan Cangang
  2023-01-31  9:56 ` Greg KH
  0 siblings, 1 reply; 2+ messages in thread
From: Yan Cangang @ 2023-01-27  7:20 UTC (permalink / raw)
  To: gregkh, jirislaby; +Cc: linux-kernel, Yan Cangang

wake_up_interruptible() may wake up the session leader blocked on pts, at
this time the tty_signal_session_leader() in __tty_hangup() has not been
executed.

The session leader's subsequent IO on pts will fail, but the session
leader did not received SIGHUP as expected at this time.

A observed phenomenon is that when the ssh connection is disconnected, the
background jobs managed by bash did not terminate as expected. This
problem is more easily observed on low-end single-processor systems.

Signed-off-by: Yan Cangang <nalanzeyu@gmail.com>
---
 drivers/tty/pty.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
index 07394fdaf522..fbcf2caa8fc1 100644
--- a/drivers/tty/pty.c
+++ b/drivers/tty/pty.c
@@ -64,8 +64,6 @@ static void pty_close(struct tty_struct *tty, struct file *filp)
 	if (!tty->link)
 		return;
 	set_bit(TTY_OTHER_CLOSED, &tty->link->flags);
-	wake_up_interruptible(&tty->link->read_wait);
-	wake_up_interruptible(&tty->link->write_wait);
 	if (tty->driver->subtype == PTY_TYPE_MASTER) {
 		set_bit(TTY_OTHER_CLOSED, &tty->flags);
 #ifdef CONFIG_UNIX98_PTYS
@@ -78,6 +76,8 @@ static void pty_close(struct tty_struct *tty, struct file *filp)
 #endif
 		tty_vhangup(tty->link);
 	}
+	wake_up_interruptible(&tty->link->read_wait);
+	wake_up_interruptible(&tty->link->write_wait);
 }
 
 /*
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] tty:pty: move wake_up*() after tty_vhangup() in pty_close()
  2023-01-27  7:20 [PATCH] tty:pty: move wake_up*() after tty_vhangup() in pty_close() Yan Cangang
@ 2023-01-31  9:56 ` Greg KH
  0 siblings, 0 replies; 2+ messages in thread
From: Greg KH @ 2023-01-31  9:56 UTC (permalink / raw)
  To: Yan Cangang; +Cc: jirislaby, linux-kernel

On Fri, Jan 27, 2023 at 03:20:17PM +0800, Yan Cangang wrote:
> wake_up_interruptible() may wake up the session leader blocked on pts, at
> this time the tty_signal_session_leader() in __tty_hangup() has not been
> executed.
> 
> The session leader's subsequent IO on pts will fail, but the session
> leader did not received SIGHUP as expected at this time.
> 
> A observed phenomenon is that when the ssh connection is disconnected, the
> background jobs managed by bash did not terminate as expected. This
> problem is more easily observed on low-end single-processor systems.

This feels odd, why is this only showing up now?  What changed to cause
this issue?

What commit id does this fix?

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-01-31  9:56 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-27  7:20 [PATCH] tty:pty: move wake_up*() after tty_vhangup() in pty_close() Yan Cangang
2023-01-31  9:56 ` Greg KH

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).