summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzhkag <[email protected]>2023-01-07 02:09:40 +0000
committerguo <[email protected]>2023-01-09 09:32:07 +0800
commitdcaa0c166d0379dba734fde47d911ba7ffd971ce (patch)
tree39101b693fe536bf2cce3f684b7901bf3c7198bf
parent1730874cd89a5c86d178dab92030227c8820223a (diff)
【更新】 消息队列存在时,使用 O_CREAT 不应创建新的消息队列
-rw-r--r--components/libc/posix/ipc/mqueue.c21
1 files changed, 9 insertions, 12 deletions
diff --git a/components/libc/posix/ipc/mqueue.c b/components/libc/posix/ipc/mqueue.c
index 8cbe440c9f..8f78037c82 100644
--- a/components/libc/posix/ipc/mqueue.c
+++ b/components/libc/posix/ipc/mqueue.c
@@ -121,7 +121,13 @@ mqd_t mq_open(const char *name, int oflag, ...)
rt_sem_take(&posix_mq_lock, RT_WAITING_FOREVER);
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);
mode = (mode_t)va_arg(arg, unsigned int);
@@ -161,17 +167,8 @@ mqd_t mq_open(const char *name, int oflag, ...)
}
else
{
- /* find mqueue */
- mqdes = posix_mq_find(name);
- if (mqdes != RT_NULL)
- {
- mqdes->refcount ++; /* increase reference count */
- }
- else
- {
- rt_set_errno(ENOENT);
- goto __return;
- }
+ rt_set_errno(ENOENT);
+ goto __return;
}
rt_sem_release(&posix_mq_lock);