From bb17eb585257d944c7857d9400a4db247c49dcc1 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Thu, 8 Jul 2021 17:57:45 -0400 Subject: [PATCH] unix: receive pid on non-linux platforms MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Add a `pid` to the lttng_sock_cred structure definition used on non-Linux platforms and receive the peer's PID when receiving credentials. Signed-off-by: Jérémie Galarneau Change-Id: I9c92f6dda6441deca58f9cc85f846f5031cceb6e --- src/common/compat/socket.h | 10 +++++++++- src/common/unix.c | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/common/compat/socket.h b/src/common/compat/socket.h index a510473c3..464678292 100644 --- a/src/common/compat/socket.h +++ b/src/common/compat/socket.h @@ -117,6 +117,7 @@ typedef struct ucred lttng_sock_cred; struct lttng_sock_cred { uid_t uid; gid_t gid; + pid_t pid; }; typedef struct lttng_sock_cred lttng_sock_cred; @@ -155,7 +156,7 @@ typedef struct lttng_sock_cred lttng_sock_cred; #include static inline -int getpeereid(int s, uid_t *euid, gid_t *gid) +int getpeereid(int s, uid_t *euid, gid_t *gid, pid_t *pid) { int ret = 0; ucred_t *ucred = NULL; @@ -176,6 +177,13 @@ int getpeereid(int s, uid_t *euid, gid_t *gid) goto free; } *gid = ret; + + ret = ucred_getpid(ucred); + if (ret == -1) { + goto free; + } + *pid = ret; + ret = 0; free: ucred_free(ucred); diff --git a/src/common/unix.c b/src/common/unix.c index 023bff847..12622e5dd 100644 --- a/src/common/unix.c +++ b/src/common/unix.c @@ -1133,7 +1133,7 @@ ssize_t lttcomm_recv_creds_unix_sock(int sock, void *buf, size_t len, { int peer_ret; - peer_ret = getpeereid(sock, &creds->uid, &creds->gid); + peer_ret = getpeereid(sock, &creds->uid, &creds->gid, &creds->pid); if (peer_ret != 0) { return peer_ret; } -- 2.34.1