mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-30 00:31:14 +00:00
Kernel: Fix cloning file descriptions on fork
After a fork, the parent and the child are supposed to share the same file description. For example, modifying the current offset of a file description is visible in both of them.
This commit is contained in:
parent
2396b2ed70
commit
1606261c58
Notes:
sideshowbarker
2024-07-19 12:45:13 +09:00
Author: https://github.com/bugaevc Commit: https://github.com/SerenityOS/serenity/commit/1606261c585 Pull-request: https://github.com/SerenityOS/serenity/pull/434 Reviewed-by: https://github.com/awesomekling
|
@ -57,24 +57,6 @@ void FileDescription::set_socket_role(SocketRole role)
|
|||
socket()->attach(*this);
|
||||
}
|
||||
|
||||
NonnullRefPtr<FileDescription> FileDescription::clone()
|
||||
{
|
||||
RefPtr<FileDescription> description;
|
||||
if (is_fifo()) {
|
||||
description = fifo()->open_direction(m_fifo_direction);
|
||||
} else {
|
||||
description = FileDescription::create(m_file, m_socket_role);
|
||||
description->m_custody = m_custody;
|
||||
description->m_inode = m_inode;
|
||||
}
|
||||
ASSERT(description);
|
||||
description->m_current_offset = m_current_offset;
|
||||
description->m_is_blocking = m_is_blocking;
|
||||
description->m_should_append = m_should_append;
|
||||
description->m_file_flags = m_file_flags;
|
||||
return *description;
|
||||
}
|
||||
|
||||
KResult FileDescription::fstat(stat& buffer)
|
||||
{
|
||||
ASSERT(!is_fifo());
|
||||
|
|
|
@ -26,8 +26,6 @@ public:
|
|||
static NonnullRefPtr<FileDescription> create(File&, SocketRole = SocketRole::None);
|
||||
~FileDescription();
|
||||
|
||||
NonnullRefPtr<FileDescription> clone();
|
||||
|
||||
int close();
|
||||
|
||||
off_t seek(off_t, int whence);
|
||||
|
|
|
@ -624,8 +624,7 @@ Process::Process(String&& name, uid_t uid, gid_t gid, pid_t ppid, RingLevel ring
|
|||
#ifdef FORK_DEBUG
|
||||
dbgprintf("fork: cloning fd %u... (%p) istty? %u\n", i, fork_parent->m_fds[i].description.ptr(), fork_parent->m_fds[i].description->is_tty());
|
||||
#endif
|
||||
m_fds[i].description = fork_parent->m_fds[i].description->clone();
|
||||
m_fds[i].flags = fork_parent->m_fds[i].flags;
|
||||
m_fds[i] = fork_parent->m_fds[i];
|
||||
}
|
||||
} else {
|
||||
m_fds.resize(m_max_open_file_descriptors);
|
||||
|
|
Loading…
Reference in a new issue