summaryrefslogtreecommitdiffstats
path: root/sys/kern/sysv_sem.c
diff options
context:
space:
mode:
authorjhb <jhb@FreeBSD.org>2006-06-29 13:58:36 +0000
committerjhb <jhb@FreeBSD.org>2006-06-29 13:58:36 +0000
commit7a3e2522862e0ec7cb27553c86bc45d54b9f9245 (patch)
treea1e23882108a8d7fbfbd95cdbd0231f96f11f926 /sys/kern/sysv_sem.c
parentb014c1948856279154af0edc061dc613b85b8c7f (diff)
downloadFreeBSD-src-7a3e2522862e0ec7cb27553c86bc45d54b9f9245.zip
FreeBSD-src-7a3e2522862e0ec7cb27553c86bc45d54b9f9245.tar.gz
Fix semctl(2) breakage from the previous commit. Previously __semctl() had
a local 'semid' variable which was the array index and used uap->semid as the original IPC id. During the kern_semctl() conversion those two variables were collapsed into a single 'semid' variable breaking the places that needed the original IPC ID. To fix, add a new 'semidx' variable to hold the array index and leave 'semid' unmolested as the IPC id. While I'm here, explicitly document that the (undocumented, at least in semctl(2)) SEM_STAT command curiously expects an array index in the 'semid' parameter rather than an IPC id. Submitted by: maxim
Diffstat (limited to 'sys/kern/sysv_sem.c')
-rw-r--r--sys/kern/sysv_sem.c19
1 files changed, 12 insertions, 7 deletions
diff --git a/sys/kern/sysv_sem.c b/sys/kern/sysv_sem.c
index a842d32..d2e4cd8 100644
--- a/sys/kern/sysv_sem.c
+++ b/sys/kern/sysv_sem.c
@@ -591,6 +591,7 @@ kern_semctl(struct thread *td, int semid, int semnum, int cmd, union semun *arg,
struct semid_kernel *semakptr;
struct mtx *sema_mtxp;
u_short usval, count;
+ int semidx;
DPRINTF(("call to semctl(%d, %d, %d, 0x%x)\n",
semid, semnum, cmd, arg));
@@ -601,6 +602,10 @@ kern_semctl(struct thread *td, int semid, int semnum, int cmd, union semun *arg,
switch(cmd) {
case SEM_STAT:
+ /*
+ * For this command we assume semid is an array index
+ * rather than an IPC id.
+ */
if (semid < 0 || semid >= seminfo.semmni)
return (EINVAL);
semakptr = &sema[semid];
@@ -632,12 +637,12 @@ kern_semctl(struct thread *td, int semid, int semnum, int cmd, union semun *arg,
return (error);
}
- semid = IPCID_TO_IX(semid);
- if (semid < 0 || semid >= seminfo.semmni)
+ semidx = IPCID_TO_IX(semid);
+ if (semidx < 0 || semidx >= seminfo.semmni)
return (EINVAL);
- semakptr = &sema[semid];
- sema_mtxp = &sema_mtx[semid];
+ semakptr = &sema[semidx];
+ sema_mtxp = &sema_mtx[semidx];
#ifdef MAC
mtx_lock(sema_mtxp);
error = mac_check_sysv_semctl(cred, semakptr, cmd);
@@ -674,7 +679,7 @@ kern_semctl(struct thread *td, int semid, int semnum, int cmd, union semun *arg,
mac_cleanup_sysv_sem(semakptr);
#endif
SEMUNDO_LOCK();
- semundo_clear(semid, -1);
+ semundo_clear(semidx, -1);
SEMUNDO_UNLOCK();
wakeup(semakptr);
break;
@@ -804,7 +809,7 @@ kern_semctl(struct thread *td, int semid, int semnum, int cmd, union semun *arg,
}
semakptr->u.sem_base[semnum].semval = arg->val;
SEMUNDO_LOCK();
- semundo_clear(semid, semnum);
+ semundo_clear(semidx, semnum);
SEMUNDO_UNLOCK();
wakeup(semakptr);
break;
@@ -847,7 +852,7 @@ raced:
semakptr->u.sem_base[i].semval = usval;
}
SEMUNDO_LOCK();
- semundo_clear(semid, -1);
+ semundo_clear(semidx, -1);
SEMUNDO_UNLOCK();
wakeup(semakptr);
break;
OpenPOWER on IntegriCloud