Skip to content

Commit f446776

Browse files
cminyardgregkh
authored andcommitted
tty: Export redirect release
This will be required by the pty code when it removes tty_vhangup() on master close. Signed-off-by: Corey Minyard <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent c31c3ea commit f446776

File tree

2 files changed

+25
-8
lines changed

2 files changed

+25
-8
lines changed

drivers/tty/tty_io.c

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,28 @@ void tty_wakeup(struct tty_struct *tty)
540540

541541
EXPORT_SYMBOL_GPL(tty_wakeup);
542542

543+
/**
544+
* tty_release_redirect - Release a redirect on a pty if present
545+
* @tty: tty device
546+
*
547+
* This is available to the pty code so if the master closes, if the
548+
* slave is a redirect it can release the redirect.
549+
*/
550+
struct file *tty_release_redirect(struct tty_struct *tty)
551+
{
552+
struct file *f = NULL;
553+
554+
spin_lock(&redirect_lock);
555+
if (redirect && file_tty(redirect) == tty) {
556+
f = redirect;
557+
redirect = NULL;
558+
}
559+
spin_unlock(&redirect_lock);
560+
561+
return f;
562+
}
563+
EXPORT_SYMBOL_GPL(tty_release_redirect);
564+
543565
/**
544566
* __tty_hangup - actual handler for hangup events
545567
* @tty: tty device
@@ -566,21 +588,15 @@ EXPORT_SYMBOL_GPL(tty_wakeup);
566588
static void __tty_hangup(struct tty_struct *tty, int exit_session)
567589
{
568590
struct file *cons_filp = NULL;
569-
struct file *filp, *f = NULL;
591+
struct file *filp, *f;
570592
struct tty_file_private *priv;
571593
int closecount = 0, n;
572594
int refs;
573595

574596
if (!tty)
575597
return;
576598

577-
578-
spin_lock(&redirect_lock);
579-
if (redirect && file_tty(redirect) == tty) {
580-
f = redirect;
581-
redirect = NULL;
582-
}
583-
spin_unlock(&redirect_lock);
599+
f = tty_release_redirect(tty);
584600

585601
tty_lock(tty);
586602

include/linux/tty.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,7 @@ extern void tty_kclose(struct tty_struct *tty);
421421
extern int tty_dev_name_to_number(const char *name, dev_t *number);
422422
extern int tty_ldisc_lock(struct tty_struct *tty, unsigned long timeout);
423423
extern void tty_ldisc_unlock(struct tty_struct *tty);
424+
extern struct file *tty_release_redirect(struct tty_struct *tty);
424425
#else
425426
static inline void tty_kref_put(struct tty_struct *tty)
426427
{ }

0 commit comments

Comments
 (0)