diff --git a/meson.build b/meson.build index f469756f..3d94094b 100644 --- a/meson.build +++ b/meson.build @@ -40,6 +40,7 @@ endforeach have_funcs = [ 'accept4', + 'getpeereid', 'mkostemp', 'posix_fallocate', 'prctl', diff --git a/src/wayland-os.c b/src/wayland-os.c index a9066cae..6651c8ce 100644 --- a/src/wayland-os.c +++ b/src/wayland-os.c @@ -115,6 +115,22 @@ wl_os_socket_peercred(int sockfd, uid_t *uid, gid_t *gid, pid_t *pid) *pid = ucred.pid; 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 #error "Don't know how to read ucred on this platform" #endif