* Only callable by the session leader and only if it does not already have
* a controlling terminal.
*
- * Caller must hold: a readlock on tasklist_lock
+ * Caller must hold: tty_lock()
+ * a readlock on tasklist_lock
* sighand lock
*/
static void __proc_set_tty(struct tty_struct *tty)
goto retry_open;
}
clear_bit(TTY_HUPPED, &tty->flags);
- tty_unlock(tty);
- mutex_lock(&tty_mutex);
- tty_lock(tty);
read_lock(&tasklist_lock);
spin_lock_irq(¤t->sighand->siglock);
if (!noctty &&
spin_unlock_irq(¤t->sighand->siglock);
read_unlock(&tasklist_lock);
tty_unlock(tty);
- mutex_unlock(&tty_mutex);
return 0;
err_unlock:
mutex_unlock(&tty_mutex);
* leader to set this tty as the controlling tty for the session.
*
* Locking:
- * Takes tty_mutex() to protect tty instance
+ * Takes tty_lock() to serialize proc_set_tty() for this tty
* Takes tasklist_lock internally to walk sessions
* Takes ->siglock() when updating signal->tty
*/
{
int ret = 0;
- mutex_lock(&tty_mutex);
+ tty_lock(tty);
read_lock(&tasklist_lock);
if (current->signal->leader && (task_session(current) == tty->session))
proc_set_tty(tty);
unlock:
read_unlock(&tasklist_lock);
- mutex_unlock(&tty_mutex);
+ tty_unlock(tty);
return ret;
}