[libvirt] [PATCH] rpc: Retrieve peer PID via new getsockopt() for Mac

While LOCAL_PEERCRED on the BSDs does not return the pid information of the peer, Mac OS X 10.8 added LOCAL_PEERPID to retrieve the pid so we should use that when its available to get that information. --- src/rpc/virnetsocket.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/rpc/virnetsocket.c b/src/rpc/virnetsocket.c index e8cdfa6..09a0a12 100644 --- a/src/rpc/virnetsocket.c +++ b/src/rpc/virnetsocket.c @@ -1195,12 +1195,26 @@ int virNetSocketGetUNIXIdentity(virNetSocketPtr sock, return -1; } - /* PID and process creation time are not supported on BSDs */ + /* PID and process creation time are not supported on BSDs by + * LOCAL_PEERCRED. + */ *pid = -1; *timestamp = -1; *uid = cr.cr_uid; *gid = cr.cr_gid; +# ifdef LOCAL_PEERPID + /* Exists on Mac OS X 10.8 for retrieving the peer's PID */ + cr_len = sizeof(*pid); + + if (getsockopt(sock->fd, VIR_SOL_PEERCRED, LOCAL_PEERPID, pid, &cr_len) < 0) { + virReportSystemError(errno, "%s", + _("Failed to get client socket PID")); + virObjectUnlock(sock); + return -1; + } +# endif + virObjectUnlock(sock); return 0; } -- 1.8.1.5

Il 12/10/2013 19:21, Doug Goldstein ha scritto:
While LOCAL_PEERCRED on the BSDs does not return the pid information of the peer, Mac OS X 10.8 added LOCAL_PEERPID to retrieve the pid so we should use that when its available to get that information. --- src/rpc/virnetsocket.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-)
diff --git a/src/rpc/virnetsocket.c b/src/rpc/virnetsocket.c index e8cdfa6..09a0a12 100644 --- a/src/rpc/virnetsocket.c +++ b/src/rpc/virnetsocket.c @@ -1195,12 +1195,26 @@ int virNetSocketGetUNIXIdentity(virNetSocketPtr sock, return -1; }
- /* PID and process creation time are not supported on BSDs */ + /* PID and process creation time are not supported on BSDs by + * LOCAL_PEERCRED. + */ *pid = -1; *timestamp = -1; *uid = cr.cr_uid; *gid = cr.cr_gid;
+# ifdef LOCAL_PEERPID + /* Exists on Mac OS X 10.8 for retrieving the peer's PID */ + cr_len = sizeof(*pid); + + if (getsockopt(sock->fd, VIR_SOL_PEERCRED, LOCAL_PEERPID, pid, &cr_len) < 0) { + virReportSystemError(errno, "%s", + _("Failed to get client socket PID")); + virObjectUnlock(sock); + return -1; + } +# endif
I think a failure should not be fatal, so that you can compile on 10.8 and run on an older version. Paolo
virObjectUnlock(sock); return 0; }

On Sat, Oct 12, 2013 at 2:23 PM, Paolo Bonzini <pbonzini@redhat.com> wrote:
Il 12/10/2013 19:21, Doug Goldstein ha scritto:
While LOCAL_PEERCRED on the BSDs does not return the pid information of the peer, Mac OS X 10.8 added LOCAL_PEERPID to retrieve the pid so we should use that when its available to get that information. --- src/rpc/virnetsocket.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-)
diff --git a/src/rpc/virnetsocket.c b/src/rpc/virnetsocket.c index e8cdfa6..09a0a12 100644 --- a/src/rpc/virnetsocket.c +++ b/src/rpc/virnetsocket.c @@ -1195,12 +1195,26 @@ int virNetSocketGetUNIXIdentity(virNetSocketPtr sock, return -1; }
- /* PID and process creation time are not supported on BSDs */ + /* PID and process creation time are not supported on BSDs by + * LOCAL_PEERCRED. + */ *pid = -1; *timestamp = -1; *uid = cr.cr_uid; *gid = cr.cr_gid;
+# ifdef LOCAL_PEERPID + /* Exists on Mac OS X 10.8 for retrieving the peer's PID */ + cr_len = sizeof(*pid); + + if (getsockopt(sock->fd, VIR_SOL_PEERCRED, LOCAL_PEERPID, pid, &cr_len) < 0) { + virReportSystemError(errno, "%s", + _("Failed to get client socket PID")); + virObjectUnlock(sock); + return -1; + } +# endif
I think a failure should not be fatal, so that you can compile on 10.8 and run on an older version.
Paolo
Good point. I'll respin. -- Doug Goldstein
participants (2)
-
Doug Goldstein
-
Paolo Bonzini