提交 ff003787 编写于 作者: B Bernard Xiong

[libc] Fix the unamed pipe close issue

上级 c9bcfcc6
......@@ -24,6 +24,7 @@
struct rt_pipe_device
{
struct rt_device parent;
rt_bool_t is_named;
/* ring buffer in pipe device */
struct rt_ringbuffer *fifo;
......
......@@ -97,6 +97,12 @@ static int pipe_fops_close(struct dfs_fd *fd)
rt_mutex_release(&(pipe->lock));
if (device->ref_count == 0 && pipe->is_named == RT_FALSE)
{
/* delete the unamed pipe */
rt_pipe_delete(device->parent.name);
}
return 0;
}
......@@ -423,6 +429,7 @@ rt_pipe_t *rt_pipe_create(const char *name, int bufsz)
if (pipe == RT_NULL) return RT_NULL;
rt_memset(pipe, 0, sizeof(rt_pipe_t));
pipe->is_named = RT_TRUE; /* initialize as a named pipe */
rt_mutex_init(&(pipe->lock), name, RT_IPC_FLAG_FIFO);
rt_wqueue_init(&(pipe->reader_queue));
rt_wqueue_init(&(pipe->writer_queue));
......@@ -517,6 +524,7 @@ int pipe(int fildes[2])
return -1;
}
pipe->is_named = RT_FALSE; /* unamed pipe */
rt_snprintf(dev_name, sizeof(dev_name), "/dev/%s", dname);
fildes[0] = open(dev_name, O_RDONLY, 0);
if (fildes[0] < 0)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册