【更新】 消息队列存在时,使用 O_CREAT 不应创建新的消息队列

This commit is contained in:
zhkag 2023-01-07 02:09:40 +00:00 committed by guo
parent 1730874cd8
commit dcaa0c166d
1 changed files with 9 additions and 12 deletions

View File

@ -121,7 +121,13 @@ mqd_t mq_open(const char *name, int oflag, ...)
rt_sem_take(&posix_mq_lock, RT_WAITING_FOREVER); rt_sem_take(&posix_mq_lock, RT_WAITING_FOREVER);
mqdes = RT_NULL; mqdes = RT_NULL;
if (oflag & O_CREAT) /* find mqueue */
mqdes = posix_mq_find(name);
if (mqdes != RT_NULL)
{
mqdes->refcount ++; /* increase reference count */
}
else if (oflag & O_CREAT)
{ {
va_start(arg, oflag); va_start(arg, oflag);
mode = (mode_t)va_arg(arg, unsigned int); mode = (mode_t)va_arg(arg, unsigned int);
@ -160,19 +166,10 @@ mqd_t mq_open(const char *name, int oflag, ...)
posix_mq_insert(mqdes); posix_mq_insert(mqdes);
} }
else else
{
/* find mqueue */
mqdes = posix_mq_find(name);
if (mqdes != RT_NULL)
{
mqdes->refcount ++; /* increase reference count */
}
else
{ {
rt_set_errno(ENOENT); rt_set_errno(ENOENT);
goto __return; goto __return;
} }
}
rt_sem_release(&posix_mq_lock); rt_sem_release(&posix_mq_lock);
return (mqd_t)((uintptr_t)mqdes >> 1); return (mqd_t)((uintptr_t)mqdes >> 1);