From 1d033914885dc36b5bf2becf4281f482ac091f90 Mon Sep 17 00:00:00 2001 From: Sergey Bugaev Date: Sat, 10 Aug 2019 19:03:34 +0300 Subject: [PATCH] Net: Store an acceptor PID alongside the origin PID in a socket * The origin PID is the PID of the process that created this socket, either explicitly by calling socket(), or implicitly by accepting a TCP connection. Note that accepting a local socket connection does not create a new socket, it reuses the one connect() was called on, so for accepted local sockets the origin PID points to the connecting process. * The acceptor PID is the PID of the process that accept()ed this socket. For accepted TCP sockets, this is the same as origin PID. --- Kernel/Net/Socket.cpp | 1 + Kernel/Net/Socket.h | 2 ++ 2 files changed, 3 insertions(+) diff --git a/Kernel/Net/Socket.cpp b/Kernel/Net/Socket.cpp index 2229de18d2..5a28b660d8 100644 --- a/Kernel/Net/Socket.cpp +++ b/Kernel/Net/Socket.cpp @@ -63,6 +63,7 @@ RefPtr Socket::accept() #endif auto client = m_pending.take_first(); ASSERT(!client->is_connected()); + client->m_acceptor_pid = m_origin_pid; client->set_setup_state(SetupState::Completed); client->m_connected = true; client->m_role = Role::Accepted; diff --git a/Kernel/Net/Socket.h b/Kernel/Net/Socket.h index c10a085212..98a3d221f5 100644 --- a/Kernel/Net/Socket.h +++ b/Kernel/Net/Socket.h @@ -80,6 +80,7 @@ public: KResult getsockopt(int level, int option, void*, socklen_t*); pid_t origin_pid() const { return m_origin_pid; } + pid_t acceptor_pid() const { return m_acceptor_pid; } timeval receive_deadline() const { return m_receive_deadline; } timeval send_deadline() const { return m_send_deadline; } @@ -111,6 +112,7 @@ private: Lock m_lock { "Socket" }; pid_t m_origin_pid { 0 }; + pid_t m_acceptor_pid { 0 }; int m_domain { 0 }; int m_type { 0 }; int m_protocol { 0 };