tty: Combine SIGTTOU/SIGTTIN handling
The job_control() check in n_tty_read() has nearly identical purpose and results as tty_check_change(). Both functions' purpose is to determine if the current task's pgrp is the foreground pgrp for the tty, and if not, to signal the current pgrp. Introduce __tty_check_change() which takes the signal to send and performs the shared operations for job control() and tty_check_change(). Signed-off-by: Peter Hurley <peter@hurleysoftware.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
71a5cd8a4a
commit
2812d9e9fd
3 changed files with 27 additions and 46 deletions
|
@ -2138,37 +2138,15 @@ extern ssize_t redirected_tty_write(struct file *, const char __user *,
|
||||||
|
|
||||||
static int job_control(struct tty_struct *tty, struct file *file)
|
static int job_control(struct tty_struct *tty, struct file *file)
|
||||||
{
|
{
|
||||||
struct pid *pgrp;
|
|
||||||
|
|
||||||
/* Job control check -- must be done at start and after
|
/* Job control check -- must be done at start and after
|
||||||
every sleep (POSIX.1 7.1.1.4). */
|
every sleep (POSIX.1 7.1.1.4). */
|
||||||
/* NOTE: not yet done after every sleep pending a thorough
|
/* NOTE: not yet done after every sleep pending a thorough
|
||||||
check of the logic of this change. -- jlc */
|
check of the logic of this change. -- jlc */
|
||||||
/* don't stop on /dev/console */
|
/* don't stop on /dev/console */
|
||||||
if (file->f_op->write == redirected_tty_write ||
|
if (file->f_op->write == redirected_tty_write)
|
||||||
current->signal->tty != tty)
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
rcu_read_lock();
|
return __tty_check_change(tty, SIGTTIN);
|
||||||
pgrp = task_pgrp(current);
|
|
||||||
|
|
||||||
spin_lock_irq(&tty->ctrl_lock);
|
|
||||||
if (!tty->pgrp)
|
|
||||||
printk(KERN_ERR "n_tty_read: no tty->pgrp!\n");
|
|
||||||
else if (pgrp != tty->pgrp) {
|
|
||||||
spin_unlock_irq(&tty->ctrl_lock);
|
|
||||||
if (is_ignored(SIGTTIN) || is_current_pgrp_orphaned()) {
|
|
||||||
rcu_read_unlock();
|
|
||||||
return -EIO;
|
|
||||||
}
|
|
||||||
kill_pgrp(pgrp, SIGTTIN, 1);
|
|
||||||
rcu_read_unlock();
|
|
||||||
set_thread_flag(TIF_SIGPENDING);
|
|
||||||
return -ERESTARTSYS;
|
|
||||||
}
|
|
||||||
spin_unlock_irq(&tty->ctrl_lock);
|
|
||||||
rcu_read_unlock();
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -390,10 +390,10 @@ EXPORT_SYMBOL_GPL(tty_find_polling_driver);
|
||||||
* Locking: ctrl_lock
|
* Locking: ctrl_lock
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int tty_check_change(struct tty_struct *tty)
|
int __tty_check_change(struct tty_struct *tty, int sig)
|
||||||
{
|
{
|
||||||
unsigned long flags;
|
unsigned long flags;
|
||||||
struct pid *pgrp;
|
struct pid *pgrp, *tty_pgrp;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
if (current->signal->tty != tty)
|
if (current->signal->tty != tty)
|
||||||
|
@ -403,33 +403,35 @@ int tty_check_change(struct tty_struct *tty)
|
||||||
pgrp = task_pgrp(current);
|
pgrp = task_pgrp(current);
|
||||||
|
|
||||||
spin_lock_irqsave(&tty->ctrl_lock, flags);
|
spin_lock_irqsave(&tty->ctrl_lock, flags);
|
||||||
|
tty_pgrp = tty->pgrp;
|
||||||
if (!tty->pgrp) {
|
|
||||||
printk(KERN_WARNING "tty_check_change: tty->pgrp == NULL!\n");
|
|
||||||
goto out_unlock;
|
|
||||||
}
|
|
||||||
if (pgrp == tty->pgrp)
|
|
||||||
goto out_unlock;
|
|
||||||
spin_unlock_irqrestore(&tty->ctrl_lock, flags);
|
spin_unlock_irqrestore(&tty->ctrl_lock, flags);
|
||||||
|
|
||||||
if (is_ignored(SIGTTOU))
|
if (tty_pgrp && pgrp != tty->pgrp) {
|
||||||
goto out_rcuunlock;
|
if (is_ignored(sig)) {
|
||||||
if (is_current_pgrp_orphaned()) {
|
if (sig == SIGTTIN)
|
||||||
ret = -EIO;
|
ret = -EIO;
|
||||||
goto out_rcuunlock;
|
} else if (is_current_pgrp_orphaned())
|
||||||
}
|
ret = -EIO;
|
||||||
kill_pgrp(pgrp, SIGTTOU, 1);
|
else {
|
||||||
rcu_read_unlock();
|
kill_pgrp(pgrp, sig, 1);
|
||||||
set_thread_flag(TIF_SIGPENDING);
|
set_thread_flag(TIF_SIGPENDING);
|
||||||
ret = -ERESTARTSYS;
|
ret = -ERESTARTSYS;
|
||||||
return ret;
|
}
|
||||||
out_unlock:
|
}
|
||||||
spin_unlock_irqrestore(&tty->ctrl_lock, flags);
|
|
||||||
out_rcuunlock:
|
|
||||||
rcu_read_unlock();
|
rcu_read_unlock();
|
||||||
|
|
||||||
|
if (!tty_pgrp) {
|
||||||
|
pr_warn("%s: tty_check_change: sig=%d, tty->pgrp == NULL!\n",
|
||||||
|
tty_name(tty), sig);
|
||||||
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int tty_check_change(struct tty_struct *tty)
|
||||||
|
{
|
||||||
|
return __tty_check_change(tty, SIGTTOU);
|
||||||
|
}
|
||||||
EXPORT_SYMBOL(tty_check_change);
|
EXPORT_SYMBOL(tty_check_change);
|
||||||
|
|
||||||
static ssize_t hung_up_tty_read(struct file *file, char __user *buf,
|
static ssize_t hung_up_tty_read(struct file *file, char __user *buf,
|
||||||
|
|
|
@ -423,6 +423,7 @@ extern int tty_paranoia_check(struct tty_struct *tty, struct inode *inode,
|
||||||
const char *routine);
|
const char *routine);
|
||||||
extern const char *tty_name(const struct tty_struct *tty);
|
extern const char *tty_name(const struct tty_struct *tty);
|
||||||
extern void tty_wait_until_sent(struct tty_struct *tty, long timeout);
|
extern void tty_wait_until_sent(struct tty_struct *tty, long timeout);
|
||||||
|
extern int __tty_check_change(struct tty_struct *tty, int sig);
|
||||||
extern int tty_check_change(struct tty_struct *tty);
|
extern int tty_check_change(struct tty_struct *tty);
|
||||||
extern void __stop_tty(struct tty_struct *tty);
|
extern void __stop_tty(struct tty_struct *tty);
|
||||||
extern void stop_tty(struct tty_struct *tty);
|
extern void stop_tty(struct tty_struct *tty);
|
||||||
|
|
Loading…
Add table
Reference in a new issue