LibCore: Implement System::set_close_on_exec

This commit is contained in:
stasoid 2025-02-13 18:50:23 +05:00 committed by Andrew Kaster
commit 2abc792938
Notes: github-actions[bot] 2025-03-20 02:26:29 +00:00
8 changed files with 31 additions and 35 deletions

View file

@ -11,25 +11,11 @@
namespace IPC {
// FIXME: IPC::Files transferred over the wire are always set O_CLOEXEC during decoding.
// Perhaps we should add an option to IPC::File to allow the receiver to decide whether to
// make it O_CLOEXEC or not. Or an attribute in the .ipc file?
ErrorOr<void> File::clear_close_on_exec()
{
auto fd_flags = TRY(Core::System::fcntl(m_fd, F_GETFD));
fd_flags &= ~FD_CLOEXEC;
TRY(Core::System::fcntl(m_fd, F_SETFD, fd_flags));
return {};
}
template<>
ErrorOr<File> decode(Decoder& decoder)
{
auto file = TRY(decoder.files().try_dequeue());
auto fd = file.fd();
auto fd_flags = TRY(Core::System::fcntl(fd, F_GETFD));
TRY(Core::System::fcntl(fd, F_SETFD, fd_flags | FD_CLOEXEC));
TRY(Core::System::set_close_on_exec(file.fd(), true));
return file;
}