Lines Matching +full:ctrl +full:- +full:a

1 // SPDX-License-Identifier: GPL-2.0
18 return (sigismember(&current->blocked, sig) || in is_ignored()
19 current->sighand->action[sig-1].sa.sa_handler == SIG_IGN); in is_ignored()
23 * __tty_check_change - check for POSIX terminal changes
27 * If we try to write to, or set the state of, a terminal and we're
28 * not in the foreground, send a SIGTTOU. If the signal is blocked or
31 * Locking: ctrl.lock
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()
52 ret = -EIO; in __tty_check_change()
54 ret = -EIO; in __tty_check_change()
58 ret = -ERESTARTSYS; in __tty_check_change()
64 tty_warn(tty, "sig=%d, tty->pgrp == NULL!\n", sig); in __tty_check_change()
80 spin_lock_irqsave(&p->sighand->siglock, flags); in proc_clear_tty()
81 tty = p->signal->tty; in proc_clear_tty()
82 p->signal->tty = NULL; in proc_clear_tty()
83 spin_unlock_irqrestore(&p->sighand->siglock, flags); in proc_clear_tty()
88 * __proc_set_tty - set the controlling terminal
92 * a controlling terminal.
95 * a readlock on tasklist_lock
102 spin_lock_irqsave(&tty->ctrl.lock, flags); in __proc_set_tty()
104 * The session and fg pgrp references will be non-NULL if 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()
114 current->signal->tty->name); in __proc_set_tty()
115 tty_kref_put(current->signal->tty); in __proc_set_tty()
117 put_pid(current->signal->tty_old_pgrp); in __proc_set_tty()
118 current->signal->tty = tty_kref_get(tty); in __proc_set_tty()
119 current->signal->tty_old_pgrp = NULL; in __proc_set_tty()
124 spin_lock_irq(&current->sighand->siglock); in proc_set_tty()
126 spin_unlock_irq(&current->sighand->siglock); in proc_set_tty()
135 spin_lock_irq(&current->sighand->siglock); in tty_open_proc_set_tty()
136 if (current->signal->leader && in tty_open_proc_set_tty()
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()
145 * grant write-only access to all terminals for setgid tty in tty_open_proc_set_tty()
149 * on a write-only file descriptor. In that case, it might be in tty_open_proc_set_tty()
153 if (filp->f_mode & FMODE_READ) in tty_open_proc_set_tty()
156 spin_unlock_irq(&current->sighand->siglock); in tty_open_proc_set_tty()
165 spin_lock_irqsave(&current->sighand->siglock, flags); in get_current_tty()
166 tty = tty_kref_get(current->signal->tty); in get_current_tty()
167 spin_unlock_irqrestore(&current->sighand->siglock, flags); in get_current_tty()
185 * tty_signal_session_leader - sends SIGHUP to session leader
187 * @exit_session: if non-zero, signal all foreground group processes
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()
205 spin_lock_irq(&p->sighand->siglock); 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()
214 if (!p->signal->leader) { in tty_signal_session_leader()
215 spin_unlock_irq(&p->sighand->siglock); in tty_signal_session_leader()
220 put_pid(p->signal->tty_old_pgrp); /* A noop */ 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()
224 p->signal->tty_old_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()
227 spin_unlock_irq(&p->sighand->siglock); 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
249 * (1) Sends a SIGHUP and SIGCONT to the foreground process group
254 * The argument on_exit is set to 1 if called when a process is
261 * ->siglock is taken to protect ->signal/->sighand
263 * ->siglock is taken to protect ->signal/->sighand
269 if (!current->signal->leader) in disassociate_ctty()
274 if (on_exit && tty->driver->type != TTY_DRIVER_TYPE_PTY) { in disassociate_ctty()
291 spin_lock_irq(&current->sighand->siglock); in disassociate_ctty()
292 old_pgrp = current->signal->tty_old_pgrp; in disassociate_ctty()
293 current->signal->tty_old_pgrp = NULL; in disassociate_ctty()
294 spin_unlock_irq(&current->sighand->siglock); 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()
318 /* If tty->ctrl.pgrp is not NULL, it may be assigned to in disassociate_ctty()
319 * current->signal->tty_old_pgrp in a race condition, and in disassociate_ctty()
320 * cause pid memleak. Release current->signal->tty_old_pgrp in disassociate_ctty()
321 * after tty->ctrl.pgrp set to NULL. in disassociate_ctty()
323 spin_lock_irq(&current->sighand->siglock); in disassociate_ctty()
324 put_pid(current->signal->tty_old_pgrp); in disassociate_ctty()
325 current->signal->tty_old_pgrp = NULL; in disassociate_ctty()
326 spin_unlock_irq(&current->sighand->siglock); 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
342 * between a new association and proc_clear_tty but possibly we need in no_tty()
352 * tiocsctty - set controlling tty
357 * This ioctl is used to manage job control. It permits a session
363 * Takes ->siglock() when updating signal->tty
372 if (current->signal->leader && in tiocsctty()
373 task_session(current) == tty->ctrl.session) in tiocsctty()
377 * The process must be a session leader and in tiocsctty()
378 * not have a controlling tty already. in tiocsctty()
380 if (!current->signal->leader || current->signal->tty) { in tiocsctty()
381 ret = -EPERM; in tiocsctty()
385 if (tty->ctrl.session) { in tiocsctty()
394 session_clear_tty(tty->ctrl.session); in tiocsctty()
396 ret = -EPERM; in tiocsctty()
402 if ((file->f_mode & FMODE_READ) == 0 && !capable(CAP_SYS_ADMIN)) { in tiocsctty()
403 ret = -EPERM; in tiocsctty()
415 * tty_get_pgrp - return a ref counted pgrp pid
418 * Returns a refcounted instance of the pid struct for the process
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()
436 * satisfactory pgrp is found. I dunno - gdb doesn't work correctly
456 * tiocgpgrp - get process group
458 * @real_tty: tty side of the tty passed by the user if a pty else the tty
464 * Locking: none. Reference to current->signal->tty is safe.
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()
475 return -ENOTTY; in tiocgpgrp()
483 * tiocspgrp - attempt to set process group
491 * Locking: RCU, ctrl lock
499 if (retval == -EIO) in tiocspgrp()
500 return -ENOTTY; in tiocspgrp()
505 return -EFAULT; in tiocspgrp()
507 return -EINVAL; in tiocspgrp()
509 spin_lock_irq(&real_tty->ctrl.lock); in tiocspgrp()
510 if (!current->signal->tty || in tiocspgrp()
511 (current->signal->tty != real_tty) || in tiocspgrp()
512 (real_tty->ctrl.session != task_session(current))) { in tiocspgrp()
513 retval = -ENOTTY; in tiocspgrp()
518 retval = -ESRCH; in tiocspgrp()
521 retval = -EPERM; in tiocspgrp()
525 put_pid(real_tty->ctrl.pgrp); in tiocspgrp()
526 real_tty->ctrl.pgrp = get_pid(pgrp); in tiocspgrp()
530 spin_unlock_irq(&real_tty->ctrl.lock); in tiocspgrp()
535 * tiocgsid - get session id
537 * @real_tty: tty side of the tty passed by the user if a pty else the tty
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()
553 return -ENOTTY; in tiocgsid()
555 spin_lock_irqsave(&real_tty->ctrl.lock, flags); in tiocgsid()
556 if (!real_tty->ctrl.session) in tiocgsid()
558 sid = pid_vnr(real_tty->ctrl.session); in tiocgsid()
559 spin_unlock_irqrestore(&real_tty->ctrl.lock, flags); in tiocgsid()
564 spin_unlock_irqrestore(&real_tty->ctrl.lock, flags); in tiocgsid()
565 return -ENOTTY; in tiocgsid()
569 * Called from tty_ioctl(). If tty is a pty then real_tty is the slave side,
579 if (current->signal->tty != tty) in tty_jobctrl_ioctl()
580 return -ENOTTY; in tty_jobctrl_ioctl()
592 return -ENOIOCTLCMD; in tty_jobctrl_ioctl()