Skip to contentSkip to conversation

reduce reparent_to_init()

PATCH In review Oleg Nesterov 2 participants 2 messages Apr 10, 2007

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 reduce reparent_to_init()

Move some random stuff which doesn't need tasklist_lock from reparent_to_init() to its caller, daemonize(). Strictly speaking, rlim is protected by task_lock() but we don't need it to copy init_task->rlim.

kernel/exit.c renamed from kernel/exit.c~1_REDUCE +11 -10
@@ -271,7 +271,6 @@ static void reparent_to_init(void)
 	write_lock_irq(&tasklist_lock);
 
 	ptrace_unlink(current);
-	/* Reparent to init */
 	remove_parent(current);
 	current->parent = child_reaper(current);
 	current->real_parent = child_reaper(current);
@@ -280,17 +279,8 @@ static void reparent_to_init(void)
 	/* Set the exit signal to SIGCHLD so we signal init on exit */
 	current->exit_signal = SIGCHLD;
 
-	if (!has_rt_policy(current) && (task_nice(current) < 0))
-		set_user_nice(current, 0);
-	/* cpus_allowed? */
-	/* rt_priority? */
-	/* signals? */
 	security_task_reparent_to_init(current);
-	memcpy(current->signal->rlim, init_task.signal->rlim,
-	       sizeof(current->signal->rlim));
-	atomic_inc(&(INIT_USER->__count));
 	write_unlock_irq(&tasklist_lock);
-	switch_uid(INIT_USER);
 }
 
 void __set_special_pids(pid_t session, pid_t pgrp)
@@ -402,6 +392,17 @@ void daemonize(const char *name, ...)
 	atomic_inc(&current->files->count);
 
 	reparent_to_init();
+
+	if (!has_rt_policy(current) && (task_nice(current) < 0))
+		set_user_nice(current, 0);
+	/* cpus_allowed? */
+	/* rt_priority? */
+	/* signals? */
+	memcpy(current->signal->rlim, init_task.signal->rlim,
+	       sizeof(current->signal->rlim));
+
+	atomic_inc(&(INIT_USER->__count));
+	switch_uid(INIT_USER);
 }
 
 EXPORT_SYMBOL(daemonize);
Acked-by on v1 1/3
#1 lore raw
Quoted 3 lines · Oleg Nesterov

Move some random stuff which doesn't need tasklist_lock from reparent_to_init() to its caller, daemonize(). Strictly speaking, rlim is protected by task_lock() but we don't need it to copy init_task->rlim.

Regardless of whatever else we are doing getting junk out of a function whose goal is to reparent a kernel thread makes sense.

Eric