Commit 461a50a3 authored by Ingo Molnar's avatar Ingo Molnar

[PATCH] session handling using pid lists..

These are the debated tty_io.c changes to use the session group lists to
maintain controlling tty information.
parent 64cf8edb
...@@ -432,6 +432,7 @@ void do_tty_hangup(void *data) ...@@ -432,6 +432,7 @@ void do_tty_hangup(void *data)
struct file * cons_filp = NULL; struct file * cons_filp = NULL;
struct task_struct *p; struct task_struct *p;
struct list_head *l; struct list_head *l;
struct pid *pid;
int closecount = 0, n; int closecount = 0, n;
if (!tty) if (!tty)
...@@ -496,17 +497,17 @@ void do_tty_hangup(void *data) ...@@ -496,17 +497,17 @@ void do_tty_hangup(void *data)
} }
read_lock(&tasklist_lock); read_lock(&tasklist_lock);
for_each_process(p) { if (tty->session > 0)
if ((tty->session > 0) && (p->session == tty->session) && for_each_task_pid(tty->session, PIDTYPE_SID, p, l, pid) {
p->leader) { if (p->tty == tty)
send_sig(SIGHUP,p,1); p->tty = NULL;
send_sig(SIGCONT,p,1); if (!p->leader)
continue;
send_sig(SIGHUP, p, 1);
send_sig(SIGCONT, p, 1);
if (tty->pgrp > 0) if (tty->pgrp > 0)
p->tty_old_pgrp = tty->pgrp; p->tty_old_pgrp = tty->pgrp;
} }
if (p->tty == tty)
p->tty = NULL;
}
read_unlock(&tasklist_lock); read_unlock(&tasklist_lock);
tty->flags = 0; tty->flags = 0;
...@@ -571,6 +572,8 @@ void disassociate_ctty(int on_exit) ...@@ -571,6 +572,8 @@ void disassociate_ctty(int on_exit)
{ {
struct tty_struct *tty = current->tty; struct tty_struct *tty = current->tty;
struct task_struct *p; struct task_struct *p;
struct list_head *l;
struct pid *pid;
int tty_pgrp = -1; int tty_pgrp = -1;
lock_kernel(); lock_kernel();
...@@ -598,9 +601,8 @@ void disassociate_ctty(int on_exit) ...@@ -598,9 +601,8 @@ void disassociate_ctty(int on_exit)
tty->pgrp = -1; tty->pgrp = -1;
read_lock(&tasklist_lock); read_lock(&tasklist_lock);
for_each_process(p) for_each_task_pid(current->session, PIDTYPE_SID, p, l, pid)
if (p->session == current->session) p->tty = NULL;
p->tty = NULL;
read_unlock(&tasklist_lock); read_unlock(&tasklist_lock);
unlock_kernel(); unlock_kernel();
} }
...@@ -1221,12 +1223,15 @@ static void release_dev(struct file * filp) ...@@ -1221,12 +1223,15 @@ static void release_dev(struct file * filp)
*/ */
if (tty_closing || o_tty_closing) { if (tty_closing || o_tty_closing) {
struct task_struct *p; struct task_struct *p;
struct list_head *l;
struct pid *pid;
read_lock(&tasklist_lock); read_lock(&tasklist_lock);
for_each_process(p) { for_each_task_pid(tty->session, PIDTYPE_SID, p, l, pid)
if (p->tty == tty || (o_tty && p->tty == o_tty)) p->tty = NULL;
if (o_tty)
for_each_task_pid(o_tty->session, PIDTYPE_SID, p,l, pid)
p->tty = NULL; p->tty = NULL;
}
read_unlock(&tasklist_lock); read_unlock(&tasklist_lock);
if (redirect == tty || (o_tty && redirect == o_tty)) if (redirect == tty || (o_tty && redirect == o_tty))
...@@ -1540,6 +1545,10 @@ static int fionbio(struct file *file, int *arg) ...@@ -1540,6 +1545,10 @@ static int fionbio(struct file *file, int *arg)
static int tiocsctty(struct tty_struct *tty, int arg) static int tiocsctty(struct tty_struct *tty, int arg)
{ {
struct list_head *l;
struct pid *pid;
task_t *p;
if (current->leader && if (current->leader &&
(current->session == tty->session)) (current->session == tty->session))
return 0; return 0;
...@@ -1558,12 +1567,10 @@ static int tiocsctty(struct tty_struct *tty, int arg) ...@@ -1558,12 +1567,10 @@ static int tiocsctty(struct tty_struct *tty, int arg)
/* /*
* Steal it away * Steal it away
*/ */
struct task_struct *p;
read_lock(&tasklist_lock); read_lock(&tasklist_lock);
for_each_process(p) for_each_task_pid(tty->session, PIDTYPE_SID, p, l, pid)
if (p->tty == tty) p->tty = NULL;
p->tty = NULL;
read_unlock(&tasklist_lock); read_unlock(&tasklist_lock);
} else } else
return -EPERM; return -EPERM;
......
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