vfs/dup: add nonblock flag to avoid happening block when dup

Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
This commit is contained in:
dongjiuzhu1 2023-04-19 12:31:09 +08:00 committed by Xiang Xiao
parent 9fdf36c17e
commit f8991f7782
1 changed files with 18 additions and 0 deletions

View File

@ -23,11 +23,14 @@
****************************************************************************/
#include <nuttx/config.h>
#include <nuttx/fs/fs.h>
#include <nuttx/fs/ioctl.h>
#include <unistd.h>
#include <sched.h>
#include <assert.h>
#include <errno.h>
#include <fcntl.h>
#include "inode/inode.h"
@ -107,10 +110,25 @@ int file_dup2(FAR struct file *filep1, FAR struct file *filep2)
temp.f_priv = filep1->f_priv;
/* Add nonblock flags to avoid happening block when
* calling open()
*/
temp.f_oflags |= O_NONBLOCK;
if (inode->u.i_ops->open)
{
ret = inode->u.i_ops->open(&temp);
}
if (ret >= 0 && (filep1->f_oflags & O_NONBLOCK) == 0)
{
ret = file_ioctl(&temp, FIONBIO, 0);
if (ret < 0 && inode->u.i_ops->close)
{
ret = inode->u.i_ops->close(&temp);
}
}
}
/* Handle open failures */