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
This commit is contained in:
John Baldwin 2006-06-29 13:58:36 +00:00
parent 4d09f5a030
commit fe95c76276

View File

@ -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 @@ kern_semctl(struct thread *td, int semid, int semnum, int cmd, union semun *arg,
semakptr->u.sem_base[i].semval = usval;
}
SEMUNDO_LOCK();
semundo_clear(semid, -1);
semundo_clear(semidx, -1);
SEMUNDO_UNLOCK();
wakeup(semakptr);
break;