aboutsummaryrefslogtreecommitdiffstats
path: root/ipc
diff options
context:
space:
mode:
authorPierre Peiffer <pierre.peiffer@bull.net>2008-02-08 07:18:56 -0500
committerLinus Torvalds <torvalds@woody.linux-foundation.org>2008-02-08 12:22:26 -0500
commit4b9fcb0ec60584d639ad105c42b75a3447071e47 (patch)
treeb68be0c60ca985901cd20c0b8a7321e8be07d328 /ipc
parentb2d75cddc83a349ef5633f609b9734b6b957f90f (diff)
IPC/semaphores: consolidate SEM_STAT and IPC_STAT commands
These commands (SEM_STAT and IPC_STAT) are rather doing the same things (only the meaning of the id given as input and the return value differ). However, for the semaphores, they are handled in two different places (two different functions). This patch consolidates this for clarification by handling these both commands in the same place in semctl_nolock(). It also removes one unused parameter for this function. Signed-off-by: Pierre Peiffer <pierre.peiffer@bull.net> Cc: Nadia Derbey <Nadia.Derbey@bull.net> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'ipc')
-rw-r--r--ipc/sem.c38
1 files changed, 16 insertions, 22 deletions
diff --git a/ipc/sem.c b/ipc/sem.c
index 84c701fe5004..7836edb0cf96 100644
--- a/ipc/sem.c
+++ b/ipc/sem.c
@@ -617,8 +617,8 @@ static unsigned long copy_semid_to_user(void __user *buf, struct semid64_ds *in,
617 } 617 }
618} 618}
619 619
620static int semctl_nolock(struct ipc_namespace *ns, int semid, int semnum, 620static int semctl_nolock(struct ipc_namespace *ns, int semid,
621 int cmd, int version, union semun arg) 621 int cmd, int version, union semun arg)
622{ 622{
623 int err = -EINVAL; 623 int err = -EINVAL;
624 struct sem_array *sma; 624 struct sem_array *sma;
@@ -657,14 +657,23 @@ static int semctl_nolock(struct ipc_namespace *ns, int semid, int semnum,
657 return -EFAULT; 657 return -EFAULT;
658 return (max_id < 0) ? 0: max_id; 658 return (max_id < 0) ? 0: max_id;
659 } 659 }
660 case IPC_STAT:
660 case SEM_STAT: 661 case SEM_STAT:
661 { 662 {
662 struct semid64_ds tbuf; 663 struct semid64_ds tbuf;
663 int id; 664 int id;
664 665
665 sma = sem_lock(ns, semid); 666 if (cmd == SEM_STAT) {
666 if (IS_ERR(sma)) 667 sma = sem_lock(ns, semid);
667 return PTR_ERR(sma); 668 if (IS_ERR(sma))
669 return PTR_ERR(sma);
670 id = sma->sem_perm.id;
671 } else {
672 sma = sem_lock_check(ns, semid);
673 if (IS_ERR(sma))
674 return PTR_ERR(sma);
675 id = 0;
676 }
668 677
669 err = -EACCES; 678 err = -EACCES;
670 if (ipcperms (&sma->sem_perm, S_IRUGO)) 679 if (ipcperms (&sma->sem_perm, S_IRUGO))
@@ -674,8 +683,6 @@ static int semctl_nolock(struct ipc_namespace *ns, int semid, int semnum,
674 if (err) 683 if (err)
675 goto out_unlock; 684 goto out_unlock;
676 685
677 id = sma->sem_perm.id;
678
679 memset(&tbuf, 0, sizeof(tbuf)); 686 memset(&tbuf, 0, sizeof(tbuf));
680 687
681 kernel_to_ipc64_perm(&sma->sem_perm, &tbuf.sem_perm); 688 kernel_to_ipc64_perm(&sma->sem_perm, &tbuf.sem_perm);
@@ -810,19 +817,6 @@ static int semctl_main(struct ipc_namespace *ns, int semid, int semnum,
810 err = 0; 817 err = 0;
811 goto out_unlock; 818 goto out_unlock;
812 } 819 }
813 case IPC_STAT:
814 {
815 struct semid64_ds tbuf;
816 memset(&tbuf,0,sizeof(tbuf));
817 kernel_to_ipc64_perm(&sma->sem_perm, &tbuf.sem_perm);
818 tbuf.sem_otime = sma->sem_otime;
819 tbuf.sem_ctime = sma->sem_ctime;
820 tbuf.sem_nsems = sma->sem_nsems;
821 sem_unlock(sma);
822 if (copy_semid_to_user (arg.buf, &tbuf, version))
823 return -EFAULT;
824 return 0;
825 }
826 /* GETVAL, GETPID, GETNCTN, GETZCNT, SETVAL: fall-through */ 820 /* GETVAL, GETPID, GETNCTN, GETZCNT, SETVAL: fall-through */
827 } 821 }
828 err = -EINVAL; 822 err = -EINVAL;
@@ -989,15 +983,15 @@ asmlinkage long sys_semctl (int semid, int semnum, int cmd, union semun arg)
989 switch(cmd) { 983 switch(cmd) {
990 case IPC_INFO: 984 case IPC_INFO:
991 case SEM_INFO: 985 case SEM_INFO:
986 case IPC_STAT:
992 case SEM_STAT: 987 case SEM_STAT:
993 err = semctl_nolock(ns,semid,semnum,cmd,version,arg); 988 err = semctl_nolock(ns, semid, cmd, version, arg);
994 return err; 989 return err;
995 case GETALL: 990 case GETALL:
996 case GETVAL: 991 case GETVAL:
997 case GETPID: 992 case GETPID:
998 case GETNCNT: 993 case GETNCNT:
999 case GETZCNT: 994 case GETZCNT:
1000 case IPC_STAT:
1001 case SETVAL: 995 case SETVAL:
1002 case SETALL: 996 case SETALL:
1003 err = semctl_main(ns,semid,semnum,cmd,version,arg); 997 err = semctl_main(ns,semid,semnum,cmd,version,arg);