From b058852c62c3d1097e4cf2c8ecb90611c24a4353 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Mon, 28 Sep 2020 22:40:44 +0200 Subject: [PATCH] Kernel: Fix overly eager fd closing in sys$execve() When obeying FD_CLOEXEC, we don't need to explicitly call close() on all the FileDescriptions. We can just clear them out from the process fd table. ~FileDescription() will call close() anyway. This fixes an issue where TelnetServer would shut down accepted sockets when exec'ing a shell for them. Since the parent process still has the socket open, we should not force-close it. Just let go. --- Kernel/Syscalls/execve.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Kernel/Syscalls/execve.cpp b/Kernel/Syscalls/execve.cpp index ac8492745d..e398259238 100644 --- a/Kernel/Syscalls/execve.cpp +++ b/Kernel/Syscalls/execve.cpp @@ -245,11 +245,8 @@ int Process::do_exec(NonnullRefPtr main_program_description, Ve for (size_t i = 0; i < m_fds.size(); ++i) { auto& description_and_flags = m_fds[i]; - if (description_and_flags.description() && description_and_flags.flags() & FD_CLOEXEC) { - // FIXME: Should this error path be observed somehow? - (void)description_and_flags.description()->close(); + if (description_and_flags.description() && description_and_flags.flags() & FD_CLOEXEC) description_and_flags = {}; - } } new_main_thread = nullptr;