Commit ab521dc0 authored by Eric W. Biederman's avatar Eric W. Biederman Committed by Linus Torvalds

[PATCH] tty: update the tty layer to work with struct pid

Of kernel subsystems that work with pids the tty layer is probably the largest
consumer.  But it has the nice virtue that the assiation with a session only
lasts until the session leader exits.  Which means that no reference counting
is required.  So using struct pid winds up being a simple optimization to
avoid hash table lookups.

In the long term the use of pid_nr also ensures that when we have multiple pid
spaces mixed everything will work correctly.
Signed-off-by: default avatarEric W. Biederman <eric@maxwell.lnxi.com>
Cc: Alan Cox <alan@lxorguk.ukuu.org.uk>
Cc: Oleg Nesterov <oleg@tv-sign.ru>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 3e7cd6c4
...@@ -774,7 +774,7 @@ static irqreturn_t winch_interrupt(int irq, void *data) ...@@ -774,7 +774,7 @@ static irqreturn_t winch_interrupt(int irq, void *data)
line = tty->driver_data; line = tty->driver_data;
chan_window_size(&line->chan_list, &tty->winsize.ws_row, chan_window_size(&line->chan_list, &tty->winsize.ws_row,
&tty->winsize.ws_col); &tty->winsize.ws_col);
kill_pg(tty->pgrp, SIGWINCH, 1); kill_pgrp(tty->pgrp, SIGWINCH, 1);
} }
out: out:
if(winch->fd != -1) if(winch->fd != -1)
......
...@@ -1271,8 +1271,8 @@ static void do_input(struct work_struct *work) ...@@ -1271,8 +1271,8 @@ static void do_input(struct work_struct *work)
// code duplicated from n_tty (ldisc) // code duplicated from n_tty (ldisc)
static inline void isig(int sig, struct tty_struct *tty, int flush) static inline void isig(int sig, struct tty_struct *tty, int flush)
{ {
if (tty->pgrp > 0) if (tty->pgrp)
kill_pg(tty->pgrp, sig, 1); kill_pgrp(tty->pgrp, sig, 1);
if (flush || !L_NOFLSH(tty)) { if (flush || !L_NOFLSH(tty)) {
if ( tty->ldisc.flush_buffer ) if ( tty->ldisc.flush_buffer )
tty->ldisc.flush_buffer(tty); tty->ldisc.flush_buffer(tty);
......
...@@ -579,8 +579,8 @@ static void eraser(unsigned char c, struct tty_struct *tty) ...@@ -579,8 +579,8 @@ static void eraser(unsigned char c, struct tty_struct *tty)
static inline void isig(int sig, struct tty_struct *tty, int flush) static inline void isig(int sig, struct tty_struct *tty, int flush)
{ {
if (tty->pgrp > 0) if (tty->pgrp)
kill_pg(tty->pgrp, sig, 1); kill_pgrp(tty->pgrp, sig, 1);
if (flush || !L_NOFLSH(tty)) { if (flush || !L_NOFLSH(tty)) {
n_tty_flush_buffer(tty); n_tty_flush_buffer(tty);
if (tty->driver->flush_buffer) if (tty->driver->flush_buffer)
...@@ -1184,13 +1184,13 @@ static int job_control(struct tty_struct *tty, struct file *file) ...@@ -1184,13 +1184,13 @@ static int job_control(struct tty_struct *tty, struct file *file)
/* 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) { current->signal->tty == tty) {
if (tty->pgrp <= 0) if (!tty->pgrp)
printk("read_chan: tty->pgrp <= 0!\n"); printk("read_chan: no tty->pgrp!\n");
else if (process_group(current) != tty->pgrp) { else if (task_pgrp(current) != tty->pgrp) {
if (is_ignored(SIGTTIN) || if (is_ignored(SIGTTIN) ||
is_current_pgrp_orphaned()) is_current_pgrp_orphaned())
return -EIO; return -EIO;
kill_pg(process_group(current), SIGTTIN, 1); kill_pgrp(task_pgrp(current), SIGTTIN, 1);
return -ERESTARTSYS; return -ERESTARTSYS;
} }
} }
......
This diff is collapsed.
...@@ -866,8 +866,8 @@ int vc_resize(struct vc_data *vc, unsigned int cols, unsigned int lines) ...@@ -866,8 +866,8 @@ int vc_resize(struct vc_data *vc, unsigned int cols, unsigned int lines)
ws.ws_col = vc->vc_cols; ws.ws_col = vc->vc_cols;
ws.ws_ypixel = vc->vc_scan_lines; ws.ws_ypixel = vc->vc_scan_lines;
if ((ws.ws_row != cws->ws_row || ws.ws_col != cws->ws_col) && if ((ws.ws_row != cws->ws_row || ws.ws_col != cws->ws_col) &&
vc->vc_tty->pgrp > 0) vc->vc_tty->pgrp)
kill_pg(vc->vc_tty->pgrp, SIGWINCH, 1); kill_pgrp(vc->vc_tty->pgrp, SIGWINCH, 1);
*cws = ws; *cws = ws;
} }
......
...@@ -351,7 +351,7 @@ static int do_task_stat(struct task_struct *task, char * buffer, int whole) ...@@ -351,7 +351,7 @@ static int do_task_stat(struct task_struct *task, char * buffer, int whole)
struct signal_struct *sig = task->signal; struct signal_struct *sig = task->signal;
if (sig->tty) { if (sig->tty) {
tty_pgrp = sig->tty->pgrp; tty_pgrp = pid_nr(sig->tty->pgrp);
tty_nr = new_encode_dev(tty_devnum(sig->tty)); tty_nr = new_encode_dev(tty_devnum(sig->tty));
} }
......
...@@ -66,7 +66,7 @@ ...@@ -66,7 +66,7 @@
.cpu_timers = INIT_CPU_TIMERS(sig.cpu_timers), \ .cpu_timers = INIT_CPU_TIMERS(sig.cpu_timers), \
.rlim = INIT_RLIMITS, \ .rlim = INIT_RLIMITS, \
.pgrp = 1, \ .pgrp = 1, \
.tty_old_pgrp = 0, \ .tty_old_pgrp = NULL, \
{ .__session = 1}, \ { .__session = 1}, \
} }
......
...@@ -436,7 +436,7 @@ struct signal_struct { ...@@ -436,7 +436,7 @@ struct signal_struct {
/* job control IDs */ /* job control IDs */
pid_t pgrp; pid_t pgrp;
pid_t tty_old_pgrp; struct pid *tty_old_pgrp;
union { union {
pid_t session __deprecated; pid_t session __deprecated;
......
...@@ -197,8 +197,8 @@ struct tty_struct { ...@@ -197,8 +197,8 @@ struct tty_struct {
struct mutex termios_mutex; struct mutex termios_mutex;
struct ktermios *termios, *termios_locked; struct ktermios *termios, *termios_locked;
char name[64]; char name[64];
int pgrp; struct pid *pgrp;
int session; struct pid *session;
unsigned long flags; unsigned long flags;
int count; int count;
struct winsize winsize; struct winsize winsize;
......
...@@ -869,7 +869,7 @@ static inline int copy_signal(unsigned long clone_flags, struct task_struct * ts ...@@ -869,7 +869,7 @@ static inline int copy_signal(unsigned long clone_flags, struct task_struct * ts
sig->it_prof_incr = cputime_zero; sig->it_prof_incr = cputime_zero;
sig->leader = 0; /* session leadership doesn't inherit */ sig->leader = 0; /* session leadership doesn't inherit */
sig->tty_old_pgrp = 0; sig->tty_old_pgrp = NULL;
sig->utime = sig->stime = sig->cutime = sig->cstime = cputime_zero; sig->utime = sig->stime = sig->cutime = sig->cstime = cputime_zero;
sig->nvcsw = sig->nivcsw = sig->cnvcsw = sig->cnivcsw = 0; sig->nvcsw = sig->nivcsw = sig->cnvcsw = sig->cnivcsw = 0;
......
...@@ -1510,7 +1510,6 @@ asmlinkage long sys_setsid(void) ...@@ -1510,7 +1510,6 @@ asmlinkage long sys_setsid(void)
spin_lock(&group_leader->sighand->siglock); spin_lock(&group_leader->sighand->siglock);
group_leader->signal->tty = NULL; group_leader->signal->tty = NULL;
group_leader->signal->tty_old_pgrp = 0;
spin_unlock(&group_leader->sighand->siglock); spin_unlock(&group_leader->sighand->siglock);
err = process_group(group_leader); err = process_group(group_leader);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment