In message queue created return ENOSPC error if size exceeds the configured size of pre-allocatd messages; Use ENOSPC vs ENOMEM per OpenGroup.org. From Pierre-Noel Bouteville

This commit is contained in:
Gregory Nutt 2014-12-06 07:18:48 -06:00
parent d007a49194
commit ff87e2e02a
3 changed files with 22 additions and 25 deletions

View File

@ -52,17 +52,8 @@
#include "inode/inode.h" #include "inode/inode.h"
#include "mqueue/mqueue.h" #include "mqueue/mqueue.h"
#if 0
#include <sys/types.h>
#include <stdint.h>
#include <debug.h>
#include "sched/sched.h"
#endif
/**************************************************************************** /****************************************************************************
* Pre-procesor Definitions * Pre-processor Definitions
****************************************************************************/ ****************************************************************************/
/**************************************************************************** /****************************************************************************
@ -220,7 +211,7 @@ mqd_t mq_open(FAR const char *mq_name, int oflags, ...)
msgq = (FAR struct mqueue_inode_s*)mq_msgqalloc(mode, attr); msgq = (FAR struct mqueue_inode_s*)mq_msgqalloc(mode, attr);
if (!msgq) if (!msgq)
{ {
errcode = ENOMEM; errcode = ENOSPC;
goto errout_with_inode; goto errout_with_inode;
} }

View File

@ -40,6 +40,7 @@
#include <nuttx/config.h> #include <nuttx/config.h>
#include <mqueue.h> #include <mqueue.h>
#include <assert.h>
#include <nuttx/kmalloc.h> #include <nuttx/kmalloc.h>
#include <nuttx/sched.h> #include <nuttx/sched.h>
@ -77,16 +78,16 @@
* *
* Description: * Description:
* This function implements a part of the POSIX message queue open logic. * This function implements a part of the POSIX message queue open logic.
* It allocates and initializes a structu mqueue_inode_s structure. * It allocates and initializes a struct mqueue_inode_s structure.
* *
* Parameters: * Parameters:
* mode - mode_t value is ignored * mode - mode_t value is ignored
* attr - The mq_maxmsg attribute is used at the time that the message * attr - The mq_maxmsg attribute is used at the time that the message
* queue is created to determine the maximum number of * queue is created to determine the maximum number of
* messages that may be placed in the message queue. * messages that may be placed in the message queue.
* *
* Return Value: * Return Value:
* The allocated and initalized message queue structure or NULL in the * The allocated and initialized message queue structure or NULL in the
* event of a failure. * event of a failure.
* *
****************************************************************************/ ****************************************************************************/
@ -96,9 +97,21 @@ FAR struct mqueue_inode_s *mq_msgqalloc(mode_t mode,
{ {
FAR struct mqueue_inode_s *msgq; FAR struct mqueue_inode_s *msgq;
/* Check if the caller is attempting to allocate a message for messages
* larger than the configured maximum message size.
*/
DEBUGASSERT(!attr || attr->mq_msgsize <= MQ_MAX_BYTES);
if (attr && attr->mq_msgsize > MQ_MAX_BYTES)
{
return NULL;
}
/* Allocate memory for the new message queue. */ /* Allocate memory for the new message queue. */
msgq = (FAR struct mqueue_inode_s*)kmm_zalloc(sizeof(struct mqueue_inode_s)); msgq = (FAR struct mqueue_inode_s*)
kmm_zalloc(sizeof(struct mqueue_inode_s));
if (msgq) if (msgq)
{ {
/* Initialize the new named message queue */ /* Initialize the new named message queue */
@ -106,15 +119,8 @@ FAR struct mqueue_inode_s *mq_msgqalloc(mode_t mode,
sq_init(&msgq->msglist); sq_init(&msgq->msglist);
if (attr) if (attr)
{ {
msgq->maxmsgs = (int16_t)attr->mq_maxmsg; msgq->maxmsgs = (int16_t)attr->mq_maxmsg;
if (attr->mq_msgsize <= MQ_MAX_BYTES) msgq->maxmsgsize = (int16_t)attr->mq_msgsize;
{
msgq->maxmsgsize = (int16_t)attr->mq_msgsize;
}
else
{
msgq->maxmsgsize = MQ_MAX_BYTES;
}
} }
else else
{ {

View File

@ -98,7 +98,7 @@ struct mqueue_msg_s
#else #else
uint16_t msglen; /* Message data length */ uint16_t msglen; /* Message data length */
#endif #endif
uint8_t mail[MQ_MAX_BYTES]; /* Message data */ char mail[MQ_MAX_BYTES]; /* Message data */
}; };
/**************************************************************************** /****************************************************************************