From: Jérémie Galarneau Date: Thu, 8 Jul 2021 21:57:45 +0000 (-0400) Subject: unix: receive pid on non-linux platforms X-Git-Tag: v2.13.0-rc3~12 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=bb17eb585257d944c7857d9400a4db247c49dcc1;p=lttng-tools.git unix: receive pid on non-linux platforms 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 --- 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; }