Skip to content

Commit ad0ac5f

Browse files
fcntl: handle F_DUPFD
Signed-off-by: Andy-Python-Programmer <andypythonappdeveloper@gmail.com>
1 parent 5f0f244 commit ad0ac5f

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/aero_kernel/src/fs/file_table.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ impl FileTable {
242242
for (i, file) in array.iter_mut().enumerate() {
243243
if file.is_none() {
244244
*file = Some(handle.duplicate(i, flags)?);
245-
return Ok(i);
245+
return Ok(start + i);
246246
}
247247
}
248248

src/aero_kernel/src/syscall/fs.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,10 +339,19 @@ pub fn fcntl(fd: usize, command: usize, arg: usize) -> Result<usize, SyscallErro
339339
//
340340
// F_DUPFD_CLOEXEC additionally sets the close-on-exec flag for the duplicate
341341
// file descriptor.
342+
aero_syscall::prelude::F_DUPFD => scheduler::get_scheduler()
343+
.current_task()
344+
.file_table
345+
.duplicate(fd, DuplicateHint::GreatorOrEqual(arg), handle.flags),
346+
342347
aero_syscall::prelude::F_DUPFD_CLOEXEC => scheduler::get_scheduler()
343348
.current_task()
344349
.file_table
345-
.duplicate(fd, DuplicateHint::GreatorOrEqual(arg), OpenFlags::O_CLOEXEC),
350+
.duplicate(
351+
fd,
352+
DuplicateHint::GreatorOrEqual(arg),
353+
handle.flags | OpenFlags::O_CLOEXEC,
354+
),
346355

347356
// Get the value of file descriptor flags.
348357
aero_syscall::prelude::F_GETFD => {

0 commit comments

Comments
 (0)