mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-04 05:20:30 +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
Notes:
sideshowbarker
2024-07-18 17:58:04 +09:00
Author: https://github.com/gunnarbeutner Commit: https://github.com/SerenityOS/serenity/commit/fbfd0ed5ab4 Pull-request: https://github.com/SerenityOS/serenity/pull/7173 Reviewed-by: https://github.com/awesomekling
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);
|
||||
|
|
|
@ -42,6 +42,7 @@ enum class OpenMode : unsigned {
|
|||
Append = 4,
|
||||
Truncate = 8,
|
||||
MustBeNew = 16,
|
||||
KeepOnExec = 32,
|
||||
};
|
||||
|
||||
enum class SeekMode {
|
||||
|
|
Loading…
Reference in a new issue