mirror of
https://github.com/apache/nuttx.git
synced 2026-05-23 23:28:29 +08:00
fs/vfs/fs_dup.c: before file_allocate should restore minfd if define FDCHECK
When we use fcntl for dup, an fd is directly passed. If we have opened FDCHECK. we need to restore this file descriptor.
open FDCHECK and test this:
`
int main(int ac, char **av)
{
int fd1= open("./1.txt", O_WRONLY | O_CREAT, 0666);
if (fd1 < 0)
{
printf("open err\n");
return fd1;
}
int fd2= open("./2.txt", O_WRONLY | O_CREAT, 0666);
if (fd2 < 0)
{
printf("open err\n");
close(fd1);
return fd2;
}
//close(fd2);
int fd3 = fcntl(fd1, F_DUPFD, fd2);
printf("fd3 = %d\n", fd3);
close(fd1);
close(fd3);
return 0;
}
`
Signed-off-by: zhangshoukui <zhangshoukui@xiaomi.com>
This commit is contained in:
committed by
Alan C. Assis
parent
54510c5f94
commit
f57a5a6802
@@ -63,6 +63,8 @@ int file_dup(FAR struct file *filep, int minfd, int flags)
|
||||
|
||||
#ifdef CONFIG_FDCHECK
|
||||
uint8_t f_tag_fdcheck; /* File owner fdcheck tag, init to 0 */
|
||||
|
||||
minfd = fdcheck_restore(minfd);
|
||||
#endif
|
||||
|
||||
fd2 = file_allocate(g_root_inode, 0, 0, NULL, minfd, true);
|
||||
|
||||
Reference in New Issue
Block a user