Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 11e1d4aa authored by Peter Hurley's avatar Peter Hurley Committed by Greg Kroah-Hartman
Browse files

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: default avatarPeter Hurley <peter@hurleysoftware.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent c2bb524b
Loading
Loading
Loading
Loading
+8 −9
Original line number Original line Diff line number Diff line
@@ -1960,7 +1960,7 @@ static struct tty_struct *tty_open_current_tty(dev_t device, struct file *filp)
 *	Locking: tty_mutex protects get_tty_driver
 *	Locking: tty_mutex protects get_tty_driver
 */
 */
static struct tty_driver *tty_lookup_driver(dev_t device, struct file *filp,
static struct tty_driver *tty_lookup_driver(dev_t device, struct file *filp,
		int *noctty, int *index)
		int *index)
{
{
	struct tty_driver *driver;
	struct tty_driver *driver;


@@ -1970,7 +1970,6 @@ static struct tty_driver *tty_lookup_driver(dev_t device, struct file *filp,
		extern struct tty_driver *console_driver;
		extern struct tty_driver *console_driver;
		driver = tty_driver_kref_get(console_driver);
		driver = tty_driver_kref_get(console_driver);
		*index = fg_console;
		*index = fg_console;
		*noctty = 1;
		break;
		break;
	}
	}
#endif
#endif
@@ -1981,7 +1980,6 @@ static struct tty_driver *tty_lookup_driver(dev_t device, struct file *filp,
			if (driver) {
			if (driver) {
				/* Don't let /dev/console block */
				/* Don't let /dev/console block */
				filp->f_flags |= O_NONBLOCK;
				filp->f_flags |= O_NONBLOCK;
				*noctty = 1;
				break;
				break;
			}
			}
		}
		}
@@ -2036,14 +2034,13 @@ static int tty_open(struct inode *inode, struct file *filp)
	if (retval)
	if (retval)
		return -ENOMEM;
		return -ENOMEM;


	noctty = filp->f_flags & O_NOCTTY;
	index  = -1;
	index  = -1;
	retval = 0;
	retval = 0;


	tty = tty_open_current_tty(device, filp);
	tty = tty_open_current_tty(device, filp);
	if (!tty) {
	if (!tty) {
		mutex_lock(&tty_mutex);
		mutex_lock(&tty_mutex);
		driver = tty_lookup_driver(device, filp, &noctty, &index);
		driver = tty_lookup_driver(device, filp, &index);
		if (IS_ERR(driver)) {
		if (IS_ERR(driver)) {
			retval = PTR_ERR(driver);
			retval = PTR_ERR(driver);
			goto err_unlock;
			goto err_unlock;
@@ -2091,10 +2088,6 @@ static int tty_open(struct inode *inode, struct file *filp)
	tty_add_file(tty, filp);
	tty_add_file(tty, filp);


	check_tty_count(tty, __func__);
	check_tty_count(tty, __func__);
	if (tty->driver->type == TTY_DRIVER_TYPE_PTY &&
	    tty->driver->subtype == PTY_TYPE_MASTER)
		noctty = 1;

	tty_debug_hangup(tty, "opening (count=%d)\n", tty->count);
	tty_debug_hangup(tty, "opening (count=%d)\n", tty->count);


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


	read_lock(&tasklist_lock);
	read_lock(&tasklist_lock);
	spin_lock_irq(&current->sighand->siglock);
	spin_lock_irq(&current->sighand->siglock);
	noctty = (filp->f_flags & O_NOCTTY) ||
			device == MKDEV(TTY_MAJOR, 0) ||
			device == MKDEV(TTYAUX_MAJOR, 1) ||
			(tty->driver->type == TTY_DRIVER_TYPE_PTY &&
			 tty->driver->subtype == PTY_TYPE_MASTER);

	if (!noctty &&
	if (!noctty &&
	    current->signal->leader &&
	    current->signal->leader &&
	    !current->signal->tty &&
	    !current->signal->tty &&