[PATCH 7/13] Set virtual pids for a newly cloned task

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



When new task is created it must have its virtual pids set.
When task belongs to init namespace the pids are equal to 
global ones so it is safe to get vpid from any task.

This is the place where we export pids to use space and there
will be a patch for these cases, but this case is specal and
thus goes separately.

Signed-off-by: Pavel Emelianov <xemul@xxxxxxxxxx>

---

diff --git a/kernel/fork.c b/kernel/fork.c
index d7207a1..3ab517c 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -1026,6 +1026,7 @@ static struct task_struct *copy_process(
 	delayacct_tsk_init(p);	/* Must remain after dup_task_struct() */
 	copy_flags(clone_flags, p);
 	p->pid = pid_nr(pid);
+	set_task_vpid(p, pid_vnr(pid));
 	INIT_LIST_HEAD(&p->children);
 	INIT_LIST_HEAD(&p->sibling);
 	p->vfork_done = NULL;
@@ -1101,8 +1102,11 @@ static struct task_struct *copy_process(
 #endif
 
 	p->tgid = p->pid;
-	if (clone_flags & CLONE_THREAD)
+	set_task_vtgid(p, task_pid_vnr(p));
+	if (clone_flags & CLONE_THREAD) {
 		p->tgid = current->tgid;
+		set_task_vtgid(p, task_pid_vnr(current));
+	}
 
 	if ((retval = security_task_alloc(p)))
 		goto bad_fork_cleanup_policy;
@@ -1251,6 +1255,8 @@ static struct task_struct *copy_process(
 			p->signal->tty = current->signal->tty;
 			p->signal->pgrp = task_pgrp_nr(current);
 			set_task_session(p, task_session_nr(current));
+			set_task_vpgrp(p, task_pgrp_vnr(current));
+			set_task_vsession(p, task_session_vnr(current));
 			attach_pid(p, PIDTYPE_PGID, task_pgrp(current));
 			attach_pid(p, PIDTYPE_SID, task_session(current));
 
@@ -1270,7 +1276,7 @@ static struct task_struct *copy_process(
 	 * TID.  It's too late to back out if this fails.
 	 */
 	if (clone_flags & CLONE_PARENT_SETTID)
-		put_user(p->pid, parent_tidptr);
+		put_user(task_pid_vnr(p), parent_tidptr);
 
 	proc_fork_connector(p);
 	return p;
@@ -1372,7 +1378,7 @@ long do_fork(unsigned long clone_flags,
 
 	if (!pid)
 		return -EAGAIN;
-	nr = pid->nr;
+	nr = pid_vnr(pid);
 	if (unlikely(current->ptrace)) {
 		trace = fork_traceflag (clone_flags);
 		if (trace)

_______________________________________________
Containers mailing list
Containers@xxxxxxxxxxxxxxxxxxxxxxxxxx
https://lists.linux-foundation.org/mailman/listinfo/containers

[Index of Archives]     [Cgroups]     [Netdev]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite Forum]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux