From 59fd10000eb0a3e87d345e5bc4fff5934af447fd Mon Sep 17 00:00:00 2001 From: yangjiao Date: Fri, 9 Jun 2023 17:45:22 +0800 Subject: [PATCH] sched/mqueue/mq_send: fix the wrong return value in mq_send function. And add the condition if message priority equal to MQ_PRIO_MAX. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Standard POSIX specification in URL “https://pubs.opengroup.org/onlinepubs/9699919799/functions/mq_send.html” requires that "EBADF" be returned when mqdes is not open for writing. And message priorities range from 0 to {MQ_PRIO_MAX}-1. In this change, i update them to follow POSIX spec. Signed-off-by: yangjiao --- sched/mqueue/mq_send.c | 2 +- sched/mqueue/mq_sndinternal.c | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/sched/mqueue/mq_send.c b/sched/mqueue/mq_send.c index 0df8c7b2b8..4ca49d54d5 100644 --- a/sched/mqueue/mq_send.c +++ b/sched/mqueue/mq_send.c @@ -216,7 +216,7 @@ int nxmq_send(mqd_t mqdes, FAR const char *msg, size_t msglen, * EAGAIN The queue was full and the O_NONBLOCK flag was set for the * message queue description referred to by mqdes. * EINVAL Either msg or mqdes is NULL or the value of prio is invalid. - * EPERM Message queue opened not opened for writing. + * EBADF Message queue opened not opened for writing. * EMSGSIZE 'msglen' was greater than the maxmsgsize attribute of the * message queue. * EINTR The call was interrupted by a signal handler. diff --git a/sched/mqueue/mq_sndinternal.c b/sched/mqueue/mq_sndinternal.c index fe0af476fb..eceff480e5 100644 --- a/sched/mqueue/mq_sndinternal.c +++ b/sched/mqueue/mq_sndinternal.c @@ -66,7 +66,7 @@ * returned. * * EINVAL Either msg or msgq is NULL or the value of prio is invalid. - * EPERM Message queue opened not opened for writing. + * EBADF Message queue opened not opened for writing. * EMSGSIZE 'msglen' was greater than the maxmsgsize attribute of the * message queue. * @@ -88,14 +88,14 @@ int nxmq_verify_send(FAR FAR struct file *mq, FAR const char *msg, /* Verify the input parameters */ - if (msg == NULL || msgq == NULL || prio > MQ_PRIO_MAX) + if (msg == NULL || msgq == NULL || prio >= MQ_PRIO_MAX) { return -EINVAL; } if ((mq->f_oflags & O_WROK) == 0) { - return -EPERM; + return -EBADF; } if (msglen > (size_t)msgq->maxmsgsize)