Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a6f5e063 authored by Sukadev Bhattiprolu's avatar Sukadev Bhattiprolu Committed by Linus Torvalds
Browse files

pid namespaces: move alloc_pid() to copy_process()



Move alloc_pid() into copy_process().  This will keep all pid and pid
namespace code together and simplify error handling when we support multiple
pid namespaces.

Signed-off-by: default avatarSukadev Bhattiprolu <sukadev@us.ibm.com>
Cc: Pavel Emelianov <xemul@openvz.org>
Cc: Eric W. Biederman <ebiederm@xmission.com>
Cc: Cedric Le Goater <clg@fr.ibm.com>
Cc: Dave Hansen <haveblue@us.ibm.com>
Cc: Serge Hallyn <serue@us.ibm.com>
Cc: Herbert Poetzel <herbert@13thfloor.at>
Cc: Kirill Korotaev <dev@sw.ru>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent b460cbc5
Loading
Loading
Loading
Loading
+13 −6
Original line number Original line Diff line number Diff line
@@ -1040,6 +1040,12 @@ static struct task_struct *copy_process(unsigned long clone_flags,
	if (p->binfmt && !try_module_get(p->binfmt->module))
	if (p->binfmt && !try_module_get(p->binfmt->module))
		goto bad_fork_cleanup_put_domain;
		goto bad_fork_cleanup_put_domain;


	if (pid != &init_struct_pid) {
		pid = alloc_pid();
		if (!pid)
			goto bad_fork_put_binfmt_module;
	}

	p->did_exec = 0;
	p->did_exec = 0;
	delayacct_tsk_init(p);	/* Must remain after dup_task_struct() */
	delayacct_tsk_init(p);	/* Must remain after dup_task_struct() */
	copy_flags(clone_flags, p);
	copy_flags(clone_flags, p);
@@ -1331,6 +1337,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
	cgroup_exit(p, cgroup_callbacks_done);
	cgroup_exit(p, cgroup_callbacks_done);
bad_fork_cleanup_delays_binfmt:
bad_fork_cleanup_delays_binfmt:
	delayacct_tsk_free(p);
	delayacct_tsk_free(p);
	if (pid != &init_struct_pid)
		free_pid(pid);
bad_fork_put_binfmt_module:
	if (p->binfmt)
	if (p->binfmt)
		module_put(p->binfmt->module);
		module_put(p->binfmt->module);
bad_fork_cleanup_put_domain:
bad_fork_cleanup_put_domain:
@@ -1395,19 +1404,16 @@ long do_fork(unsigned long clone_flags,
{
{
	struct task_struct *p;
	struct task_struct *p;
	int trace = 0;
	int trace = 0;
	struct pid *pid = alloc_pid();
	long nr;
	long nr;


	if (!pid)
		return -EAGAIN;
	nr = pid->nr;
	if (unlikely(current->ptrace)) {
	if (unlikely(current->ptrace)) {
		trace = fork_traceflag (clone_flags);
		trace = fork_traceflag (clone_flags);
		if (trace)
		if (trace)
			clone_flags |= CLONE_PTRACE;
			clone_flags |= CLONE_PTRACE;
	}
	}


	p = copy_process(clone_flags, stack_start, regs, stack_size, parent_tidptr, child_tidptr, pid);
	p = copy_process(clone_flags, stack_start, regs, stack_size,
			parent_tidptr, child_tidptr, NULL);
	/*
	/*
	 * Do this prior waking up the new thread - the thread pointer
	 * Do this prior waking up the new thread - the thread pointer
	 * might get invalid after that point, if the thread exits quickly.
	 * might get invalid after that point, if the thread exits quickly.
@@ -1415,6 +1421,8 @@ long do_fork(unsigned long clone_flags,
	if (!IS_ERR(p)) {
	if (!IS_ERR(p)) {
		struct completion vfork;
		struct completion vfork;


		nr = pid_nr(task_pid(p));

		if (clone_flags & CLONE_VFORK) {
		if (clone_flags & CLONE_VFORK) {
			p->vfork_done = &vfork;
			p->vfork_done = &vfork;
			init_completion(&vfork);
			init_completion(&vfork);
@@ -1448,7 +1456,6 @@ long do_fork(unsigned long clone_flags,
			}
			}
		}
		}
	} else {
	} else {
		free_pid(pid);
		nr = PTR_ERR(p);
		nr = PTR_ERR(p);
	}
	}
	return nr;
	return nr;