mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-10-20 21:19:19 +00:00
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.
This commit is contained in:
parent
160a70fe4f
commit
e24aec629d
@ -1197,12 +1197,36 @@ int virNetSocketGetUNIXIdentity(virNetSocketPtr sock,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 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;
|
*pid = -1;
|
||||||
*timestamp = -1;
|
*timestamp = -1;
|
||||||
*uid = cr.cr_uid;
|
*uid = cr.cr_uid;
|
||||||
*gid = cr.cr_gid;
|
*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) {
|
||||||
|
/* Ensure this is set to something sane as there are no guarantees
|
||||||
|
* as to what its set to now.
|
||||||
|
*/
|
||||||
|
*pid = -1;
|
||||||
|
|
||||||
|
/* If this was built on a system with LOCAL_PEERPID defined but
|
||||||
|
* the kernel doesn't support it we'll get back EOPNOTSUPP so
|
||||||
|
* treat all errors but EOPNOTSUPP as fatal
|
||||||
|
*/
|
||||||
|
if (errno != EOPNOTSUPP) {
|
||||||
|
virReportSystemError(errno, "%s",
|
||||||
|
_("Failed to get client socket PID"));
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
# endif
|
||||||
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
|
Loading…
Reference in New Issue
Block a user