unix: receive pid on non-linux platforms
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Thu, 8 Jul 2021 21:57:45 +0000 (17:57 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Mon, 12 Jul 2021 21:38:52 +0000 (17:38 -0400)
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 <jeremie.galarneau@efficios.com>
Change-Id: I9c92f6dda6441deca58f9cc85f846f5031cceb6e

src/common/compat/socket.h
src/common/unix.c

index a510473c35fbdeb4e78e245b35732c7f52e1dca9..464678292b95eed68afa5cc2d9e0311bd6843b41 100644 (file)
@@ -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 <ucred.h>
 
 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);
index 023bff847273df004c537593cbbbceb012540681..12622e5dd03152a78ee492699539b7f86335f104 100644 (file)
@@ -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;
                }
This page took 0.02662 seconds and 4 git commands to generate.