kernel+libc: Implement O_CLOEXEC

This commit is contained in:
apio 2023-03-24 21:19:24 +01:00
parent d48d0efb07
commit 374a9ff7b8
Signed by: apio
GPG Key ID: B8A7D06E42258954
3 changed files with 8 additions and 3 deletions

View File

@ -6,6 +6,7 @@
#include "thread/Scheduler.h" #include "thread/Scheduler.h"
#include "thread/ThreadImage.h" #include "thread/ThreadImage.h"
#include <bits/modes.h> #include <bits/modes.h>
#include <bits/open-flags.h>
#include <luna/CString.h> #include <luna/CString.h>
#include <luna/ScopeGuard.h> #include <luna/ScopeGuard.h>
#include <luna/Vector.h> #include <luna/Vector.h>
@ -76,8 +77,11 @@ Result<u64> sys_exec(Registers* regs, SyscallArgs args)
guard.deactivate(); guard.deactivate();
// FIXME: Close O_CLOEXEC file descriptors. for (int i = 0; i < FD_MAX; i++)
// for (int i = 0; i < FD_MAX; i++) { current->fd_table[i] = {}; } {
auto& descriptor = current->fd_table[i];
if (descriptor->flags & O_CLOEXEC) descriptor = {};
}
MMU::delete_userspace_page_directory(current->directory); MMU::delete_userspace_page_directory(current->directory);

View File

@ -7,7 +7,7 @@
#include <bits/open-flags.h> #include <bits/open-flags.h>
// These flags are needed after open(), the rest only affect open(). // These flags are needed after open(), the rest only affect open().
constexpr int FLAGS_TO_KEEP = O_RDWR | O_APPEND | O_NONBLOCK; constexpr int FLAGS_TO_KEEP = O_RDWR | O_APPEND | O_NONBLOCK | O_CLOEXEC;
Result<u64> sys_open(Registers*, SyscallArgs args) Result<u64> sys_open(Registers*, SyscallArgs args)
{ {

View File

@ -11,5 +11,6 @@
#define O_EXCL 16 #define O_EXCL 16
#define O_TRUNC 32 #define O_TRUNC 32
#define O_NONBLOCK 64 #define O_NONBLOCK 64
#define O_CLOEXEC 128
#endif #endif