mirror of
https://gitlab.freedesktop.org/wayland/wayland.git
synced 2026-03-22 05:34:12 -04:00
os: Add an implementation of wl_os_socket_peercred() for darwin
This adds an alternative implementation of wl_os_socket_peercred() using getpeereid(3) and LOCAL_PEERPID, similar to changes I recently made to xorg-server. Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu@apple.com>
This commit is contained in:
parent
83e9c9e117
commit
aa7c02ff80
2 changed files with 17 additions and 0 deletions
|
|
@ -40,6 +40,7 @@ endforeach
|
||||||
|
|
||||||
have_funcs = [
|
have_funcs = [
|
||||||
'accept4',
|
'accept4',
|
||||||
|
'getpeereid',
|
||||||
'mkostemp',
|
'mkostemp',
|
||||||
'posix_fallocate',
|
'posix_fallocate',
|
||||||
'prctl',
|
'prctl',
|
||||||
|
|
|
||||||
|
|
@ -115,6 +115,22 @@ wl_os_socket_peercred(int sockfd, uid_t *uid, gid_t *gid, pid_t *pid)
|
||||||
*pid = ucred.pid;
|
*pid = ucred.pid;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
#elif defined(HAVE_GETPEEREID) && defined(LOCAL_PEERPID)
|
||||||
|
int
|
||||||
|
wl_os_socket_peercred(int sockfd, uid_t *uid, gid_t *gid, pid_t *pid)
|
||||||
|
{
|
||||||
|
socklen_t len;
|
||||||
|
|
||||||
|
if (getpeereid(sockfd, uid, gid) != 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
len = sizeof(pid_t);
|
||||||
|
if (getsockopt(sockfd, SOL_LOCAL, LOCAL_PEERPID, pid, &len) != 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
#error "Don't know how to read ucred on this platform"
|
#error "Don't know how to read ucred on this platform"
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue