aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/fork.c
diff options
context:
space:
mode:
authorPavel Emelyanov <xemul@openvz.org>2007-10-19 02:40:07 -0400
committerLinus Torvalds <torvalds@woody.linux-foundation.org>2007-10-19 14:53:39 -0400
commit425fb2b4bf5dde24be4a82e9a2c344bb49ac92e4 (patch)
tree04cdf3042ee0f593b243c6402f2ce3cacac5cc2d /kernel/fork.c
parent198fe21b0a17fe9c68cb519ecc566534b04f122b (diff)
pid namespaces: move alloc_pid() lower in copy_process()
When we create new namespace we will need to allocate the struct pid, that will have one extra struct upid in array, comparing to the parent. Thus we need to know the new namespace (if any) in alloc_pid() to init this struct upid properly, so move the alloc_pid() call lower in copy_process(). Signed-off-by: Pavel Emelyanov <xemul@openvz.org> Cc: Oleg Nesterov <oleg@tv-sign.ru> Cc: Sukadev Bhattiprolu <sukadev@us.ibm.com> Cc: Paul Menage <menage@google.com> Cc: "Eric W. Biederman" <ebiederm@xmission.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'kernel/fork.c')
-rw-r--r--kernel/fork.c31
1 files changed, 16 insertions, 15 deletions
diff --git a/kernel/fork.c b/kernel/fork.c
index 984d259e172d..bab34192799b 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -1040,16 +1040,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
1040 if (p->binfmt && !try_module_get(p->binfmt->module)) 1040 if (p->binfmt && !try_module_get(p->binfmt->module))
1041 goto bad_fork_cleanup_put_domain; 1041 goto bad_fork_cleanup_put_domain;
1042 1042
1043 if (pid != &init_struct_pid) {
1044 pid = alloc_pid(task_active_pid_ns(p));
1045 if (!pid)
1046 goto bad_fork_put_binfmt_module;
1047 }
1048
1049 p->did_exec = 0; 1043 p->did_exec = 0;
1050 delayacct_tsk_init(p); /* Must remain after dup_task_struct() */ 1044 delayacct_tsk_init(p); /* Must remain after dup_task_struct() */
1051 copy_flags(clone_flags, p); 1045 copy_flags(clone_flags, p);
1052 p->pid = pid_nr(pid);
1053 retval = -EFAULT; 1046 retval = -EFAULT;
1054 if (clone_flags & CLONE_PARENT_SETTID) 1047 if (clone_flags & CLONE_PARENT_SETTID)
1055 if (put_user(p->pid, parent_tidptr)) 1048 if (put_user(p->pid, parent_tidptr))
@@ -1133,10 +1126,6 @@ static struct task_struct *copy_process(unsigned long clone_flags,
1133 p->blocked_on = NULL; /* not blocked yet */ 1126 p->blocked_on = NULL; /* not blocked yet */
1134#endif 1127#endif
1135 1128
1136 p->tgid = p->pid;
1137 if (clone_flags & CLONE_THREAD)
1138 p->tgid = current->tgid;
1139
1140 if ((retval = security_task_alloc(p))) 1129 if ((retval = security_task_alloc(p)))
1141 goto bad_fork_cleanup_policy; 1130 goto bad_fork_cleanup_policy;
1142 if ((retval = audit_alloc(p))) 1131 if ((retval = audit_alloc(p)))
@@ -1162,6 +1151,18 @@ static struct task_struct *copy_process(unsigned long clone_flags,
1162 if (retval) 1151 if (retval)
1163 goto bad_fork_cleanup_namespaces; 1152 goto bad_fork_cleanup_namespaces;
1164 1153
1154 if (pid != &init_struct_pid) {
1155 retval = -ENOMEM;
1156 pid = alloc_pid(task_active_pid_ns(p));
1157 if (!pid)
1158 goto bad_fork_cleanup_namespaces;
1159 }
1160
1161 p->pid = pid_nr(pid);
1162 p->tgid = p->pid;
1163 if (clone_flags & CLONE_THREAD)
1164 p->tgid = current->tgid;
1165
1165 p->set_child_tid = (clone_flags & CLONE_CHILD_SETTID) ? child_tidptr : NULL; 1166 p->set_child_tid = (clone_flags & CLONE_CHILD_SETTID) ? child_tidptr : NULL;
1166 /* 1167 /*
1167 * Clear TID on mm_release()? 1168 * Clear TID on mm_release()?
@@ -1259,7 +1260,7 @@ static struct task_struct *copy_process(unsigned long clone_flags,
1259 spin_unlock(&current->sighand->siglock); 1260 spin_unlock(&current->sighand->siglock);
1260 write_unlock_irq(&tasklist_lock); 1261 write_unlock_irq(&tasklist_lock);
1261 retval = -ERESTARTNOINTR; 1262 retval = -ERESTARTNOINTR;
1262 goto bad_fork_cleanup_namespaces; 1263 goto bad_fork_free_pid;
1263 } 1264 }
1264 1265
1265 if (clone_flags & CLONE_THREAD) { 1266 if (clone_flags & CLONE_THREAD) {
@@ -1308,6 +1309,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
1308 cgroup_post_fork(p); 1309 cgroup_post_fork(p);
1309 return p; 1310 return p;
1310 1311
1312bad_fork_free_pid:
1313 if (pid != &init_struct_pid)
1314 free_pid(pid);
1311bad_fork_cleanup_namespaces: 1315bad_fork_cleanup_namespaces:
1312 exit_task_namespaces(p); 1316 exit_task_namespaces(p);
1313bad_fork_cleanup_keys: 1317bad_fork_cleanup_keys:
@@ -1337,9 +1341,6 @@ bad_fork_cleanup_cgroup:
1337 cgroup_exit(p, cgroup_callbacks_done); 1341 cgroup_exit(p, cgroup_callbacks_done);
1338bad_fork_cleanup_delays_binfmt: 1342bad_fork_cleanup_delays_binfmt:
1339 delayacct_tsk_free(p); 1343 delayacct_tsk_free(p);
1340 if (pid != &init_struct_pid)
1341 free_pid(pid);
1342bad_fork_put_binfmt_module:
1343 if (p->binfmt) 1344 if (p->binfmt)
1344 module_put(p->binfmt->module); 1345 module_put(p->binfmt->module);
1345bad_fork_cleanup_put_domain: 1346bad_fork_cleanup_put_domain: