Skip to content

Commit 11e1d4a

Browse files
peterhurleygregkh
authored andcommitted
tty: Consolidate noctty checks in tty_open()
Evaluate the conditions which prevent this tty being the controlling terminal in one place, just before setting the controlling terminal. Signed-off-by: Peter Hurley <peter@hurleysoftware.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent c2bb524 commit 11e1d4a

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

drivers/tty/tty_io.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1960,7 +1960,7 @@ static struct tty_struct *tty_open_current_tty(dev_t device, struct file *filp)
19601960
* Locking: tty_mutex protects get_tty_driver
19611961
*/
19621962
static struct tty_driver *tty_lookup_driver(dev_t device, struct file *filp,
1963-
int *noctty, int *index)
1963+
int *index)
19641964
{
19651965
struct tty_driver *driver;
19661966

@@ -1970,7 +1970,6 @@ static struct tty_driver *tty_lookup_driver(dev_t device, struct file *filp,
19701970
extern struct tty_driver *console_driver;
19711971
driver = tty_driver_kref_get(console_driver);
19721972
*index = fg_console;
1973-
*noctty = 1;
19741973
break;
19751974
}
19761975
#endif
@@ -1981,7 +1980,6 @@ static struct tty_driver *tty_lookup_driver(dev_t device, struct file *filp,
19811980
if (driver) {
19821981
/* Don't let /dev/console block */
19831982
filp->f_flags |= O_NONBLOCK;
1984-
*noctty = 1;
19851983
break;
19861984
}
19871985
}
@@ -2036,14 +2034,13 @@ static int tty_open(struct inode *inode, struct file *filp)
20362034
if (retval)
20372035
return -ENOMEM;
20382036

2039-
noctty = filp->f_flags & O_NOCTTY;
20402037
index = -1;
20412038
retval = 0;
20422039

20432040
tty = tty_open_current_tty(device, filp);
20442041
if (!tty) {
20452042
mutex_lock(&tty_mutex);
2046-
driver = tty_lookup_driver(device, filp, &noctty, &index);
2043+
driver = tty_lookup_driver(device, filp, &index);
20472044
if (IS_ERR(driver)) {
20482045
retval = PTR_ERR(driver);
20492046
goto err_unlock;
@@ -2091,10 +2088,6 @@ static int tty_open(struct inode *inode, struct file *filp)
20912088
tty_add_file(tty, filp);
20922089

20932090
check_tty_count(tty, __func__);
2094-
if (tty->driver->type == TTY_DRIVER_TYPE_PTY &&
2095-
tty->driver->subtype == PTY_TYPE_MASTER)
2096-
noctty = 1;
2097-
20982091
tty_debug_hangup(tty, "opening (count=%d)\n", tty->count);
20992092

21002093
if (tty->ops->open)
@@ -2127,6 +2120,12 @@ static int tty_open(struct inode *inode, struct file *filp)
21272120

21282121
read_lock(&tasklist_lock);
21292122
spin_lock_irq(&current->sighand->siglock);
2123+
noctty = (filp->f_flags & O_NOCTTY) ||
2124+
device == MKDEV(TTY_MAJOR, 0) ||
2125+
device == MKDEV(TTYAUX_MAJOR, 1) ||
2126+
(tty->driver->type == TTY_DRIVER_TYPE_PTY &&
2127+
tty->driver->subtype == PTY_TYPE_MASTER);
2128+
21302129
if (!noctty &&
21312130
current->signal->leader &&
21322131
!current->signal->tty &&

0 commit comments

Comments
 (0)