1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 07:08:10 +00:00

LibIPC: Get client/server PIDs using getsockopt(SO_PEERCRED)

Instead of passing the PIDs back and forth in a handshake "Greet"
message, just use getsockopt(SO_PEERCRED) on both sides to get the same
information from the kernel.

This is a nice little simplification of the IPC protocol, although it
does not get rid of the handshake since we still have to pass the
"client ID" from the server to each client so they know how to refer
to themselves. This might not be necessary and we might be able to get
rid of this later on.
This commit is contained in:
Andreas Kling 2019-12-06 18:39:59 +01:00
parent 23e802518d
commit f93c0dc489
11 changed files with 27 additions and 20 deletions

View file

@ -39,12 +39,19 @@ public:
usleep(10000);
--retries;
}
ucred creds;
socklen_t creds_size = sizeof(creds);
if (getsockopt(m_connection->fd(), SOL_SOCKET, SO_PEERCRED, &creds, &creds_size) < 0) {
ASSERT_NOT_REACHED();
}
m_server_pid = creds.pid;
ASSERT(m_connection->is_connected());
}
virtual void handshake() = 0;
void set_server_pid(pid_t pid) { m_server_pid = pid; }
pid_t server_pid() const { return m_server_pid; }
void set_my_client_id(int id) { m_my_client_id = id; }
int my_client_id() const { return m_my_client_id; }