diff options
author | Eric Seifert <seiferteric@gmail.com> | 2021-09-18 19:39:00 -0700 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-09-19 12:20:16 +0200 |
commit | edbc5489a8895f01e376a1fd2a76c961f72474a8 (patch) | |
tree | 2aab511eff7688998effc5213761b2517e6f4666 | |
parent | 2e079c6d69c62f35e7503bcb626d6e08870eddff (diff) | |
download | serenity-edbc5489a8895f01e376a1fd2a76c961f72474a8.zip |
Kernel: Add support for O_NONBLOCK in pipe syscall
While working on a port, I saw a pipe creation fail due to missing
nonblock support in pipe syscall.
-rw-r--r-- | Kernel/Syscalls/pipe.cpp | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/Kernel/Syscalls/pipe.cpp b/Kernel/Syscalls/pipe.cpp index 7e31850481..5363d3d7d2 100644 --- a/Kernel/Syscalls/pipe.cpp +++ b/Kernel/Syscalls/pipe.cpp @@ -15,8 +15,8 @@ KResultOr<FlatPtr> Process::sys$pipe(int pipefd[2], int flags) REQUIRE_PROMISE(stdio); if (fds().open_count() + 2 > fds().max_open()) return EMFILE; - // Reject flags other than O_CLOEXEC. - if ((flags & O_CLOEXEC) != flags) + // Reject flags other than O_CLOEXEC, O_NONBLOCK + if ((flags & (O_CLOEXEC | O_NONBLOCK)) != flags) return EINVAL; u32 fd_flags = (flags & O_CLOEXEC) ? FD_CLOEXEC : 0; @@ -30,6 +30,10 @@ KResultOr<FlatPtr> Process::sys$pipe(int pipefd[2], int flags) reader_description->set_readable(true); writer_description->set_writable(true); + if (flags & O_NONBLOCK) { + reader_description->set_blocking(false); + writer_description->set_blocking(false); + } m_fds[reader_fd_allocation.fd].set(move(reader_description), fd_flags); m_fds[writer_fd_allocation.fd].set(move(writer_description), fd_flags); |