mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 19:17:44 +00:00
LibCore: Open files with O_CLOEXEC by default
This changes Core::File::open() to specify O_CLOEXEC by default so that we don't leak file descriptors into child processes. The new behavior can be overriden by specifying OpenMode::KeepOnExec.
This commit is contained in:
parent
67ed580532
commit
fbfd0ed5ab
2 changed files with 3 additions and 0 deletions
|
@ -79,6 +79,8 @@ bool File::open_impl(OpenMode mode, mode_t permissions)
|
|||
flags |= O_TRUNC;
|
||||
if (has_flag(mode, OpenMode::MustBeNew))
|
||||
flags |= O_EXCL;
|
||||
if (!has_flag(mode, OpenMode::KeepOnExec))
|
||||
flags |= O_CLOEXEC;
|
||||
int fd = ::open(m_filename.characters(), flags, permissions);
|
||||
if (fd < 0) {
|
||||
set_error(errno);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue