vfs/dup: add nonblock flag to avoid happening block when dup
Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
This commit is contained in:
parent
9fdf36c17e
commit
f8991f7782
1 changed files with 18 additions and 0 deletions
|
@ -23,11 +23,14 @@
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include <nuttx/config.h>
|
#include <nuttx/config.h>
|
||||||
|
#include <nuttx/fs/fs.h>
|
||||||
|
#include <nuttx/fs/ioctl.h>
|
||||||
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <sched.h>
|
#include <sched.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
|
||||||
#include "inode/inode.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;
|
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)
|
if (inode->u.i_ops->open)
|
||||||
{
|
{
|
||||||
ret = inode->u.i_ops->open(&temp);
|
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 */
|
/* Handle open failures */
|
||||||
|
|
Loading…
Reference in a new issue