Lines Matching refs:tty

11 #include <linux/tty.h>
14 #include "tty.h"
24 * @tty: tty to check
32 int __tty_check_change(struct tty_struct *tty, int sig)
38 if (current->signal->tty != tty)
44 spin_lock_irqsave(&tty->ctrl_lock, flags);
45 tty_pgrp = tty->pgrp;
46 spin_unlock_irqrestore(&tty->ctrl_lock, flags);
63 tty_warn(tty, "sig=%d, tty->pgrp == NULL!\n", sig);
68 int tty_check_change(struct tty_struct *tty)
70 return __tty_check_change(tty, SIGTTOU);
77 struct tty_struct *tty;
79 tty = p->signal->tty;
80 p->signal->tty = NULL;
82 tty_kref_put(tty);
95 static void __proc_set_tty(struct tty_struct *tty)
99 spin_lock_irqsave(&tty->ctrl_lock, flags);
102 * tiocsctty() is stealing the controlling tty
104 put_pid(tty->session);
105 put_pid(tty->pgrp);
106 tty->pgrp = get_pid(task_pgrp(current));
107 tty->session = get_pid(task_session(current));
108 spin_unlock_irqrestore(&tty->ctrl_lock, flags);
109 if (current->signal->tty) {
110 tty_debug(tty, "current tty %s not NULL!!\n",
111 current->signal->tty->name);
112 tty_kref_put(current->signal->tty);
115 current->signal->tty = tty_kref_get(tty);
119 static void proc_set_tty(struct tty_struct *tty)
122 __proc_set_tty(tty);
127 * Called by tty_open() to set the controlling tty if applicable.
129 void tty_open_proc_set_tty(struct file *filp, struct tty_struct *tty)
134 !current->signal->tty &&
135 tty->session == NULL) {
137 * Don't let a process that only has write access to the tty
138 * obtain the privileges associated with having a tty as
140 * access through /dev/tty, being able to perform pushback).
141 * Many distributions set the group of all ttys to "tty" and
142 * grant write-only access to all terminals for setgid tty
151 __proc_set_tty(tty);
159 struct tty_struct *tty;
163 tty = tty_kref_get(current->signal->tty);
165 return tty;
182 * @tty: controlling tty
188 * Returns the number of processes in the session with this tty
190 * tty references for those processes.
192 int tty_signal_session_leader(struct tty_struct *tty, int exit_session)
199 if (tty->session) {
200 do_each_pid_task(tty->session, PIDTYPE_SID, p) {
202 if (p->signal->tty == tty) {
203 p->signal->tty = NULL;
215 spin_lock(&tty->ctrl_lock);
216 tty_pgrp = get_pid(tty->pgrp);
217 if (tty->pgrp)
218 p->signal->tty_old_pgrp = get_pid(tty->pgrp);
219 spin_unlock(&tty->ctrl_lock);
221 } while_each_pid_task(tty->session, PIDTYPE_SID, p);
235 * disassociate_ctty - disconnect controlling tty
239 * it wants to disassociate itself from its controlling tty.
243 * (2) Clears the tty from being controlling the session
244 * (3) Clears the controlling tty for all processes in the
253 * tty_mutex is taken to protect tty
260 struct tty_struct *tty;
265 tty = get_current_tty();
266 if (tty) {
267 if (on_exit && tty->driver->type != TTY_DRIVER_TYPE_PTY) {
268 tty_vhangup_session(tty);
270 struct pid *tty_pgrp = tty_get_pgrp(tty);
278 tty_kref_put(tty);
294 tty = get_current_tty();
295 if (tty) {
298 tty_lock(tty);
299 spin_lock_irqsave(&tty->ctrl_lock, flags);
300 put_pid(tty->session);
301 put_pid(tty->pgrp);
302 tty->session = NULL;
303 tty->pgrp = NULL;
304 spin_unlock_irqrestore(&tty->ctrl_lock, flags);
305 tty_unlock(tty);
306 tty_kref_put(tty);
309 /* If tty->ctrl.pgrp is not NULL, it may be assigned to
312 * after tty->ctrl.pgrp set to NULL.
319 /* Now clear signal->tty under the lock */
327 * no_tty - Ensure the current process does not have a controlling tty
340 * tiocsctty - set controlling tty
341 * @tty: tty structure
345 * leader to set this tty as the controlling tty for the session.
348 * Takes tty_lock() to serialize proc_set_tty() for this tty
350 * Takes ->siglock() when updating signal->tty
352 static int tiocsctty(struct tty_struct *tty, struct file *file, int arg)
356 tty_lock(tty);
359 if (current->signal->leader && (task_session(current) == tty->session))
364 * not have a controlling tty already.
366 if (!current->signal->leader || current->signal->tty) {
371 if (tty->session) {
373 * This tty is already the controlling
374 * tty for another session group!
380 session_clear_tty(tty->session);
393 proc_set_tty(tty);
396 tty_unlock(tty);
402 * @tty: tty to read
405 * group controlling the tty.
407 struct pid *tty_get_pgrp(struct tty_struct *tty)
412 spin_lock_irqsave(&tty->ctrl_lock, flags);
413 pgrp = get_pid(tty->pgrp);
414 spin_unlock_irqrestore(&tty->ctrl_lock, flags);
443 * @tty: tty passed by user
444 * @real_tty: tty side of the tty passed by the user if a pty else the tty
447 * Obtain the process group of the tty. If there is no process group
450 * Locking: none. Reference to current->signal->tty is safe.
452 static int tiocgpgrp(struct tty_struct *tty, struct tty_struct *real_tty, pid_t __user *p)
457 * (tty == real_tty) is a cheap way of
458 * testing if the tty is NOT a master pty.
460 if (tty == real_tty && current->signal->tty != real_tty)
470 * @tty: tty passed by user
471 * @real_tty: tty side device matching tty passed by user
474 * Set the process group of the tty to the session passed. Only
475 * permitted where the tty session is our session.
479 static int tiocspgrp(struct tty_struct *tty, struct tty_struct *real_tty, pid_t __user *p)
496 if (!current->signal->tty ||
497 (current->signal->tty != real_tty) ||
522 * @tty: tty passed by user
523 * @real_tty: tty side of the tty passed by the user if a pty else the tty
526 * Obtain the session id of the tty. If there is no session
529 static int tiocgsid(struct tty_struct *tty, struct tty_struct *real_tty, pid_t __user *p)
535 * (tty == real_tty) is a cheap way of
536 * testing if the tty is NOT a master pty.
538 if (tty == real_tty && current->signal->tty != real_tty)
555 * Called from tty_ioctl(). If tty is a pty then real_tty is the slave side,
556 * if not then tty == real_tty.
558 long tty_jobctrl_ioctl(struct tty_struct *tty, struct tty_struct *real_tty,
565 if (current->signal->tty != tty)
572 return tiocgpgrp(tty, real_tty, p);
574 return tiocspgrp(tty, real_tty, p);
576 return tiocgsid(tty, real_tty, p);