Define a debug printf macro rather than wrapping all calls to printf
with #ifdefs.
This commit is contained in:
Alfred Perlstein 2002-07-22 18:27:54 +00:00
parent 4a78ccd771
commit fd6d9be4f5
2 changed files with 134 additions and 285 deletions

View file

@ -41,8 +41,11 @@ static void msginit(void);
static int msgunload(void);
static int sysvmsg_modload(struct module *, int, void *);
#define MSG_DEBUG
#undef MSG_DEBUG_OK
#ifdef MSG_DEBUG
#define DPRINTF(a) printf a
#else
#define DPRINTF(a)
#endif
static void msg_freehdr(struct msg *msghdr);
@ -160,13 +163,13 @@ msginit()
while (i < 1024 && i != msginfo.msgssz)
i <<= 1;
if (i != msginfo.msgssz) {
printf("msginfo.msgssz=%d (0x%x)\n", msginfo.msgssz,
msginfo.msgssz);
DPRINTF(("msginfo.msgssz=%d (0x%x)\n", msginfo.msgssz,
msginfo.msgssz));
panic("msginfo.msgssz not a small power of 2");
}
if (msginfo.msgseg > 32767) {
printf("msginfo.msgseg=%d\n", msginfo.msgseg);
DPRINTF(("msginfo.msgseg=%d\n", msginfo.msgseg));
panic("msginfo.msgseg > 32767");
}
@ -345,9 +348,7 @@ msgctl(td, uap)
struct msqid_ds msqbuf;
register struct msqid_ds *msqptr;
#ifdef MSG_DEBUG_OK
printf("call to msgctl(%d, %d, 0x%x)\n", msqid, cmd, user_msqptr);
#endif
DPRINTF(("call to msgctl(%d, %d, 0x%x)\n", msqid, cmd, user_msqptr));
if (!jail_sysvipc_allowed && jailed(td->td_ucred))
return (ENOSYS);
@ -355,10 +356,8 @@ msgctl(td, uap)
msqid = IPCID_TO_IX(msqid);
if (msqid < 0 || msqid >= msginfo.msgmni) {
#ifdef MSG_DEBUG_OK
printf("msqid (%d) out of range (0<=msqid<%d)\n", msqid,
msginfo.msgmni);
#endif
DPRINTF(("msqid (%d) out of range (0<=msqid<%d)\n", msqid,
msginfo.msgmni));
error = EINVAL;
goto done2;
}
@ -366,16 +365,12 @@ msgctl(td, uap)
msqptr = &msqids[msqid];
if (msqptr->msg_qbytes == 0) {
#ifdef MSG_DEBUG_OK
printf("no such msqid\n");
#endif
DPRINTF(("no such msqid\n"));
error = EINVAL;
goto done2;
}
if (msqptr->msg_perm.seq != IPCID_TO_SEQ(uap->msqid)) {
#ifdef MSG_DEBUG_OK
printf("wrong sequence number\n");
#endif
DPRINTF(("wrong sequence number\n"));
error = EINVAL;
goto done2;
}
@ -426,16 +421,12 @@ msgctl(td, uap)
goto done2;
}
if (msqbuf.msg_qbytes > msginfo.msgmnb) {
#ifdef MSG_DEBUG_OK
printf("can't increase msg_qbytes beyond %d (truncating)\n",
msginfo.msgmnb);
#endif
DPRINTF(("can't increase msg_qbytes beyond %d"
"(truncating)\n", msginfo.msgmnb));
msqbuf.msg_qbytes = msginfo.msgmnb; /* silently restrict qbytes to system limit */
}
if (msqbuf.msg_qbytes == 0) {
#ifdef MSG_DEBUG_OK
printf("can't reduce msg_qbytes to 0\n");
#endif
DPRINTF(("can't reduce msg_qbytes to 0\n"));
error = EINVAL; /* non-standard errno! */
goto done2;
}
@ -449,18 +440,14 @@ msgctl(td, uap)
case IPC_STAT:
if ((error = ipcperm(td, &msqptr->msg_perm, IPC_R))) {
#ifdef MSG_DEBUG_OK
printf("requester doesn't have read access\n");
#endif
DPRINTF(("requester doesn't have read access\n"));
goto done2;
}
error = copyout(msqptr, user_msqptr, sizeof(struct msqid_ds));
break;
default:
#ifdef MSG_DEBUG_OK
printf("invalid command %d\n", cmd);
#endif
DPRINTF(("invalid command %d\n", cmd));
error = EINVAL;
goto done2;
}
@ -493,9 +480,7 @@ msgget(td, uap)
struct ucred *cred = td->td_ucred;
register struct msqid_ds *msqptr = NULL;
#ifdef MSG_DEBUG_OK
printf("msgget(0x%x, 0%o)\n", key, msgflg);
#endif
DPRINTF(("msgget(0x%x, 0%o)\n", key, msgflg));
if (!jail_sysvipc_allowed && jailed(td->td_ucred))
return (ENOSYS);
@ -509,30 +494,22 @@ msgget(td, uap)
break;
}
if (msqid < msginfo.msgmni) {
#ifdef MSG_DEBUG_OK
printf("found public key\n");
#endif
DPRINTF(("found public key\n"));
if ((msgflg & IPC_CREAT) && (msgflg & IPC_EXCL)) {
#ifdef MSG_DEBUG_OK
printf("not exclusive\n");
#endif
DPRINTF(("not exclusive\n"));
error = EEXIST;
goto done2;
}
if ((error = ipcperm(td, &msqptr->msg_perm, msgflg & 0700 ))) {
#ifdef MSG_DEBUG_OK
printf("requester doesn't have 0%o access\n",
msgflg & 0700);
#endif
DPRINTF(("requester doesn't have 0%o access\n",
msgflg & 0700));
goto done2;
}
goto found;
}
}
#ifdef MSG_DEBUG_OK
printf("need to allocate the msqid_ds\n");
#endif
DPRINTF(("need to allocate the msqid_ds\n"));
if (key == IPC_PRIVATE || (msgflg & IPC_CREAT)) {
for (msqid = 0; msqid < msginfo.msgmni; msqid++) {
/*
@ -547,15 +524,11 @@ msgget(td, uap)
break;
}
if (msqid == msginfo.msgmni) {
#ifdef MSG_DEBUG_OK
printf("no more msqid_ds's available\n");
#endif
DPRINTF(("no more msqid_ds's available\n"));
error = ENOSPC;
goto done2;
}
#ifdef MSG_DEBUG_OK
printf("msqid %d is available\n", msqid);
#endif
DPRINTF(("msqid %d is available\n", msqid));
msqptr->msg_perm.key = key;
msqptr->msg_perm.cuid = cred->cr_uid;
msqptr->msg_perm.uid = cred->cr_uid;
@ -575,9 +548,7 @@ msgget(td, uap)
msqptr->msg_rtime = 0;
msqptr->msg_ctime = time_second;
} else {
#ifdef MSG_DEBUG_OK
printf("didn't find it and wasn't asked to create it\n");
#endif
DPRINTF(("didn't find it and wasn't asked to create it\n"));
error = ENOENT;
goto done2;
}
@ -616,10 +587,8 @@ msgsnd(td, uap)
register struct msg *msghdr;
short next;
#ifdef MSG_DEBUG_OK
printf("call to msgsnd(%d, 0x%x, %d, %d)\n", msqid, user_msgp, msgsz,
msgflg);
#endif
DPRINTF(("call to msgsnd(%d, 0x%x, %d, %d)\n", msqid, user_msgp, msgsz,
msgflg));
if (!jail_sysvipc_allowed && jailed(td->td_ucred))
return (ENOSYS);
@ -627,42 +596,32 @@ msgsnd(td, uap)
msqid = IPCID_TO_IX(msqid);
if (msqid < 0 || msqid >= msginfo.msgmni) {
#ifdef MSG_DEBUG_OK
printf("msqid (%d) out of range (0<=msqid<%d)\n", msqid,
msginfo.msgmni);
#endif
DPRINTF(("msqid (%d) out of range (0<=msqid<%d)\n", msqid,
msginfo.msgmni));
error = EINVAL;
goto done2;
}
msqptr = &msqids[msqid];
if (msqptr->msg_qbytes == 0) {
#ifdef MSG_DEBUG_OK
printf("no such message queue id\n");
#endif
DPRINTF(("no such message queue id\n"));
error = EINVAL;
goto done2;
}
if (msqptr->msg_perm.seq != IPCID_TO_SEQ(uap->msqid)) {
#ifdef MSG_DEBUG_OK
printf("wrong sequence number\n");
#endif
DPRINTF(("wrong sequence number\n"));
error = EINVAL;
goto done2;
}
if ((error = ipcperm(td, &msqptr->msg_perm, IPC_W))) {
#ifdef MSG_DEBUG_OK
printf("requester doesn't have write access\n");
#endif
DPRINTF(("requester doesn't have write access\n"));
goto done2;
}
segs_needed = (msgsz + msginfo.msgssz - 1) / msginfo.msgssz;
#ifdef MSG_DEBUG_OK
printf("msgsz=%d, msgssz=%d, segs_needed=%d\n", msgsz, msginfo.msgssz,
segs_needed);
#endif
DPRINTF(("msgsz=%d, msgssz=%d, segs_needed=%d\n", msgsz, msginfo.msgssz,
segs_needed));
for (;;) {
int need_more_resources = 0;
@ -672,35 +631,25 @@ msgsnd(td, uap)
*/
if (msgsz > msqptr->msg_qbytes) {
#ifdef MSG_DEBUG_OK
printf("msgsz > msqptr->msg_qbytes\n");
#endif
DPRINTF(("msgsz > msqptr->msg_qbytes\n"));
error = EINVAL;
goto done2;
}
if (msqptr->msg_perm.mode & MSG_LOCKED) {
#ifdef MSG_DEBUG_OK
printf("msqid is locked\n");
#endif
DPRINTF(("msqid is locked\n"));
need_more_resources = 1;
}
if (msgsz + msqptr->msg_cbytes > msqptr->msg_qbytes) {
#ifdef MSG_DEBUG_OK
printf("msgsz + msg_cbytes > msg_qbytes\n");
#endif
DPRINTF(("msgsz + msg_cbytes > msg_qbytes\n"));
need_more_resources = 1;
}
if (segs_needed > nfree_msgmaps) {
#ifdef MSG_DEBUG_OK
printf("segs_needed > nfree_msgmaps\n");
#endif
DPRINTF(("segs_needed > nfree_msgmaps\n"));
need_more_resources = 1;
}
if (free_msghdrs == NULL) {
#ifdef MSG_DEBUG_OK
printf("no more msghdrs\n");
#endif
DPRINTF(("no more msghdrs\n"));
need_more_resources = 1;
}
@ -708,41 +657,30 @@ msgsnd(td, uap)
int we_own_it;
if ((msgflg & IPC_NOWAIT) != 0) {
#ifdef MSG_DEBUG_OK
printf("need more resources but caller doesn't want to wait\n");
#endif
DPRINTF(("need more resources but caller "
"doesn't want to wait\n"));
error = EAGAIN;
goto done2;
}
if ((msqptr->msg_perm.mode & MSG_LOCKED) != 0) {
#ifdef MSG_DEBUG_OK
printf("we don't own the msqid_ds\n");
#endif
DPRINTF(("we don't own the msqid_ds\n"));
we_own_it = 0;
} else {
/* Force later arrivals to wait for our
request */
#ifdef MSG_DEBUG_OK
printf("we own the msqid_ds\n");
#endif
DPRINTF(("we own the msqid_ds\n"));
msqptr->msg_perm.mode |= MSG_LOCKED;
we_own_it = 1;
}
#ifdef MSG_DEBUG_OK
printf("goodnight\n");
#endif
DPRINTF(("goodnight\n"));
error = tsleep(msqptr, (PZERO - 4) | PCATCH,
"msgwait", 0);
#ifdef MSG_DEBUG_OK
printf("good morning, error=%d\n", error);
#endif
DPRINTF(("good morning, error=%d\n", error));
if (we_own_it)
msqptr->msg_perm.mode &= ~MSG_LOCKED;
if (error != 0) {
#ifdef MSG_DEBUG_OK
printf("msgsnd: interrupted system call\n");
#endif
DPRINTF(("msgsnd: interrupted system call\n"));
error = EINTR;
goto done2;
}
@ -752,17 +690,13 @@ msgsnd(td, uap)
*/
if (msqptr->msg_qbytes == 0) {
#ifdef MSG_DEBUG_OK
printf("msqid deleted\n");
#endif
DPRINTF(("msqid deleted\n"));
error = EIDRM;
goto done2;
}
} else {
#ifdef MSG_DEBUG_OK
printf("got all the resources that we need\n");
#endif
DPRINTF(("got all the resources that we need\n"));
break;
}
}
@ -813,9 +747,7 @@ msgsnd(td, uap)
panic("next too low #1");
if (next >= msginfo.msgseg)
panic("next out of range #1");
#ifdef MSG_DEBUG_OK
printf("allocating segment %d to message\n", next);
#endif
DPRINTF(("allocating segment %d to message\n", next));
free_msgmaps = msgmaps[next].next;
nfree_msgmaps--;
msgmaps[next].next = msghdr->msg_spot;
@ -829,9 +761,7 @@ msgsnd(td, uap)
if ((error = copyin(user_msgp, &msghdr->msg_type,
sizeof(msghdr->msg_type))) != 0) {
#ifdef MSG_DEBUG_OK
printf("error %d copying the message type\n", error);
#endif
DPRINTF(("error %d copying the message type\n", error));
msg_freehdr(msghdr);
msqptr->msg_perm.mode &= ~MSG_LOCKED;
wakeup(msqptr);
@ -847,9 +777,7 @@ msgsnd(td, uap)
msg_freehdr(msghdr);
msqptr->msg_perm.mode &= ~MSG_LOCKED;
wakeup(msqptr);
#ifdef MSG_DEBUG_OK
printf("mtype (%d) < 1\n", msghdr->msg_type);
#endif
DPRINTF(("mtype (%d) < 1\n", msghdr->msg_type));
error = EINVAL;
goto done2;
}
@ -871,9 +799,8 @@ msgsnd(td, uap)
panic("next out of range #2");
if ((error = copyin(user_msgp, &msgpool[next * msginfo.msgssz],
tlen)) != 0) {
#ifdef MSG_DEBUG_OK
printf("error %d copying in message segment\n", error);
#endif
DPRINTF(("error %d copying in message segment\n",
error));
msg_freehdr(msghdr);
msqptr->msg_perm.mode &= ~MSG_LOCKED;
wakeup(msqptr);
@ -957,10 +884,8 @@ msgrcv(td, uap)
int error = 0;
short next;
#ifdef MSG_DEBUG_OK
printf("call to msgrcv(%d, 0x%x, %d, %ld, %d)\n", msqid, user_msgp,
msgsz, msgtyp, msgflg);
#endif
DPRINTF(("call to msgrcv(%d, 0x%x, %d, %ld, %d)\n", msqid, user_msgp,
msgsz, msgtyp, msgflg));
if (!jail_sysvipc_allowed && jailed(td->td_ucred))
return (ENOSYS);
@ -969,34 +894,26 @@ msgrcv(td, uap)
msqid = IPCID_TO_IX(msqid);
if (msqid < 0 || msqid >= msginfo.msgmni) {
#ifdef MSG_DEBUG_OK
printf("msqid (%d) out of range (0<=msqid<%d)\n", msqid,
msginfo.msgmni);
#endif
DPRINTF(("msqid (%d) out of range (0<=msqid<%d)\n", msqid,
msginfo.msgmni));
error = EINVAL;
goto done2;
}
msqptr = &msqids[msqid];
if (msqptr->msg_qbytes == 0) {
#ifdef MSG_DEBUG_OK
printf("no such message queue id\n");
#endif
DPRINTF(("no such message queue id\n"));
error = EINVAL;
goto done2;
}
if (msqptr->msg_perm.seq != IPCID_TO_SEQ(uap->msqid)) {
#ifdef MSG_DEBUG_OK
printf("wrong sequence number\n");
#endif
DPRINTF(("wrong sequence number\n"));
error = EINVAL;
goto done2;
}
if ((error = ipcperm(td, &msqptr->msg_perm, IPC_R))) {
#ifdef MSG_DEBUG_OK
printf("requester doesn't have read access\n");
#endif
DPRINTF(("requester doesn't have read access\n"));
goto done2;
}
@ -1007,10 +924,9 @@ msgrcv(td, uap)
if (msghdr != NULL) {
if (msgsz < msghdr->msg_ts &&
(msgflg & MSG_NOERROR) == 0) {
#ifdef MSG_DEBUG_OK
printf("first message on the queue is too big (want %d, got %d)\n",
msgsz, msghdr->msg_ts);
#endif
DPRINTF(("first message on the queue "
"is too big (want %d, got %d)\n",
msgsz, msghdr->msg_ts));
error = E2BIG;
goto done2;
}
@ -1041,16 +957,15 @@ msgrcv(td, uap)
if (msgtyp == msghdr->msg_type ||
msghdr->msg_type <= -msgtyp) {
#ifdef MSG_DEBUG_OK
printf("found message type %d, requested %d\n",
msghdr->msg_type, msgtyp);
#endif
DPRINTF(("found message type %d, "
"requested %d\n",
msghdr->msg_type, msgtyp));
if (msgsz < msghdr->msg_ts &&
(msgflg & MSG_NOERROR) == 0) {
#ifdef MSG_DEBUG_OK
printf("requested message on the queue is too big (want %d, got %d)\n",
msgsz, msghdr->msg_ts);
#endif
DPRINTF(("requested message "
"on the queue is too big "
"(want %d, got %d)\n",
msgsz, msghdr->msg_ts));
error = E2BIG;
goto done2;
}
@ -1093,10 +1008,8 @@ msgrcv(td, uap)
*/
if ((msgflg & IPC_NOWAIT) != 0) {
#ifdef MSG_DEBUG_OK
printf("no appropriate message found (msgtyp=%d)\n",
msgtyp);
#endif
DPRINTF(("no appropriate message found (msgtyp=%d)\n",
msgtyp));
/* The SVID says to return ENOMSG. */
error = ENOMSG;
goto done2;
@ -1106,18 +1019,12 @@ msgrcv(td, uap)
* Wait for something to happen
*/
#ifdef MSG_DEBUG_OK
printf("msgrcv: goodnight\n");
#endif
DPRINTF(("msgrcv: goodnight\n"));
error = tsleep(msqptr, (PZERO - 4) | PCATCH, "msgwait", 0);
#ifdef MSG_DEBUG_OK
printf("msgrcv: good morning (error=%d)\n", error);
#endif
DPRINTF(("msgrcv: good morning (error=%d)\n", error));
if (error != 0) {
#ifdef MSG_DEBUG_OK
printf("msgsnd: interrupted system call\n");
#endif
DPRINTF(("msgsnd: interrupted system call\n"));
error = EINTR;
goto done2;
}
@ -1128,9 +1035,7 @@ msgrcv(td, uap)
if (msqptr->msg_qbytes == 0 ||
msqptr->msg_perm.seq != IPCID_TO_SEQ(uap->msqid)) {
#ifdef MSG_DEBUG_OK
printf("msqid deleted\n");
#endif
DPRINTF(("msqid deleted\n"));
error = EIDRM;
goto done2;
}
@ -1153,10 +1058,8 @@ msgrcv(td, uap)
* (since msgsz is never increased).
*/
#ifdef MSG_DEBUG_OK
printf("found a message, msgsz=%d, msg_ts=%d\n", msgsz,
msghdr->msg_ts);
#endif
DPRINTF(("found a message, msgsz=%d, msg_ts=%d\n", msgsz,
msghdr->msg_ts));
if (msgsz > msghdr->msg_ts)
msgsz = msghdr->msg_ts;
@ -1167,9 +1070,7 @@ msgrcv(td, uap)
error = copyout(&(msghdr->msg_type), user_msgp,
sizeof(msghdr->msg_type));
if (error != 0) {
#ifdef MSG_DEBUG_OK
printf("error (%d) copying out message type\n", error);
#endif
DPRINTF(("error (%d) copying out message type\n", error));
msg_freehdr(msghdr);
wakeup(msqptr);
goto done2;
@ -1195,10 +1096,8 @@ msgrcv(td, uap)
error = copyout(&msgpool[next * msginfo.msgssz],
user_msgp, tlen);
if (error != 0) {
#ifdef MSG_DEBUG_OK
printf("error (%d) copying out message segment\n",
error);
#endif
DPRINTF(("error (%d) copying out message segment\n",
error));
msg_freehdr(msghdr);
wakeup(msqptr);
goto done2;

View file

@ -26,6 +26,12 @@
static MALLOC_DEFINE(M_SEM, "sem", "SVID compatible semaphores");
#ifdef SEM_DEBUG
#define DPRINTF(a) printf a
#else
#define DPRINTF(a)
#endif
static void seminit(void);
static int sysvsem_modload(struct module *, int, void *);
static int semunload(void);
@ -477,9 +483,8 @@ __semctl(td, uap)
register struct semid_ds *semaptr;
u_short usval;
#ifdef SEM_DEBUG
printf("call to semctl(%d, %d, %d, 0x%x)\n", semid, semnum, cmd, arg);
#endif
DPRINTF(("call to semctl(%d, %d, %d, 0x%x)\n",
semid, semnum, cmd, arg));
if (!jail_sysvipc_allowed && jailed(td->td_ucred))
return (ENOSYS);
@ -686,9 +691,7 @@ semget(td, uap)
int semflg = uap->semflg;
struct ucred *cred = td->td_ucred;
#ifdef SEM_DEBUG
printf("semget(0x%x, %d, 0%o)\n", key, nsems, semflg);
#endif
DPRINTF(("semget(0x%x, %d, 0%o)\n", key, nsems, semflg));
if (!jail_sysvipc_allowed && jailed(td->td_ucred))
return (ENOSYS);
@ -700,24 +703,18 @@ semget(td, uap)
break;
}
if (semid < seminfo.semmni) {
#ifdef SEM_DEBUG
printf("found public key\n");
#endif
DPRINTF(("found public key\n"));
if ((error = ipcperm(td, &sema[semid].sem_perm,
semflg & 0700))) {
goto done2;
}
if (nsems > 0 && sema[semid].sem_nsems < nsems) {
#ifdef SEM_DEBUG
printf("too small\n");
#endif
DPRINTF(("too small\n"));
error = EINVAL;
goto done2;
}
if ((semflg & IPC_CREAT) && (semflg & IPC_EXCL)) {
#ifdef SEM_DEBUG
printf("not exclusive\n");
#endif
DPRINTF(("not exclusive\n"));
error = EEXIST;
goto done2;
}
@ -725,23 +722,18 @@ semget(td, uap)
}
}
#ifdef SEM_DEBUG
printf("need to allocate the semid_ds\n");
#endif
DPRINTF(("need to allocate the semid_ds\n"));
if (key == IPC_PRIVATE || (semflg & IPC_CREAT)) {
if (nsems <= 0 || nsems > seminfo.semmsl) {
#ifdef SEM_DEBUG
printf("nsems out of range (0<%d<=%d)\n", nsems,
seminfo.semmsl);
#endif
DPRINTF(("nsems out of range (0<%d<=%d)\n", nsems,
seminfo.semmsl));
error = EINVAL;
goto done2;
}
if (nsems > seminfo.semmns - semtot) {
#ifdef SEM_DEBUG
printf("not enough semaphores left (need %d, got %d)\n",
nsems, seminfo.semmns - semtot);
#endif
DPRINTF((
"not enough semaphores left (need %d, got %d)\n",
nsems, seminfo.semmns - semtot));
error = ENOSPC;
goto done2;
}
@ -750,15 +742,11 @@ semget(td, uap)
break;
}
if (semid == seminfo.semmni) {
#ifdef SEM_DEBUG
printf("no more semid_ds's available\n");
#endif
DPRINTF(("no more semid_ds's available\n"));
error = ENOSPC;
goto done2;
}
#ifdef SEM_DEBUG
printf("semid %d is available\n", semid);
#endif
DPRINTF(("semid %d is available\n", semid));
sema[semid].sem_perm.key = key;
sema[semid].sem_perm.cuid = cred->cr_uid;
sema[semid].sem_perm.uid = cred->cr_uid;
@ -774,14 +762,10 @@ semget(td, uap)
semtot += nsems;
bzero(sema[semid].sem_base,
sizeof(sema[semid].sem_base[0])*nsems);
#ifdef SEM_DEBUG
printf("sembase = 0x%x, next = 0x%x\n", sema[semid].sem_base,
&sem[semtot]);
#endif
DPRINTF(("sembase = 0x%x, next = 0x%x\n", sema[semid].sem_base,
&sem[semtot]));
} else {
#ifdef SEM_DEBUG
printf("didn't find it and wasn't asked to create it\n");
#endif
DPRINTF(("didn't find it and wasn't asked to create it\n"));
error = ENOENT;
goto done2;
}
@ -819,9 +803,7 @@ semop(td, uap)
int i, j, error;
int do_wakeup, do_undos;
#ifdef SEM_DEBUG
printf("call to semop(%d, 0x%x, %u)\n", semid, sops, nsops);
#endif
DPRINTF(("call to semop(%d, 0x%x, %u)\n", semid, sops, nsops));
if (!jail_sysvipc_allowed && jailed(td->td_ucred))
return (ENOSYS);
@ -844,10 +826,8 @@ semop(td, uap)
goto done2;
}
if (nsops > seminfo.semopm) {
#ifdef SEM_DEBUG
printf("too many sops (max=%d, nsops=%d)\n", seminfo.semopm,
nsops);
#endif
DPRINTF(("too many sops (max=%d, nsops=%d)\n", seminfo.semopm,
nsops));
error = E2BIG;
goto done2;
}
@ -858,10 +838,8 @@ semop(td, uap)
panic("Failed to allocate %d sem_ops", nsops);
if ((error = copyin(uap->sops, sops, nsops * sizeof(sops[0]))) != 0) {
#ifdef SEM_DEBUG
printf("error = %d from copyin(%08x, %08x, %d)\n", error,
uap->sops, sops, nsops * sizeof(sops[0]));
#endif
DPRINTF(("error = %d from copyin(%08x, %08x, %d)\n", error,
uap->sops, sops, nsops * sizeof(sops[0])));
goto done2;
}
@ -884,9 +862,7 @@ semop(td, uap)
}
if ((error = ipcperm(td, &semaptr->sem_perm, j))) {
#ifdef SEM_DEBUG
printf("error = %d from ipaccess\n", error);
#endif
DPRINTF(("error = %d from ipaccess\n", error));
goto done2;
}
@ -907,18 +883,17 @@ semop(td, uap)
sopptr = &sops[i];
semptr = &semaptr->sem_base[sopptr->sem_num];
#ifdef SEM_DEBUG
printf("semop: semaptr=%x, sem_base=%x, semptr=%x, sem[%d]=%d : op=%d, flag=%s\n",
DPRINTF((
"semop: semaptr=%x, sem_base=%x, "
"semptr=%x, sem[%d]=%d : op=%d, flag=%s\n",
semaptr, semaptr->sem_base, semptr,
sopptr->sem_num, semptr->semval, sopptr->sem_op,
(sopptr->sem_flg & IPC_NOWAIT) ? "nowait" : "wait");
#endif
(sopptr->sem_flg & IPC_NOWAIT) ?
"nowait" : "wait"));
if (sopptr->sem_op < 0) {
if (semptr->semval + sopptr->sem_op < 0) {
#ifdef SEM_DEBUG
printf("semop: can't do it now\n");
#endif
DPRINTF(("semop: can't do it now\n"));
break;
} else {
semptr->semval += sopptr->sem_op;
@ -928,9 +903,7 @@ semop(td, uap)
}
} else if (sopptr->sem_op == 0) {
if (semptr->semval != 0) {
#ifdef SEM_DEBUG
printf("semop: not zero now\n");
#endif
DPRINTF(("semop: not zero now\n"));
break;
}
} else if (semptr->semval + sopptr->sem_op >
@ -953,9 +926,7 @@ semop(td, uap)
/*
* No ... rollback anything that we've already done
*/
#ifdef SEM_DEBUG
printf("semop: rollback 0 through %d\n", i-1);
#endif
DPRINTF(("semop: rollback 0 through %d\n", i-1));
for (j = 0; j < i; j++)
semaptr->sem_base[sops[j].sem_num].semval -=
sops[j].sem_op;
@ -978,21 +949,15 @@ semop(td, uap)
else
semptr->semncnt++;
#ifdef SEM_DEBUG
printf("semop: good night!\n");
#endif
DPRINTF(("semop: good night!\n"));
error = tsleep(semaptr, (PZERO - 4) | PCATCH, "semwait", 0);
#ifdef SEM_DEBUG
printf("semop: good morning (error=%d)!\n", error);
#endif
DPRINTF(("semop: good morning (error=%d)!\n", error));
if (error != 0) {
error = EINTR;
goto done2;
}
#ifdef SEM_DEBUG
printf("semop: good morning!\n");
#endif
DPRINTF(("semop: good morning!\n"));
/*
* Make sure that the semaphore still exists
@ -1060,9 +1025,7 @@ done:
semaptr->sem_base[sops[j].sem_num].semval -=
sops[j].sem_op;
#ifdef SEM_DEBUG
printf("error = %d from semundo_adjust\n", error);
#endif
DPRINTF(("error = %d from semundo_adjust\n", error));
goto done2;
} /* loop through the sops */
} /* if (do_undos) */
@ -1080,17 +1043,11 @@ done:
* sleeping on it.
*/
if (do_wakeup) {
#ifdef SEM_DEBUG
printf("semop: doing wakeup\n");
#endif
DPRINTF(("semop: doing wakeup\n"));
wakeup(semaptr);
#ifdef SEM_DEBUG
printf("semop: back from wakeup\n");
#endif
DPRINTF(("semop: back from wakeup\n"));
}
#ifdef SEM_DEBUG
printf("semop: done\n");
#endif
DPRINTF(("semop: done\n"));
td->td_retval[0] = 0;
done2:
if (sops)
@ -1124,10 +1081,8 @@ semexit_myhook(p)
if (suptr == NULL)
return;
#ifdef SEM_DEBUG
printf("proc @%08x has undo structure with %d entries\n", p,
suptr->un_cnt);
#endif
DPRINTF(("proc @%08x has undo structure with %d entries\n", p,
suptr->un_cnt));
/*
* If there are any active undo elements then process them.
@ -1147,13 +1102,12 @@ semexit_myhook(p)
if (semnum >= semaptr->sem_nsems)
panic("semexit - semnum out of range");
#ifdef SEM_DEBUG
printf("semexit: %08x id=%d num=%d(adj=%d) ; sem=%d\n",
DPRINTF((
"semexit: %08x id=%d num=%d(adj=%d) ; sem=%d\n",
suptr->un_proc, suptr->un_ent[ix].un_id,
suptr->un_ent[ix].un_num,
suptr->un_ent[ix].un_adjval,
semaptr->sem_base[semnum].semval);
#endif
semaptr->sem_base[semnum].semval));
if (adjval < 0) {
if (semaptr->sem_base[semnum].semval < -adjval)
@ -1165,18 +1119,14 @@ semexit_myhook(p)
semaptr->sem_base[semnum].semval += adjval;
wakeup(semaptr);
#ifdef SEM_DEBUG
printf("semexit: back from wakeup\n");
#endif
DPRINTF(("semexit: back from wakeup\n"));
}
}
/*
* Deallocate the undo vector.
*/
#ifdef SEM_DEBUG
printf("removing vector\n");
#endif
DPRINTF(("removing vector\n"));
suptr->un_proc = NULL;
*supptr = suptr->un_next;
}