Keep track of client's pid

This commit is contained in:
2026-06-04 01:29:04 +03:00
parent a1f00aa443
commit e4bbc31c7b
2 changed files with 11 additions and 0 deletions

View File

@@ -143,6 +143,7 @@ struct Client
bool has_epollout { false };
bool has_bigrequests { false };
CARD16 sequence { 0 };
BAN::Optional<uint32_t> pid;
BAN::Vector<uint8_t> input_buffer;
BAN::Vector<uint8_t> output_buffer;
BAN::HashSet<CARD32> objects;

View File

@@ -391,11 +391,21 @@ int main()
continue;
}
BAN::Optional<uint32_t> client_pid;
#ifdef SO_PEERCRED
ucred client_cred;
socklen_t client_cred_len = sizeof(client_cred);
if (getsockopt(client_sock, SOL_SOCKET, SO_PEERCRED, &client_cred, &client_cred_len) == 0)
client_pid = client_cred.pid;
#endif
MUST(g_epoll_thingies.insert(client_sock, {
.type = EpollThingy::Type::Client,
.value = Client {
.fd = client_sock,
.state = Client::State::ConnectionSetup,
.pid = client_pid,
}
}));