/* uipc_mu_msg.c Melb 4.3 82/12/28 */
* Melbourne Trivial IPC mechanism
* This is intended solely to serve for the 4.1bsd MUSH implementation
* until a better IPC scheme arrives from somewhere
* If it happens to be useful for other purposes, OK, but users
* should be prepared to change at short (no) notice.
* This is purposely kept as small as possible, with the expectation
* than anything done using this scheme should be able to be
* done easily in any other, with possibly a little more legwork.
* NB: we don't go fooling with spl's in here, as it is deliberately
* not intended that interrupt level code will ever call this
register struct proc
*p
, *pp
;
int wait
; /* bit mask - see mu_msg.h */
uap
= (struct a
*)u
.u_ap
;
for (;;) { /* only loop if cmd == MSG_SNDW */
p
->p_msgflgs
&= ~MSGENAB
;
* Q: what should be done with a pending msg
* - for now we will just leave it, proc should
* do a MSG_RECV w/o waiting after MSG_DISB
while (!p
->p_mb
.msg_val
&& (uap
->wait
& MSG_W_RCV
)) {
sleep((caddr_t
) &p
->p_mb
, MSGPRI
);
u
.u_error
= copyout((caddr_t
)&p
->p_mb
,
(caddr_t
)uap
->msgp
, sizeof(mmsgbuf
));
p
->p_msgflgs
&= ~(MSGOK
|MSGWRPLY
);
if (p
->p_msgflgs
& MSGWAIT
) {
p
->p_msgflgs
&= ~MSGWAIT
;
wakeup((caddr_t
)&p
->p_mb
);
u
.u_error
= copyin((caddr_t
)uap
->msgp
, (caddr_t
)&mb
,
if (uap
->cmd
== MSG_RPLY
) {
if (!(p
->p_msgflgs
& MSGRPLY
) ||
mb
.msg_pid
!= p
->p_mb
.msg_pid
) {
if (!mb
.msg_rply
&& p
->p_msgflgs
& MSGWAIT
) {
p
->p_msgflgs
&= ~MSGWAIT
;
wakeup((caddr_t
)&p
->p_mb
);
if (p
->p_msgflgs
& MSGRPLY
) {
while (pp
= mu_send(&p
->p_mb
,
(int)p
->p_mb
.msg_pid
, 0)) {
pp
->p_msgflgs
|= MSGWAIT
;
sleep((caddr_t
)&pp
->p_mb
,
u
.u_error
= 0; /* not err if exited */
p
->p_msgflgs
& MSGWAIT
) {
p
->p_msgflgs
&= ~MSGWAIT
;
wakeup((caddr_t
)&p
->p_mb
);
p
->p_msgflgs
&= ~MSGRPLY
;
p
->p_msgflgs
|= MSGWRPLY
;
while ((pp
= mu_send(&mb
, (int)mb
.msg_pid
, p
->p_pid
)) &&
uap
->wait
& MSG_W_POST
) {
pp
->p_msgflgs
|= MSGWAIT
;
sleep((caddr_t
)&pp
->p_mb
, MSGPRI
);
p
->p_msgflgs
&= ~MSGWRPLY
;
if (uap
->cmd
== MSG_SNDW
) {
if (p
== NULL
|| p
->p_stat
== SZOMB
||
!(p
->p_msgflgs
& (MSGOK
|MSGENAB
|MSGWRPLY
))) {
return((struct proc
*)0);
from
!= 0 && p
->p_msgflgs
&MSGWRPLY
&& from
!= p
->p_mb
.msg_pid
)
if (p
->p_msgflgs
& MSGOK
)
wakeup((caddr_t
)&p
->p_mb
);
else if (p
->p_msgflgs
& MSGENAB
)
return((struct proc
*)0);
mb
.msg_uid
= 0; /* all msgs from system are from root */
while (p
= mu_send(&mb
, pid
, u
.u_procp
->p_pid
)) {
sleep((caddr_t
)&p
->p_mb
, MSGPRI
);