unix: receive pid on non-linux platforms
[lttng-tools.git] / src / common / compat / socket.h
index 1b9989369a30132c1d44e1583b6751497f93a4cb..464678292b95eed68afa5cc2d9e0311bd6843b41 100644 (file)
@@ -28,7 +28,7 @@ ssize_t lttng_recvmsg_nosigpipe(int sockfd, struct msghdr *msg)
 #else
 
 #include <signal.h>
-#include <errno.h>
+#include <common/compat/errno.h>
 
 static inline
 ssize_t lttng_recvmsg_nosigpipe(int sockfd, struct msghdr *msg)
@@ -117,10 +117,15 @@ 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;
 
+#define LTTNG_SOCK_SET_UID_CRED(c, u) LTTNG_REF(c)->uid = u
+#define LTTNG_SOCK_SET_GID_CRED(c, g) LTTNG_REF(c)->gid = g
+#define LTTNG_SOCK_SET_PID_CRED(c, p)
+
 #define LTTNG_SOCK_GET_UID_CRED(c) LTTNG_REF(c)->uid
 #define LTTNG_SOCK_GET_GID_CRED(c) LTTNG_REF(c)->gid
 #define LTTNG_SOCK_GET_PID_CRED(c) -1
@@ -151,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;
@@ -172,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);
This page took 0.024848 seconds and 5 git commands to generate.