4
0
mirror of https://github.com/RT-Thread/rt-thread.git synced 2025-01-18 10:03:30 +08:00

[libc] Fix the unamed pipe close issue

This commit is contained in:
Bernard Xiong 2019-03-31 15:21:49 +08:00
parent c9bcfcc63c
commit ff00378728
2 changed files with 9 additions and 0 deletions

View File

@ -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;

View File

@ -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)