Lines Matching full:tty

11 #include <linux/tty.h>
14 #include "tty.h"
24 * @tty: tty to check
33 int __tty_check_change(struct tty_struct *tty, int sig) in __tty_check_change() argument
39 if (current->signal->tty != tty) in __tty_check_change()
45 spin_lock_irqsave(&tty->ctrl.lock, flags); in __tty_check_change()
46 tty_pgrp = tty->ctrl.pgrp; in __tty_check_change()
47 spin_unlock_irqrestore(&tty->ctrl.lock, flags); in __tty_check_change()
64 tty_warn(tty, "sig=%d, tty->pgrp == NULL!\n", sig); in __tty_check_change()
69 int tty_check_change(struct tty_struct *tty) in tty_check_change() argument
71 return __tty_check_change(tty, SIGTTOU); in tty_check_change()
78 struct tty_struct *tty; in proc_clear_tty() local
81 tty = p->signal->tty; in proc_clear_tty()
82 p->signal->tty = NULL; in proc_clear_tty()
84 tty_kref_put(tty); in proc_clear_tty()
89 * @tty: tty structure
98 static void __proc_set_tty(struct tty_struct *tty) in __proc_set_tty() argument
102 spin_lock_irqsave(&tty->ctrl.lock, flags); in __proc_set_tty()
105 * tiocsctty() is stealing the controlling tty in __proc_set_tty()
107 put_pid(tty->ctrl.session); in __proc_set_tty()
108 put_pid(tty->ctrl.pgrp); in __proc_set_tty()
109 tty->ctrl.pgrp = get_pid(task_pgrp(current)); in __proc_set_tty()
110 tty->ctrl.session = get_pid(task_session(current)); in __proc_set_tty()
111 spin_unlock_irqrestore(&tty->ctrl.lock, flags); in __proc_set_tty()
112 if (current->signal->tty) { in __proc_set_tty()
113 tty_debug(tty, "current tty %s not NULL!!\n", in __proc_set_tty()
114 current->signal->tty->name); in __proc_set_tty()
115 tty_kref_put(current->signal->tty); in __proc_set_tty()
118 current->signal->tty = tty_kref_get(tty); in __proc_set_tty()
122 static void proc_set_tty(struct tty_struct *tty) in proc_set_tty() argument
125 __proc_set_tty(tty); in proc_set_tty()
130 * Called by tty_open() to set the controlling tty if applicable.
132 void tty_open_proc_set_tty(struct file *filp, struct tty_struct *tty) in tty_open_proc_set_tty() argument
137 !current->signal->tty && in tty_open_proc_set_tty()
138 tty->ctrl.session == NULL) { in tty_open_proc_set_tty()
140 * Don't let a process that only has write access to the tty in tty_open_proc_set_tty()
141 * obtain the privileges associated with having a tty as in tty_open_proc_set_tty()
143 * access through /dev/tty, being able to perform pushback). in tty_open_proc_set_tty()
144 * Many distributions set the group of all ttys to "tty" and in tty_open_proc_set_tty()
145 * grant write-only access to all terminals for setgid tty in tty_open_proc_set_tty()
154 __proc_set_tty(tty); in tty_open_proc_set_tty()
162 struct tty_struct *tty; in get_current_tty() local
166 tty = tty_kref_get(current->signal->tty); in get_current_tty()
168 return tty; in get_current_tty()
186 * @tty: controlling tty
192 * Returns the number of processes in the session with this tty
194 * tty references for those processes.
196 int tty_signal_session_leader(struct tty_struct *tty, int exit_session) in tty_signal_session_leader() argument
203 if (tty->ctrl.session) { in tty_signal_session_leader()
204 do_each_pid_task(tty->ctrl.session, PIDTYPE_SID, p) { in tty_signal_session_leader()
206 if (p->signal->tty == tty) { in tty_signal_session_leader()
207 p->signal->tty = NULL; in tty_signal_session_leader()
221 spin_lock(&tty->ctrl.lock); in tty_signal_session_leader()
222 tty_pgrp = get_pid(tty->ctrl.pgrp); in tty_signal_session_leader()
223 if (tty->ctrl.pgrp) in tty_signal_session_leader()
225 get_pid(tty->ctrl.pgrp); in tty_signal_session_leader()
226 spin_unlock(&tty->ctrl.lock); in tty_signal_session_leader()
228 } while_each_pid_task(tty->ctrl.session, PIDTYPE_SID, p); in tty_signal_session_leader()
242 * disassociate_ctty - disconnect controlling tty
246 * it wants to disassociate itself from its controlling tty.
250 * (2) Clears the tty from being controlling the session
251 * (3) Clears the controlling tty for all processes in the
260 * tty_mutex is taken to protect tty
267 struct tty_struct *tty; in disassociate_ctty() local
272 tty = get_current_tty(); in disassociate_ctty()
273 if (tty) { in disassociate_ctty()
274 if (on_exit && tty->driver->type != TTY_DRIVER_TYPE_PTY) { in disassociate_ctty()
275 tty_vhangup_session(tty); in disassociate_ctty()
277 struct pid *tty_pgrp = tty_get_pgrp(tty); in disassociate_ctty()
286 tty_kref_put(tty); in disassociate_ctty()
303 tty = get_current_tty(); in disassociate_ctty()
304 if (tty) { in disassociate_ctty()
307 tty_lock(tty); in disassociate_ctty()
308 spin_lock_irqsave(&tty->ctrl.lock, flags); in disassociate_ctty()
309 put_pid(tty->ctrl.session); in disassociate_ctty()
310 put_pid(tty->ctrl.pgrp); in disassociate_ctty()
311 tty->ctrl.session = NULL; in disassociate_ctty()
312 tty->ctrl.pgrp = NULL; in disassociate_ctty()
313 spin_unlock_irqrestore(&tty->ctrl.lock, flags); in disassociate_ctty()
314 tty_unlock(tty); in disassociate_ctty()
315 tty_kref_put(tty); in disassociate_ctty()
318 /* If tty->ctrl.pgrp is not NULL, it may be assigned to in disassociate_ctty()
321 * after tty->ctrl.pgrp set to NULL. in disassociate_ctty()
328 /* Now clear signal->tty under the lock */ in disassociate_ctty()
336 * no_tty - Ensure the current process does not have a controlling tty
352 * tiocsctty - set controlling tty
353 * @tty: tty structure
358 * leader to set this tty as the controlling tty for the session.
361 * Takes tty_lock() to serialize proc_set_tty() for this tty
363 * Takes ->siglock() when updating signal->tty
365 static int tiocsctty(struct tty_struct *tty, struct file *file, int arg) in tiocsctty() argument
369 tty_lock(tty); in tiocsctty()
373 task_session(current) == tty->ctrl.session) in tiocsctty()
378 * not have a controlling tty already. in tiocsctty()
380 if (!current->signal->leader || current->signal->tty) { in tiocsctty()
385 if (tty->ctrl.session) { in tiocsctty()
387 * This tty is already the controlling in tiocsctty()
388 * tty for another session group! in tiocsctty()
394 session_clear_tty(tty->ctrl.session); in tiocsctty()
407 proc_set_tty(tty); in tiocsctty()
410 tty_unlock(tty); in tiocsctty()
416 * @tty: tty to read
419 * group controlling the tty.
421 struct pid *tty_get_pgrp(struct tty_struct *tty) in tty_get_pgrp() argument
426 spin_lock_irqsave(&tty->ctrl.lock, flags); in tty_get_pgrp()
427 pgrp = get_pid(tty->ctrl.pgrp); in tty_get_pgrp()
428 spin_unlock_irqrestore(&tty->ctrl.lock, flags); in tty_get_pgrp()
457 * @tty: tty passed by user
458 * @real_tty: tty side of the tty passed by the user if a pty else the tty
461 * Obtain the process group of the tty. If there is no process group
464 * Locking: none. Reference to current->signal->tty is safe.
466 static int tiocgpgrp(struct tty_struct *tty, struct tty_struct *real_tty, pid_t __user *p) in tiocgpgrp() argument
471 * (tty == real_tty) is a cheap way of in tiocgpgrp()
472 * testing if the tty is NOT a master pty. in tiocgpgrp()
474 if (tty == real_tty && current->signal->tty != real_tty) in tiocgpgrp()
484 * @tty: tty passed by user
485 * @real_tty: tty side device matching tty passed by user
488 * Set the process group of the tty to the session passed. Only
489 * permitted where the tty session is our session.
493 static int tiocspgrp(struct tty_struct *tty, struct tty_struct *real_tty, pid_t __user *p) in tiocspgrp() argument
510 if (!current->signal->tty || in tiocspgrp()
511 (current->signal->tty != real_tty) || in tiocspgrp()
536 * @tty: tty passed by user
537 * @real_tty: tty side of the tty passed by the user if a pty else the tty
540 * Obtain the session id of the tty. If there is no session
543 static int tiocgsid(struct tty_struct *tty, struct tty_struct *real_tty, pid_t __user *p) in tiocgsid() argument
549 * (tty == real_tty) is a cheap way of in tiocgsid()
550 * testing if the tty is NOT a master pty. in tiocgsid()
552 if (tty == real_tty && current->signal->tty != real_tty) in tiocgsid()
569 * Called from tty_ioctl(). If tty is a pty then real_tty is the slave side,
570 * if not then tty == real_tty.
572 long tty_jobctrl_ioctl(struct tty_struct *tty, struct tty_struct *real_tty, in tty_jobctrl_ioctl() argument
579 if (current->signal->tty != tty) in tty_jobctrl_ioctl()
586 return tiocgpgrp(tty, real_tty, p); in tty_jobctrl_ioctl()
588 return tiocspgrp(tty, real_tty, p); in tty_jobctrl_ioctl()
590 return tiocgsid(tty, real_tty, p); in tty_jobctrl_ioctl()