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:
parent
f48693eaf5
commit
d4e7fe55c7
@ -192,6 +192,7 @@ int file_pipe(FAR struct file *filep[2], size_t bufsize, int flags)
|
||||
{
|
||||
char devname[32];
|
||||
int ret;
|
||||
bool blocking;
|
||||
|
||||
/* Register a new pipe device */
|
||||
|
||||
@ -201,14 +202,29 @@ int file_pipe(FAR struct file *filep[2], size_t bufsize, int flags)
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Check for the O_NONBLOCK bit on flags */
|
||||
|
||||
blocking = (flags & O_NONBLOCK) == 0;
|
||||
|
||||
/* 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)
|
||||
{
|
||||
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 */
|
||||
|
||||
ret = file_open(filep[0], devname, O_RDONLY | flags);
|
||||
|
Loading…
Reference in New Issue
Block a user