pid namespaces: round up the API
authorPavel Emelianov <xemul@openvz.org>
Fri, 19 Oct 2007 06:39:46 +0000 (23:39 -0700)
committerLinus Torvalds <torvalds@woody.linux-foundation.org>
Fri, 19 Oct 2007 18:53:37 +0000 (11:53 -0700)
The set of functions process_session, task_session, process_group and
task_pgrp is confusing, as the names can be mixed with each other when looking
at the code for a long time.

The proposals are to
* equip the functions that return the integer with _nr suffix to
  represent that fact,
* and to make all functions work with task (not process) by making
  the common prefix of the same name.

For monotony the routines signal_session() and set_signal_session() are
replaced with task_session_nr() and set_task_session(), especially since they
are only used with the explicit task->signal dereference.

Signed-off-by: Pavel Emelianov <xemul@openvz.org>
Acked-by: Serge E. Hallyn <serue@us.ibm.com>
Cc: Kirill Korotaev <dev@openvz.org>
Cc: "Eric W. Biederman" <ebiederm@xmission.com>
Cc: Cedric Le Goater <clg@fr.ibm.com>
Cc: Herbert Poetzl <herbert@13thfloor.at>
Cc: Sukadev Bhattiprolu <sukadev@us.ibm.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
19 files changed:
arch/mips/kernel/irixelf.c
arch/mips/kernel/irixsig.c
arch/mips/kernel/sysirix.c
arch/sparc64/solaris/misc.c
drivers/char/tty_io.c
fs/autofs/inode.c
fs/autofs/root.c
fs/autofs4/autofs_i.h
fs/autofs4/inode.c
fs/autofs4/root.c
fs/binfmt_elf.c
fs/binfmt_elf_fdpic.c
fs/coda/upcall.c
fs/proc/array.c
include/linux/sched.h
kernel/exit.c
kernel/fork.c
kernel/signal.c
kernel/sys.c

