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.
This commit is contained in:
Andreas Kling 2020-09-28 22:40:44 +02:00
parent 0930e2323b
commit b058852c62

View file

@ -245,11 +245,8 @@ int Process::do_exec(NonnullRefPtr<FileDescription> 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;