Commit 4e021306 authored by Oleg Nesterov's avatar Oleg Nesterov Committed by Linus Torvalds

sys_setpgid(): simplify pid/ns interaction

sys_setpgid() does unneeded conversions from pid_t to "struct pid" and vice
versa.  Use "struct pid" more consistently.  Saves one find_vpid() and
eliminates the explicit usage of ->nsproxy->pid_ns.  Imho, cleanups the
code.

Also use the same_thread_group() helper.
Signed-off-by: default avatarOleg Nesterov <oleg@tv-sign.ru>
Acked-by: default avatarPavel Emelyanov <xemul@openvz.org>
Acked-by: default avatar"Eric W. Biederman" <ebiederm@xmission.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent c543f1ee
...@@ -916,8 +916,8 @@ asmlinkage long sys_setpgid(pid_t pid, pid_t pgid) ...@@ -916,8 +916,8 @@ asmlinkage long sys_setpgid(pid_t pid, pid_t pgid)
{ {
struct task_struct *p; struct task_struct *p;
struct task_struct *group_leader = current->group_leader; struct task_struct *group_leader = current->group_leader;
int err = -EINVAL; struct pid *pgrp;
struct pid_namespace *ns; int err;
if (!pid) if (!pid)
pid = task_pid_vnr(group_leader); pid = task_pid_vnr(group_leader);
...@@ -929,12 +929,10 @@ asmlinkage long sys_setpgid(pid_t pid, pid_t pgid) ...@@ -929,12 +929,10 @@ asmlinkage long sys_setpgid(pid_t pid, pid_t pgid)
/* From this point forward we keep holding onto the tasklist lock /* From this point forward we keep holding onto the tasklist lock
* so that our parent does not change from under us. -DaveM * so that our parent does not change from under us. -DaveM
*/ */
ns = current->nsproxy->pid_ns;
write_lock_irq(&tasklist_lock); write_lock_irq(&tasklist_lock);
err = -ESRCH; err = -ESRCH;
p = find_task_by_pid_ns(pid, ns); p = find_task_by_vpid(pid);
if (!p) if (!p)
goto out; goto out;
...@@ -942,7 +940,7 @@ asmlinkage long sys_setpgid(pid_t pid, pid_t pgid) ...@@ -942,7 +940,7 @@ asmlinkage long sys_setpgid(pid_t pid, pid_t pgid)
if (!thread_group_leader(p)) if (!thread_group_leader(p))
goto out; goto out;
if (p->real_parent->tgid == group_leader->tgid) { if (same_thread_group(p->real_parent, group_leader)) {
err = -EPERM; err = -EPERM;
if (task_session(p) != task_session(group_leader)) if (task_session(p) != task_session(group_leader))
goto out; goto out;
...@@ -959,10 +957,12 @@ asmlinkage long sys_setpgid(pid_t pid, pid_t pgid) ...@@ -959,10 +957,12 @@ asmlinkage long sys_setpgid(pid_t pid, pid_t pgid)
if (p->signal->leader) if (p->signal->leader)
goto out; goto out;
pgrp = task_pid(p);
if (pgid != pid) { if (pgid != pid) {
struct task_struct *g; struct task_struct *g;
g = find_task_by_pid_type_ns(PIDTYPE_PGID, pgid, ns); pgrp = find_vpid(pgid);
g = pid_task(pgrp, PIDTYPE_PGID);
if (!g || task_session(g) != task_session(group_leader)) if (!g || task_session(g) != task_session(group_leader))
goto out; goto out;
} }
...@@ -971,13 +971,10 @@ asmlinkage long sys_setpgid(pid_t pid, pid_t pgid) ...@@ -971,13 +971,10 @@ asmlinkage long sys_setpgid(pid_t pid, pid_t pgid)
if (err) if (err)
goto out; goto out;
if (task_pgrp_nr_ns(p, ns) != pgid) { if (task_pgrp(p) != pgrp) {
struct pid *pid;
detach_pid(p, PIDTYPE_PGID); detach_pid(p, PIDTYPE_PGID);
pid = find_vpid(pgid); attach_pid(p, PIDTYPE_PGID, pgrp);
attach_pid(p, PIDTYPE_PGID, pid); set_task_pgrp(p, pid_nr(pgrp));
set_task_pgrp(p, pid_nr(pid));
} }
err = 0; err = 0;
......
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