teach set_special_pids() to use struct pid
authorOleg Nesterov <oleg@tv-sign.ru>
Fri, 8 Feb 2008 12:19:09 +0000 (04:19 -0800)
committerLinus Torvalds <torvalds@woody.linux-foundation.org>
Fri, 8 Feb 2008 17:22:27 +0000 (09:22 -0800)
Change set_special_pids() to work with struct pid, not pid_t from global name
space. This again speedups and imho cleanups the code, also a preparation for
the next patch.

Signed-off-by: Oleg Nesterov <oleg@tv-sign.ru>
Acked-by: "Eric W. Biederman" <ebiederm@xmission.com>
Acked-by: Pavel Emelyanov <xemul@openvz.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
include/linux/sched.h
init/main.c
kernel/exit.c
kernel/sys.c

index 8a4812c1c038db0f1e5654531784ac5c801a25d2..d1c9b7f1d51ebe54690b8d85615bcc7444cd0196 100644 (file)
@@ -1632,7 +1632,7 @@ extern struct task_struct *find_task_by_vpid(pid_t nr);
 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
                struct pid_namespace *ns);
 
-extern void __set_special_pids(pid_t session, pid_t pgrp);
+extern void __set_special_pids(struct pid *pid);
 
 /* per-UID process charging. */
 extern struct user_struct * alloc_uid(struct user_namespace *, uid_t);
index 2a78932f6c075abd36b331db09191b785d3156bc..9a5b18c0a63d0f2ce8ad8ba8e2142ab37ca94689 100644 (file)
@@ -833,7 +833,7 @@ static int __init kernel_init(void * unused)
         */
        init_pid_ns.child_reaper = current;
 
-       __set_special_pids(1, 1);
+       __set_special_pids(task_pid(current));
        cad_pid = task_pid(current);
 
        smp_prepare_cpus(setup_max_cpus);
index 42a8713b20506665b3a52556724e1bb1ededeeea..96716fd22373936d4e87dd40d3fd3ad5d0c679e4 100644 (file)
@@ -293,26 +293,27 @@ static void reparent_to_kthreadd(void)
        switch_uid(INIT_USER);
 }
 
-void __set_special_pids(pid_t session, pid_t pgrp)
+void __set_special_pids(struct pid *pid)
 {
        struct task_struct *curr = current->group_leader;
+       pid_t nr = pid_nr(pid);
 
-       if (task_session_nr(curr) != session) {
+       if (task_session(curr) != pid) {
                detach_pid(curr, PIDTYPE_SID);
-               set_task_session(curr, session);
-               attach_pid(curr, PIDTYPE_SID, find_pid(session));
+               attach_pid(curr, PIDTYPE_SID, pid);
+               set_task_session(curr, nr);
        }
-       if (task_pgrp_nr(curr) != pgrp) {
+       if (task_pgrp(curr) != pid) {
                detach_pid(curr, PIDTYPE_PGID);
-               set_task_pgrp(curr, pgrp);
-               attach_pid(curr, PIDTYPE_PGID, find_pid(pgrp));
+               attach_pid(curr, PIDTYPE_PGID, pid);
+               set_task_pgrp(curr, nr);
        }
 }
 
-static void set_special_pids(pid_t session, pid_t pgrp)
+static void set_special_pids(struct pid *pid)
 {
        write_lock_irq(&tasklist_lock);
-       __set_special_pids(session, pgrp);
+       __set_special_pids(pid);
        write_unlock_irq(&tasklist_lock);
 }
 
@@ -383,7 +384,11 @@ void daemonize(const char *name, ...)
         */
        current->flags |= PF_NOFREEZE;
 
-       set_special_pids(1, 1);
+       if (current->nsproxy != &init_nsproxy) {
+               get_nsproxy(&init_nsproxy);
+               switch_task_namespaces(current, &init_nsproxy);
+       }
+       set_special_pids(find_pid(1));
        proc_clear_tty(current);
 
        /* Block and flush all signals */
@@ -398,11 +403,6 @@ void daemonize(const char *name, ...)
        current->fs = fs;
        atomic_inc(&fs->count);
 
-       if (current->nsproxy != init_task.nsproxy) {
-               get_nsproxy(init_task.nsproxy);
-               switch_task_namespaces(current, init_task.nsproxy);
-       }
-
        exit_files(current);
        current->files = init_task.files;
        atomic_inc(&current->files->count);
index e13bc518b444d0f6f31768701717a3a6c607ce75..c326d6dceee337e41e70d441ac07ff3dabe275c6 100644 (file)
@@ -1065,7 +1065,7 @@ asmlinkage long sys_setsid(void)
                goto out;
 
        group_leader->signal->leader = 1;
-       __set_special_pids(pid_nr(sid), pid_nr(sid));
+       __set_special_pids(sid);
 
        spin_lock(&group_leader->sighand->siglock);
        group_leader->signal->tty = NULL;