minix/minix/lib/libsys/sys_mq_send.c
Sanchayan Maity fe71ea4bc1 First round of assorted bug fixes
Fixed the following bugs:
1. Message priority was not set at all at two places
2. Limits check was not correct while returning error values
3. We are suppose to allow multiple users operate on the same queue
using a named descriptor. However any one user calling close before
the other would result in closing the queue even when other users
might be using it. Track number of users and close only if number of
users is zero. Yet to do functional tests for this, so this is untested,
but introduce it anyway at this juncture.
2016-03-19 11:49:48 +05:30

33 lines
792 B
C

#include "syslib.h"
#include <string.h>
#include <machine/archtypes.h>
#include <minix/timers.h>
#include <minix/sysutil.h>
#include <minix/vm.h>
#define MAX_RECEIVERS 4
#define MAX_PAYLOAD 32
int sys_mq_send(int mqdes, const char *msg_ptr, pid_t dst[], unsigned int msg_prio)
{
message m;
m.m_lsys_krn_sys_mqueue_send.mqdes = mqdes;
m.m_lsys_krn_sys_mqueue_send.msg_prio = msg_prio;
for (int i = 0; i < MAX_RECEIVERS; i++) {
if (dst[i] == -1) {
m.m_lsys_krn_sys_mqueue_send.dst[i] = dst[i];
break;
}
endpoint_t endpoint;
int ret = sys_endpoint_from_pid(dst[i], &endpoint);
if (ret != 0)
endpoint = -1;
m.m_lsys_krn_sys_mqueue_send.dst[i] = endpoint;
}
memcpy(m.m_lsys_krn_sys_mqueue_send.msg, msg_ptr, MAX_PAYLOAD);
return (_kernel_call(SYS_MQ_SEND, &m));
}