mirror of
https://github.com/apache/nuttx.git
synced 2026-06-02 09:38:37 +08:00
drivers/pipe: fix blocking file_pipe
Similar to the fix introduced by
4d6a8663fa, it's necessary to set
one end of the file_pipe as non-blocking temporarily while opening
the other end to avoid it blocking unexpectedily.
This commit is contained in:
committed by
Xiang Xiao
parent
f48693eaf5
commit
d4e7fe55c7
+17
-1
@@ -192,6 +192,7 @@ int file_pipe(FAR struct file *filep[2], size_t bufsize, int flags)
|
|||||||
{
|
{
|
||||||
char devname[32];
|
char devname[32];
|
||||||
int ret;
|
int ret;
|
||||||
|
bool blocking;
|
||||||
|
|
||||||
/* Register a new pipe device */
|
/* Register a new pipe device */
|
||||||
|
|
||||||
@@ -201,14 +202,29 @@ int file_pipe(FAR struct file *filep[2], size_t bufsize, int flags)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Check for the O_NONBLOCK bit on flags */
|
||||||
|
|
||||||
|
blocking = (flags & O_NONBLOCK) == 0;
|
||||||
|
|
||||||
/* Get a write file descriptor */
|
/* Get a write file descriptor */
|
||||||
|
|
||||||
ret = file_open(filep[1], devname, O_WRONLY | flags);
|
ret = file_open(filep[1], devname, O_WRONLY | O_NONBLOCK | flags);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
goto errout_with_driver;
|
goto errout_with_driver;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Clear O_NONBLOCK if it was set previously */
|
||||||
|
|
||||||
|
if (blocking)
|
||||||
|
{
|
||||||
|
ret = file_fcntl(filep[1], F_SETFL, flags & (~O_NONBLOCK));
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
goto errout_with_driver;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Get a read file descriptor */
|
/* Get a read file descriptor */
|
||||||
|
|
||||||
ret = file_open(filep[0], devname, O_RDONLY | flags);
|
ret = file_open(filep[0], devname, O_RDONLY | flags);
|
||||||
|
|||||||
Reference in New Issue
Block a user