Skip to content

Commit 45a6862

Browse files
ebiedermtorvalds
authored andcommitted
pid: remove the child_reaper special case in init/main.c
This patchset is a cleanup and a preparation to unshare the pid namespace. These prerequisites prepare for Eric's patchset to give a file descriptor to a namespace and join an existing namespace. This patch: It turns out that the existing assignment in copy_process of the child_reaper can handle the initial assignment of child_reaper we just need to generalize the test in kernel/fork.c Signed-off-by: Eric W. Biederman <ebiederm@xmission.com> Signed-off-by: Daniel Lezcano <daniel.lezcano@free.fr> Cc: Oleg Nesterov <oleg@redhat.com> Cc: Alexey Dobriyan <adobriyan@gmail.com> Acked-by: Serge E. Hallyn <serge@hallyn.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent bfdc0b4 commit 45a6862

3 files changed

Lines changed: 12 additions & 10 deletions

File tree

‎include/linux/pid.h‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,17 @@ static inline struct pid_namespace *ns_of_pid(struct pid *pid)
140140
return ns;
141141
}
142142

143+
/*
144+
* is_child_reaper returns true if the pid is the init process
145+
* of the current namespace. As this one could be checked before
146+
* pid_ns->child_reaper is assigned in copy_process, we check
147+
* with the pid number.
148+
*/
149+
static inline bool is_child_reaper(struct pid *pid)
150+
{
151+
return pid->numbers[pid->level].nr == 1;
152+
}
153+
143154
/*
144155
* the helpers to get the pid's id seen from different namespaces
145156
*

‎init/main.c‎

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -787,15 +787,6 @@ static int __init kernel_init(void * unused)
787787
* init can run on any cpu.
788788
*/
789789
set_cpus_allowed_ptr(current, cpu_all_mask);
790-
/*
791-
* Tell the world that we're going to be the grim
792-
* reaper of innocent orphaned children.
793-
*
794-
* We don't want people to have to make incorrect
795-
* assumptions about where in the task array this
796-
* can be found.
797-
*/
798-
init_pid_ns.child_reaper = current;
799790

800791
cad_pid = task_pid(current);
801792

‎kernel/fork.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1296,7 +1296,7 @@ static struct task_struct *copy_process(unsigned long clone_flags,
12961296
tracehook_finish_clone(p, clone_flags, trace);
12971297

12981298
if (thread_group_leader(p)) {
1299-
if (clone_flags & CLONE_NEWPID)
1299+
if (is_child_reaper(pid))
13001300
p->nsproxy->pid_ns->child_reaper = p;
13011301

13021302
p->signal->leader_pid = pid;

0 commit comments

Comments
 (0)