index b997af713eb393aa6d4322d8f1d3d326e5dd57e9..7852c7cdf29e7e5d575d049d5367a57ed4f21fe5 100644 (file)
@@ -1172,8 +1172,8 @@ static int irix_core_dump(long signr, struct pt_regs *regs, struct file *file, u
        prstatus.pr_sighold = current->blocked.sig[0];
        psinfo.pr_pid = prstatus.pr_pid = current->pid;
        psinfo.pr_ppid = prstatus.pr_ppid = current->parent->pid;
-       psinfo.pr_pgrp = prstatus.pr_pgrp = process_group(current);
-       psinfo.pr_sid = prstatus.pr_sid = process_session(current);
+       psinfo.pr_pgrp = prstatus.pr_pgrp = task_pgrp_nr(current);
+       psinfo.pr_sid = prstatus.pr_sid = task_session_nr(current);
        if (current->pid == current->tgid) {
                /*
                 * This is the record for the group leader.  Add in the
index 85c2e389edd6f1fea3f2c4465396ef73364604dd..a0a91056fda722472edd644e9fa73e379d697a3a 100644 (file)
@@ -609,7 +609,7 @@ repeat:
                p = list_entry(_p, struct task_struct, sibling);
                if ((type == IRIX_P_PID) && p->pid != pid)
                        continue;
-               if ((type == IRIX_P_PGID) && process_group(p) != pid)
+               if ((type == IRIX_P_PGID) && task_pgrp_nr(p) != pid)
                        continue;
                if ((p->exit_signal != SIGCHLD))
                        continue;
index ee7790d9debe2e249e0ebf3480aaebb885fa4fe8..4c477c7ff74a1388c21a85392ed19ac7033cbeec 100644 (file)
@@ -763,11 +763,11 @@ asmlinkage int irix_setpgrp(int flags)
        printk("[%s:%d] setpgrp(%d) ", current->comm, current->pid, flags);
 #endif
        if(!flags)
-               error = process_group(current);
+               error = task_pgrp_nr(current);
        else
                error = sys_setsid();
 #ifdef DEBUG_PROCGRPS
-       printk("returning %d\n", process_group(current));
+       printk("returning %d\n", task_pgrp_nr(current));
 #endif
 
        return error;
index 3b67de7455f15c45f53524cc03269e18fa987521..c86cb3091a8ea8f28201f9afc66b718f230a107a 100644 (file)
@@ -415,7 +415,7 @@ asmlinkage int solaris_procids(int cmd, s32 pid, s32 pgid)
        
        switch (cmd) {
        case 0: /* getpgrp */
-               return process_group(current);
+               return task_pgrp_nr(current);
        case 1: /* setpgrp */
                {
                        int (*sys_setpgid)(pid_t,pid_t) =
@@ -426,7 +426,7 @@ asmlinkage int solaris_procids(int cmd, s32 pid, s32 pgid)
                        ret = sys_setpgid(0, 0);
                        if (ret) return ret;
                        proc_clear_tty(current);
-                       return process_group(current);
+                       return task_pgrp_nr(current);
                }
        case 2: /* getsid */
                {
index 9c867cf6de6456293314eb1675e697c87a9f64d2..9820f86831eea14ce715ca62275b4e71819f69c0 100644 (file)
@@ -3528,7 +3528,7 @@ void __do_SAK(struct tty_struct *tty)
        /* Kill the entire session */
        do_each_pid_task(session, PIDTYPE_SID, p) {
                printk(KERN_NOTICE "SAK: killed process %d"
-                       " (%s): process_session(p)==tty->session\n",
+                       " (%s): task_session_nr(p)==tty->session\n",
                        p->pid, p->comm);
                send_sig(SIGKILL, p, 1);
        } while_each_pid_task(session, PIDTYPE_SID, p);
@@ -3538,7 +3538,7 @@ void __do_SAK(struct tty_struct *tty)
        do_each_thread(g, p) {
                if (p->signal->tty == tty) {
                        printk(KERN_NOTICE "SAK: killed process %d"
-                           " (%s): process_session(p)==tty->session\n",
+                           " (%s): task_session_nr(p)==tty->session\n",
                            p->pid, p->comm);
                        send_sig(SIGKILL, p, 1);
                        continue;
index e7204d71acc94660f4a50a3d2c10eb2a6a816e63..45f5992a0957173bc0c7e744028ef40e5743aa8e 100644 (file)
@@ -80,7 +80,7 @@ static int parse_options(char *options, int *pipefd, uid_t *uid, gid_t *gid,
 
        *uid = current->uid;
        *gid = current->gid;
-       *pgrp = process_group(current);
+       *pgrp = task_pgrp_nr(current);
 
        *minproto = *maxproto = AUTOFS_PROTO_VERSION;
 
index c1489533277ae87d1f1d5358d7248e35ef5d6eb5..592f64037ae2bf58ae16ebfdd33f2bed16081af2 100644 (file)
@@ -215,7 +215,7 @@ static struct dentry *autofs_root_lookup(struct inode *dir, struct dentry *dentr
        oz_mode = autofs_oz_mode(sbi);
        DPRINTK(("autofs_lookup: pid = %u, pgrp = %u, catatonic = %d, "
                                "oz_mode = %d\n", pid_nr(task_pid(current)),
-                               process_group(current), sbi->catatonic,
+                               task_pgrp_nr(current), sbi->catatonic,
                                oz_mode));
 
        /*
@@ -536,7 +536,7 @@ static int autofs_root_ioctl(struct inode *inode, struct file *filp,
        struct autofs_sb_info *sbi = autofs_sbi(inode->i_sb);
        void __user *argp = (void __user *)arg;
 
-       DPRINTK(("autofs_ioctl: cmd = 0x%08x, arg = 0x%08lx, sbi = %p, pgrp = %u\n",cmd,arg,sbi,process_group(current)));
+       DPRINTK(("autofs_ioctl: cmd = 0x%08x, arg = 0x%08lx, sbi = %p, pgrp = %u\n",cmd,arg,sbi,task_pgrp_nr(current)));
 
        if (_IOC_TYPE(cmd) != _IOC_TYPE(AUTOFS_IOC_FIRST) ||
             _IOC_NR(cmd) - _IOC_NR(AUTOFS_IOC_FIRST) >= AUTOFS_IOC_COUNT)
index d85f42fa92060003b7000f3e686a5070e3da908e..2d4ae40718d9ecdc35119a82a10d264ce5c178ea 100644 (file)
@@ -131,7 +131,7 @@ static inline struct autofs_info *autofs4_dentry_ino(struct dentry *dentry)
    filesystem without "magic".) */
 
 static inline int autofs4_oz_mode(struct autofs_sb_info *sbi) {
-       return sbi->catatonic || process_group(current) == sbi->oz_pgrp;
+       return sbi->catatonic || task_pgrp_nr(current) == sbi->oz_pgrp;
 }
 
 /* Does a dentry have some pending activity? */
index cd81f0836671d436f5a55049812b8d854e78233c..7f05d6ccdb130c8171a80af52c7266ebb14bc2f6 100644 (file)
@@ -226,7 +226,7 @@ static int parse_options(char *options, int *pipefd, uid_t *uid, gid_t *gid,
 
        *uid = current->uid;
        *gid = current->gid;
-       *pgrp = process_group(current);
+       *pgrp = task_pgrp_nr(current);
 
        *minproto = AUTOFS_MIN_PROTO_VERSION;
        *maxproto = AUTOFS_MAX_PROTO_VERSION;
@@ -323,7 +323,7 @@ int autofs4_fill_super(struct super_block *s, void *data, int silent)
        sbi->pipe = NULL;
        sbi->catatonic = 1;
        sbi->exp_timeout = 0;
-       sbi->oz_pgrp = process_group(current);
+       sbi->oz_pgrp = task_pgrp_nr(current);
        sbi->sb = s;
        sbi->version = 0;
        sbi->sub_version = 0;
index 45ff3d63b758bd09feea0162cc0a0cbeca0473ad..2bbcc8151dc343eae48914aa95748fef401238f7 100644 (file)
@@ -582,7 +582,7 @@ static struct dentry *autofs4_lookup(struct inode *dir, struct dentry *dentry, s
        oz_mode = autofs4_oz_mode(sbi);
 
        DPRINTK("pid = %u, pgrp = %u, catatonic = %d, oz_mode = %d",
-                current->pid, process_group(current), sbi->catatonic, oz_mode);
+                current->pid, task_pgrp_nr(current), sbi->catatonic, oz_mode);
 
        unhashed = autofs4_lookup_unhashed(sbi, dentry->d_parent, &dentry->d_name);
        if (!unhashed) {
@@ -976,7 +976,7 @@ static int autofs4_root_ioctl(struct inode *inode, struct file *filp,
        void __user *p = (void __user *)arg;
 
        DPRINTK("cmd = 0x%08x, arg = 0x%08lx, sbi = %p, pgrp = %u",
-               cmd,arg,sbi,process_group(current));
+               cmd,arg,sbi,task_pgrp_nr(current));
 
        if (_IOC_TYPE(cmd) != _IOC_TYPE(AUTOFS_IOC_FIRST) ||
             _IOC_NR(cmd) - _IOC_NR(AUTOFS_IOC_FIRST) >= AUTOFS_IOC_COUNT)
index 6e2f3b8dde7f2c9dd636101b86b6049580d8143d..9ea2b99dc31ac81af8cdc8c385edb9ee60f18f19 100644 (file)
@@ -1385,8 +1385,8 @@ static void fill_prstatus(struct elf_prstatus *prstatus,
        prstatus->pr_sighold = p->blocked.sig[0];
        prstatus->pr_pid = p->pid;
        prstatus->pr_ppid = p->parent->pid;
-       prstatus->pr_pgrp = process_group(p);
-       prstatus->pr_sid = process_session(p);
+       prstatus->pr_pgrp = task_pgrp_nr(p);
+       prstatus->pr_sid = task_session_nr(p);
        if (thread_group_leader(p)) {
                /*
                 * This is the record for the group leader.  Add in the
@@ -1431,8 +1431,8 @@ static int fill_psinfo(struct elf_prpsinfo *psinfo, struct task_struct *p,
 
        psinfo->pr_pid = p->pid;
        psinfo->pr_ppid = p->parent->pid;
-       psinfo->pr_pgrp = process_group(p);
-       psinfo->pr_sid = process_session(p);
+       psinfo->pr_pgrp = task_pgrp_nr(p);
+       psinfo->pr_sid = task_session_nr(p);
 
        i = p->state ? ffz(~p->state) + 1 : 0;
        psinfo->pr_state = i;
index 033861c6b8f13028905826bcd6424bd3121f8eb2..b8b4e93f6f627079809d5ff8a2a443cc304042df 100644 (file)
@@ -1344,8 +1344,8 @@ static void fill_prstatus(struct elf_prstatus *prstatus,
        prstatus->pr_sighold = p->blocked.sig[0];
        prstatus->pr_pid = p->pid;
        prstatus->pr_ppid = p->parent->pid;
-       prstatus->pr_pgrp = process_group(p);
-       prstatus->pr_sid = process_session(p);
+       prstatus->pr_pgrp = task_pgrp_nr(p);
+       prstatus->pr_sid = task_session_nr(p);
        if (thread_group_leader(p)) {
                /*
                 * This is the record for the group leader.  Add in the
@@ -1393,8 +1393,8 @@ static int fill_psinfo(struct elf_prpsinfo *psinfo, struct task_struct *p,
 
        psinfo->pr_pid = p->pid;
        psinfo->pr_ppid = p->parent->pid;
-       psinfo->pr_pgrp = process_group(p);
-       psinfo->pr_sid = process_session(p);
+       psinfo->pr_pgrp = task_pgrp_nr(p);
+       psinfo->pr_sid = task_session_nr(p);
 
        i = p->state ? ffz(~p->state) + 1 : 0;
        psinfo->pr_state = i;
index cdb4c07a78700a93e34739a4aadddda96bfce8cc..359e531094ddddb74a88de2dbb74e11dde27d528 100644 (file)
@@ -51,7 +51,7 @@ static void *alloc_upcall(int opcode, int size)
 
         inp->ih.opcode = opcode;
        inp->ih.pid = current->pid;
-       inp->ih.pgid = process_group(current);
+       inp->ih.pgid = task_pgrp_nr(current);
 #ifdef CONFIG_CODA_FS_OLD_API
        memset(&inp->ih.cred, 0, sizeof(struct coda_cred));
        inp->ih.cred.cr_fsuid = current->fsuid;
index 27b59f5f3bd1f382ab16401671b5316dd867841d..24f7f9f6684d95201e69b70aab0749a6e1e640c9 100644 (file)
@@ -449,8 +449,8 @@ static int do_task_stat(struct task_struct *task, char *buffer, int whole)
                        gtime += cputime_add(gtime, sig->gtime);
                }
 
-               sid = signal_session(sig);
-               pgid = process_group(task);
+               sid = task_session_nr(task);
+               pgid = task_pgrp_nr(task);
                ppid = rcu_dereference(task->real_parent)->tgid;
 
                unlock_task_sighand(task, &flags);
index 93a55f2e5ef6d59c8a29c8c16157ec763c42df7c..df6049e5e8bfeef147e68aa212824904813ff007 100644 (file)
@@ -1188,24 +1188,19 @@ static inline int rt_task(struct task_struct *p)
        return rt_prio(p->prio);
 }
 
-static inline pid_t process_group(struct task_struct *tsk)
+static inline pid_t task_pgrp_nr(struct task_struct *tsk)
 {
        return tsk->signal->pgrp;
 }
 
-static inline pid_t signal_session(struct signal_struct *sig)
+static inline pid_t task_session_nr(struct task_struct *tsk)
 {
-       return sig->__session;
+       return tsk->signal->__session;
 }
 
-static inline pid_t process_session(struct task_struct *tsk)
+static inline void set_task_session(struct task_struct *tsk, pid_t session)
 {
-       return signal_session(tsk->signal);
-}
-
-static inline void set_signal_session(struct signal_struct *sig, pid_t session)
-{
-       sig->__session = session;
+       tsk->signal->__session = session;
 }
 
 static inline struct pid *task_pid(struct task_struct *task)
index cf03a52c3a9ad67a5978e770093e09ea65429622..6e6ec300330f5c09e48177897793bb74e8b096ab 100644 (file)
@@ -299,12 +299,12 @@ void __set_special_pids(pid_t session, pid_t pgrp)
 {
        struct task_struct *curr = current->group_leader;
 
-       if (process_session(curr) != session) {
+       if (task_session_nr(curr) != session) {
                detach_pid(curr, PIDTYPE_SID);
-               set_signal_session(curr->signal, session);
+               set_task_session(curr, session);
                attach_pid(curr, PIDTYPE_SID, find_pid(session));
        }
-       if (process_group(curr) != pgrp) {
+       if (task_pgrp_nr(curr) != pgrp) {
                detach_pid(curr, PIDTYPE_PGID);
                curr->signal->pgrp = pgrp;
                attach_pid(curr, PIDTYPE_PGID, find_pid(pgrp));
@@ -1091,10 +1091,10 @@ static int eligible_child(pid_t pid, int options, struct task_struct *p)
                if (p->pid != pid)
                        return 0;
        } else if (!pid) {
-               if (process_group(p) != process_group(current))
+               if (task_pgrp_nr(p) != task_pgrp_nr(current))
                        return 0;
        } else if (pid != -1) {
-               if (process_group(p) != -pid)
+               if (task_pgrp_nr(p) != -pid)
                        return 0;
        }
 
index 61516b89cb6c4cf6e026e209abcee59f8fd3c82d..fd65bca38a93df2c95444e822108d451cd544abb 100644 (file)
@@ -1283,8 +1283,8 @@ static struct task_struct *copy_process(unsigned long clone_flags,
 
                if (thread_group_leader(p)) {
                        p->signal->tty = current->signal->tty;
-                       p->signal->pgrp = process_group(current);
-                       set_signal_session(p->signal, process_session(current));
+                       p->signal->pgrp = task_pgrp_nr(current);
+                       set_task_session(p, task_session_nr(current));
                        attach_pid(p, PIDTYPE_PGID, task_pgrp(current));
                        attach_pid(p, PIDTYPE_SID, task_session(current));
 
index e4f059cd9867df74d44949cf7d16be947ee7c9e8..15c6940ab046129e9b96c3e336cdd1165b936a69 100644 (file)
@@ -536,7 +536,7 @@ static int check_kill_permission(int sig, struct siginfo *info,
                        return error;
                error = -EPERM;
                if (((sig != SIGCONT) ||
-                       (process_session(current) != process_session(t)))
+                       (task_session_nr(current) != task_session_nr(t)))
                    && (current->euid ^ t->suid) && (current->euid ^ t->uid)
                    && (current->uid ^ t->suid) && (current->uid ^ t->uid)
                    && !capable(CAP_KILL))
index b8fcbc64019331fbfd818a5983f0d2e312dac49e..4cfa213a5ac2ace2ed7837e748207e04aea06227 100644 (file)
@@ -968,7 +968,7 @@ asmlinkage long sys_setpgid(pid_t pid, pid_t pgid)
        if (err)
                goto out;
 
-       if (process_group(p) != pgid) {
+       if (task_pgrp_nr(p) != pgid) {
                detach_pid(p, PIDTYPE_PGID);
                p->signal->pgrp = pgid;
                attach_pid(p, PIDTYPE_PGID, find_pid(pgid));
@@ -984,7 +984,7 @@ out:
 asmlinkage long sys_getpgid(pid_t pid)
 {
        if (!pid)
-               return process_group(current);
+               return task_pgrp_nr(current);
        else {
                int retval;
                struct task_struct *p;
@@ -996,7 +996,7 @@ asmlinkage long sys_getpgid(pid_t pid)
                if (p) {
                        retval = security_task_getpgid(p);
                        if (!retval)
-                               retval = process_group(p);
+                               retval = task_pgrp_nr(p);
                }
                read_unlock(&tasklist_lock);
                return retval;
@@ -1008,7 +1008,7 @@ asmlinkage long sys_getpgid(pid_t pid)
 asmlinkage long sys_getpgrp(void)
 {
        /* SMP - assuming writes are word atomic this is fine */
-       return process_group(current);
+       return task_pgrp_nr(current);
 }
 
 #endif
@@ -1016,7 +1016,7 @@ asmlinkage long sys_getpgrp(void)
 asmlinkage long sys_getsid(pid_t pid)
 {
        if (!pid)
-               return process_session(current);
+               return task_session_nr(current);
        else {
                int retval;
                struct task_struct *p;
@@ -1028,7 +1028,7 @@ asmlinkage long sys_getsid(pid_t pid)
                if (p) {
                        retval = security_task_getsid(p);
                        if (!retval)
-                               retval = process_session(p);
+                               retval = task_session_nr(p);
                }
                read_unlock(&tasklist_lock);
                return retval;
@@ -1065,7 +1065,7 @@ asmlinkage long sys_setsid(void)
        group_leader->signal->tty = NULL;
        spin_unlock(&group_leader->sighand->siglock);
 
-       err = process_group(group_leader);
+       err = task_pgrp_nr(group_leader);
 out:
        write_unlock_irq(&tasklist_lock);
        return err;