tty_kref_put(tty);
}
-/* Called under the sighand lock */
-
+/**
+ * proc_set_tty - set the controlling terminal
+ *
+ * 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
+ * sighand lock
+ */
static void __proc_set_tty(struct tty_struct *tty)
{
unsigned long flags;
mutex_lock(&tty_mutex);
tty_lock(tty);
+ read_lock(&tasklist_lock);
spin_lock_irq(¤t->sighand->siglock);
if (!noctty &&
current->signal->leader &&
tty->session == NULL)
__proc_set_tty(tty);
spin_unlock_irq(¤t->sighand->siglock);
+ read_unlock(&tasklist_lock);
tty_unlock(tty);
mutex_unlock(&tty_mutex);
return 0;
static int tiocsctty(struct tty_struct *tty, int arg)
{
int ret = 0;
- if (current->signal->leader && (task_session(current) == tty->session))
- return ret;
mutex_lock(&tty_mutex);
+ read_lock(&tasklist_lock);
+
+ if (current->signal->leader && (task_session(current) == tty->session))
+ goto unlock;
+
/*
* The process must be a session leader and
* not have a controlling tty already.
/*
* Steal it away
*/
- read_lock(&tasklist_lock);
session_clear_tty(tty->session);
- read_unlock(&tasklist_lock);
} else {
ret = -EPERM;
goto unlock;
}
proc_set_tty(tty);
unlock:
+ read_unlock(&tasklist_lock);
mutex_unlock(&tty_mutex);
return ret;
}