Commit 937949d9 authored by Cedric Le Goater's avatar Cedric Le Goater Committed by Linus Torvalds

[PATCH] add process_session() helper routine

Replace occurences of task->signal->session by a new process_session() helper
routine.

It will be useful for pid namespaces to abstract the session pid number.
Signed-off-by: default avatarCedric Le Goater <clg@fr.ibm.com>
Cc: Kirill Korotaev <dev@openvz.org>
Cc: Eric W. Biederman <ebiederm@xmission.com>
Cc: Herbert Poetzl <herbert@13thfloor.at>
Cc: Sukadev Bhattiprolu <sukadev@us.ibm.com>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent ef55d53c
...@@ -1145,7 +1145,7 @@ static int irix_core_dump(long signr, struct pt_regs * regs, struct file *file) ...@@ -1145,7 +1145,7 @@ static int irix_core_dump(long signr, struct pt_regs * regs, struct file *file)
psinfo.pr_pid = prstatus.pr_pid = current->pid; psinfo.pr_pid = prstatus.pr_pid = current->pid;
psinfo.pr_ppid = prstatus.pr_ppid = current->parent->pid; psinfo.pr_ppid = prstatus.pr_ppid = current->parent->pid;
psinfo.pr_pgrp = prstatus.pr_pgrp = process_group(current); psinfo.pr_pgrp = prstatus.pr_pgrp = process_group(current);
psinfo.pr_sid = prstatus.pr_sid = current->signal->session; psinfo.pr_sid = prstatus.pr_sid = process_session(current);
if (current->pid == current->tgid) { if (current->pid == current->tgid) {
/* /*
* This is the record for the group leader. Add in the * This is the record for the group leader. Add in the
......
...@@ -994,7 +994,7 @@ static int mxser_open(struct tty_struct *tty, struct file *filp) ...@@ -994,7 +994,7 @@ static int mxser_open(struct tty_struct *tty, struct file *filp)
mxser_change_speed(info, NULL); mxser_change_speed(info, NULL);
} }
info->session = current->signal->session; info->session = process_session(current);
info->pgrp = process_group(current); info->pgrp = process_group(current);
/* /*
......
...@@ -1017,7 +1017,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp) ...@@ -1017,7 +1017,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
/* /*
* Info->count is now 1; so it's safe to sleep now. * Info->count is now 1; so it's safe to sleep now.
*/ */
info->session = current->signal->session; info->session = process_session(current);
info->pgrp = process_group(current); info->pgrp = process_group(current);
if ((info->flags & ROCKET_INITIALIZED) == 0) { if ((info->flags & ROCKET_INITIALIZED) == 0) {
......
...@@ -1511,7 +1511,7 @@ void disassociate_ctty(int on_exit) ...@@ -1511,7 +1511,7 @@ void disassociate_ctty(int on_exit)
spin_lock_irq(&current->sighand->siglock); spin_lock_irq(&current->sighand->siglock);
current->signal->tty_old_pgrp = 0; current->signal->tty_old_pgrp = 0;
session = current->signal->session; session = process_session(current);
spin_unlock_irq(&current->sighand->siglock); spin_unlock_irq(&current->sighand->siglock);
mutex_lock(&tty_mutex); mutex_lock(&tty_mutex);
...@@ -2897,7 +2897,7 @@ static int tiocsctty(struct tty_struct *tty, int arg) ...@@ -2897,7 +2897,7 @@ static int tiocsctty(struct tty_struct *tty, int arg)
{ {
int ret = 0; int ret = 0;
if (current->signal->leader && if (current->signal->leader &&
(current->signal->session == tty->session)) (process_session(current) == tty->session))
return ret; return ret;
mutex_lock(&tty_mutex); mutex_lock(&tty_mutex);
...@@ -2979,13 +2979,13 @@ static int tiocspgrp(struct tty_struct *tty, struct tty_struct *real_tty, pid_t ...@@ -2979,13 +2979,13 @@ static int tiocspgrp(struct tty_struct *tty, struct tty_struct *real_tty, pid_t
return retval; return retval;
if (!current->signal->tty || if (!current->signal->tty ||
(current->signal->tty != real_tty) || (current->signal->tty != real_tty) ||
(real_tty->session != current->signal->session)) (real_tty->session != process_session(current)))
return -ENOTTY; return -ENOTTY;
if (get_user(pgrp, p)) if (get_user(pgrp, p))
return -EFAULT; return -EFAULT;
if (pgrp < 0) if (pgrp < 0)
return -EINVAL; return -EINVAL;
if (session_of_pgrp(pgrp) != current->signal->session) if (session_of_pgrp(pgrp) != process_session(current))
return -EPERM; return -EPERM;
real_tty->pgrp = pgrp; real_tty->pgrp = pgrp;
return 0; return 0;
...@@ -3338,7 +3338,7 @@ static void __do_SAK(struct work_struct *work) ...@@ -3338,7 +3338,7 @@ static void __do_SAK(struct work_struct *work)
/* Kill the entire session */ /* Kill the entire session */
do_each_task_pid(session, PIDTYPE_SID, p) { do_each_task_pid(session, PIDTYPE_SID, p) {
printk(KERN_NOTICE "SAK: killed process %d" printk(KERN_NOTICE "SAK: killed process %d"
" (%s): p->signal->session==tty->session\n", " (%s): process_session(p)==tty->session\n",
p->pid, p->comm); p->pid, p->comm);
send_sig(SIGKILL, p, 1); send_sig(SIGKILL, p, 1);
} while_each_task_pid(session, PIDTYPE_SID, p); } while_each_task_pid(session, PIDTYPE_SID, p);
...@@ -3348,7 +3348,7 @@ static void __do_SAK(struct work_struct *work) ...@@ -3348,7 +3348,7 @@ static void __do_SAK(struct work_struct *work)
do_each_thread(g, p) { do_each_thread(g, p) {
if (p->signal->tty == tty) { if (p->signal->tty == tty) {
printk(KERN_NOTICE "SAK: killed process %d" printk(KERN_NOTICE "SAK: killed process %d"
" (%s): p->signal->session==tty->session\n", " (%s): process_session(p)==tty->session\n",
p->pid, p->comm); p->pid, p->comm);
send_sig(SIGKILL, p, 1); send_sig(SIGKILL, p, 1);
continue; continue;
......
...@@ -1317,7 +1317,7 @@ static void fill_prstatus(struct elf_prstatus *prstatus, ...@@ -1317,7 +1317,7 @@ static void fill_prstatus(struct elf_prstatus *prstatus,
prstatus->pr_pid = p->pid; prstatus->pr_pid = p->pid;
prstatus->pr_ppid = p->parent->pid; prstatus->pr_ppid = p->parent->pid;
prstatus->pr_pgrp = process_group(p); prstatus->pr_pgrp = process_group(p);
prstatus->pr_sid = p->signal->session; prstatus->pr_sid = process_session(p);
if (thread_group_leader(p)) { if (thread_group_leader(p)) {
/* /*
* This is the record for the group leader. Add in the * This is the record for the group leader. Add in the
...@@ -1363,7 +1363,7 @@ static int fill_psinfo(struct elf_prpsinfo *psinfo, struct task_struct *p, ...@@ -1363,7 +1363,7 @@ static int fill_psinfo(struct elf_prpsinfo *psinfo, struct task_struct *p,
psinfo->pr_pid = p->pid; psinfo->pr_pid = p->pid;
psinfo->pr_ppid = p->parent->pid; psinfo->pr_ppid = p->parent->pid;
psinfo->pr_pgrp = process_group(p); psinfo->pr_pgrp = process_group(p);
psinfo->pr_sid = p->signal->session; psinfo->pr_sid = process_session(p);
i = p->state ? ffz(~p->state) + 1 : 0; i = p->state ? ffz(~p->state) + 1 : 0;
psinfo->pr_state = i; psinfo->pr_state = i;
......
...@@ -1322,7 +1322,7 @@ static void fill_prstatus(struct elf_prstatus *prstatus, ...@@ -1322,7 +1322,7 @@ static void fill_prstatus(struct elf_prstatus *prstatus,
prstatus->pr_pid = p->pid; prstatus->pr_pid = p->pid;
prstatus->pr_ppid = p->parent->pid; prstatus->pr_ppid = p->parent->pid;
prstatus->pr_pgrp = process_group(p); prstatus->pr_pgrp = process_group(p);
prstatus->pr_sid = p->signal->session; prstatus->pr_sid = process_session(p);
if (thread_group_leader(p)) { if (thread_group_leader(p)) {
/* /*
* This is the record for the group leader. Add in the * This is the record for the group leader. Add in the
...@@ -1371,7 +1371,7 @@ static int fill_psinfo(struct elf_prpsinfo *psinfo, struct task_struct *p, ...@@ -1371,7 +1371,7 @@ static int fill_psinfo(struct elf_prpsinfo *psinfo, struct task_struct *p,
psinfo->pr_pid = p->pid; psinfo->pr_pid = p->pid;
psinfo->pr_ppid = p->parent->pid; psinfo->pr_ppid = p->parent->pid;
psinfo->pr_pgrp = process_group(p); psinfo->pr_pgrp = process_group(p);
psinfo->pr_sid = p->signal->session; psinfo->pr_sid = process_session(p);
i = p->state ? ffz(~p->state) + 1 : 0; i = p->state ? ffz(~p->state) + 1 : 0;
psinfo->pr_state = i; psinfo->pr_state = i;
......
...@@ -1047,6 +1047,11 @@ static inline pid_t process_group(struct task_struct *tsk) ...@@ -1047,6 +1047,11 @@ static inline pid_t process_group(struct task_struct *tsk)
return tsk->signal->pgrp; return tsk->signal->pgrp;
} }
static inline pid_t process_session(struct task_struct *tsk)
{
return tsk->signal->session;
}
static inline struct pid *task_pid(struct task_struct *task) static inline struct pid *task_pid(struct task_struct *task)
{ {
return task->pids[PIDTYPE_PID].pid; return task->pids[PIDTYPE_PID].pid;
......
...@@ -193,14 +193,14 @@ int session_of_pgrp(int pgrp) ...@@ -193,14 +193,14 @@ int session_of_pgrp(int pgrp)
read_lock(&tasklist_lock); read_lock(&tasklist_lock);
do_each_task_pid(pgrp, PIDTYPE_PGID, p) { do_each_task_pid(pgrp, PIDTYPE_PGID, p) {
if (p->signal->session > 0) { if (process_session(p) > 0) {
sid = p->signal->session; sid = process_session(p);
goto out; goto out;
} }
} while_each_task_pid(pgrp, PIDTYPE_PGID, p); } while_each_task_pid(pgrp, PIDTYPE_PGID, p);
p = find_task_by_pid(pgrp); p = find_task_by_pid(pgrp);
if (p) if (p)
sid = p->signal->session; sid = process_session(p);
out: out:
read_unlock(&tasklist_lock); read_unlock(&tasklist_lock);
...@@ -225,8 +225,8 @@ static int will_become_orphaned_pgrp(int pgrp, struct task_struct *ignored_task) ...@@ -225,8 +225,8 @@ static int will_become_orphaned_pgrp(int pgrp, struct task_struct *ignored_task)
|| p->exit_state || p->exit_state
|| is_init(p->real_parent)) || is_init(p->real_parent))
continue; continue;
if (process_group(p->real_parent) != pgrp if (process_group(p->real_parent) != pgrp &&
&& p->real_parent->signal->session == p->signal->session) { process_session(p->real_parent) == process_session(p)) {
ret = 0; ret = 0;
break; break;
} }
...@@ -302,7 +302,7 @@ void __set_special_pids(pid_t session, pid_t pgrp) ...@@ -302,7 +302,7 @@ void __set_special_pids(pid_t session, pid_t pgrp)
{ {
struct task_struct *curr = current->group_leader; struct task_struct *curr = current->group_leader;
if (curr->signal->session != session) { if (process_session(curr) != session) {
detach_pid(curr, PIDTYPE_SID); detach_pid(curr, PIDTYPE_SID);
curr->signal->session = session; curr->signal->session = session;
attach_pid(curr, PIDTYPE_SID, session); attach_pid(curr, PIDTYPE_SID, session);
...@@ -647,10 +647,11 @@ reparent_thread(struct task_struct *p, struct task_struct *father, int traced) ...@@ -647,10 +647,11 @@ reparent_thread(struct task_struct *p, struct task_struct *father, int traced)
* outside, so the child pgrp is now orphaned. * outside, so the child pgrp is now orphaned.
*/ */
if ((process_group(p) != process_group(father)) && if ((process_group(p) != process_group(father)) &&
(p->signal->session == father->signal->session)) { (process_session(p) == process_session(father))) {
int pgrp = process_group(p); int pgrp = process_group(p);
if (will_become_orphaned_pgrp(pgrp, NULL) && has_stopped_jobs(pgrp)) { if (will_become_orphaned_pgrp(pgrp, NULL) &&
has_stopped_jobs(pgrp)) {
__kill_pg_info(SIGHUP, SEND_SIG_PRIV, pgrp); __kill_pg_info(SIGHUP, SEND_SIG_PRIV, pgrp);
__kill_pg_info(SIGCONT, SEND_SIG_PRIV, pgrp); __kill_pg_info(SIGCONT, SEND_SIG_PRIV, pgrp);
} }
...@@ -784,7 +785,7 @@ static void exit_notify(struct task_struct *tsk) ...@@ -784,7 +785,7 @@ static void exit_notify(struct task_struct *tsk)
t = tsk->real_parent; t = tsk->real_parent;
if ((process_group(t) != process_group(tsk)) && if ((process_group(t) != process_group(tsk)) &&
(t->signal->session == tsk->signal->session) && (process_session(t) == process_session(tsk)) &&
will_become_orphaned_pgrp(process_group(tsk), tsk) && will_become_orphaned_pgrp(process_group(tsk), tsk) &&
has_stopped_jobs(process_group(tsk))) { has_stopped_jobs(process_group(tsk))) {
__kill_pg_info(SIGHUP, SEND_SIG_PRIV, process_group(tsk)); __kill_pg_info(SIGHUP, SEND_SIG_PRIV, process_group(tsk));
......
...@@ -1259,9 +1259,9 @@ static struct task_struct *copy_process(unsigned long clone_flags, ...@@ -1259,9 +1259,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
if (thread_group_leader(p)) { if (thread_group_leader(p)) {
p->signal->tty = current->signal->tty; p->signal->tty = current->signal->tty;
p->signal->pgrp = process_group(current); p->signal->pgrp = process_group(current);
p->signal->session = current->signal->session; p->signal->session = process_session(current);
attach_pid(p, PIDTYPE_PGID, process_group(p)); attach_pid(p, PIDTYPE_PGID, process_group(p));
attach_pid(p, PIDTYPE_SID, p->signal->session); attach_pid(p, PIDTYPE_SID, process_session(p));
list_add_tail_rcu(&p->tasks, &init_task.tasks); list_add_tail_rcu(&p->tasks, &init_task.tasks);
__get_cpu_var(process_counts)++; __get_cpu_var(process_counts)++;
......
...@@ -583,7 +583,7 @@ static int check_kill_permission(int sig, struct siginfo *info, ...@@ -583,7 +583,7 @@ static int check_kill_permission(int sig, struct siginfo *info,
error = -EPERM; error = -EPERM;
if ((info == SEND_SIG_NOINFO || (!is_si_special(info) && SI_FROMUSER(info))) if ((info == SEND_SIG_NOINFO || (!is_si_special(info) && SI_FROMUSER(info)))
&& ((sig != SIGCONT) || && ((sig != SIGCONT) ||
(current->signal->session != t->signal->session)) (process_session(current) != process_session(t)))
&& (current->euid ^ t->suid) && (current->euid ^ t->uid) && (current->euid ^ t->suid) && (current->euid ^ t->uid)
&& (current->uid ^ t->suid) && (current->uid ^ t->uid) && (current->uid ^ t->suid) && (current->uid ^ t->uid)
&& !capable(CAP_KILL)) && !capable(CAP_KILL))
......
...@@ -1381,7 +1381,7 @@ asmlinkage long sys_setpgid(pid_t pid, pid_t pgid) ...@@ -1381,7 +1381,7 @@ asmlinkage long sys_setpgid(pid_t pid, pid_t pgid)
if (p->real_parent == group_leader) { if (p->real_parent == group_leader) {
err = -EPERM; err = -EPERM;
if (p->signal->session != group_leader->signal->session) if (process_session(p) != process_session(group_leader))
goto out; goto out;
err = -EACCES; err = -EACCES;
if (p->did_exec) if (p->did_exec)
...@@ -1400,7 +1400,7 @@ asmlinkage long sys_setpgid(pid_t pid, pid_t pgid) ...@@ -1400,7 +1400,7 @@ asmlinkage long sys_setpgid(pid_t pid, pid_t pgid)
struct task_struct *p; struct task_struct *p;
do_each_task_pid(pgid, PIDTYPE_PGID, p) { do_each_task_pid(pgid, PIDTYPE_PGID, p) {
if (p->signal->session == group_leader->signal->session) if (process_session(p) == process_session(group_leader))
goto ok_pgid; goto ok_pgid;
} while_each_task_pid(pgid, PIDTYPE_PGID, p); } while_each_task_pid(pgid, PIDTYPE_PGID, p);
goto out; goto out;
...@@ -1459,7 +1459,7 @@ asmlinkage long sys_getpgrp(void) ...@@ -1459,7 +1459,7 @@ asmlinkage long sys_getpgrp(void)
asmlinkage long sys_getsid(pid_t pid) asmlinkage long sys_getsid(pid_t pid)
{ {
if (!pid) if (!pid)
return current->signal->session; return process_session(current);
else { else {
int retval; int retval;
struct task_struct *p; struct task_struct *p;
...@@ -1471,7 +1471,7 @@ asmlinkage long sys_getsid(pid_t pid) ...@@ -1471,7 +1471,7 @@ asmlinkage long sys_getsid(pid_t pid)
if (p) { if (p) {
retval = security_task_getsid(p); retval = security_task_getsid(p);
if (!retval) if (!retval)
retval = p->signal->session; retval = process_session(p);
} }
read_unlock(&tasklist_lock); read_unlock(&tasklist_lock);
return retval; return retval;
......
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