From a98712035c73dd119431efe3a953b4af84a554cd Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Fri, 3 Jul 2020 13:54:18 +0200 Subject: [PATCH] Kernel: Fix non-blocking write() blocking instead of short-writing If a partial write succeeded, we could then be in an unexpected state where the file description was non-blocking, but we could no longer write to it. Previously, the kernel would block in that state, but instead we now handle this as a proper short write and return the number of bytes we were able to write. Fixes #2645. --- Kernel/Process.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Kernel/Process.cpp b/Kernel/Process.cpp index 010188e3e6..d4b804cd93 100644 --- a/Kernel/Process.cpp +++ b/Kernel/Process.cpp @@ -1716,6 +1716,11 @@ ssize_t Process::do_write(FileDescription& description, const u8* data, int data dbg() << "while " << nwritten << " < " << size; #endif if (!description.can_write()) { + if (!description.is_blocking()) { + // Short write: We can no longer write to this non-blocking description. + ASSERT(nwritten > 0); + return nwritten; + } #ifdef IO_DEBUG dbg() << "block write on " << description.absolute_path(); #endif