From a2f2424ee8f95ec493fc5dfdca3e1eb5998ab148 Mon Sep 17 00:00:00 2001 From: felixlionardo Date: Wed, 19 Feb 2025 14:14:22 -0500 Subject: [PATCH] os: Add QNX support for wl_os_socket_peercred() This change introduces a QNX-specific implementation of wl_os_socket_peercred(), allowing Wayland to retrieve peer credentials on the QNX platform using LOCAL_PEERCRED. Signed-off-by: felixlionardo --- src/wayland-os.c | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/src/wayland-os.c b/src/wayland-os.c index f00ead4b..c34557aa 100644 --- a/src/wayland-os.c +++ b/src/wayland-os.c @@ -40,6 +40,11 @@ #include #endif +#if defined(__QNXNTO__) +#include +#include +#endif + #include "wayland-os.h" /* used by tests */ @@ -85,7 +90,31 @@ wl_os_socket_cloexec(int domain, int type, int protocol) return set_cloexec_or_close(fd); } -#if defined(__FreeBSD__) +#if defined(__QNXNTO__) +int +wl_os_socket_peercred(int sockfd, uid_t *uid, gid_t *gid, pid_t *pid) +{ + socklen_t len; + struct xucred ucred; + + len = sizeof(ucred); + if (getsockopt(sockfd, SOL_LOCAL, LOCAL_PEERCRED, &ucred, &len) < 0) { + if (errno != ENOTCONN) + return -1; + /* LOCAL_PEERCRED will report ENOTCONN for socketpair sockets */ + *pid = getpid(); + *uid = getuid(); + *gid = getgid(); + } else if (ucred.cr_version != XUCRED_VERSION) { + return -1; + } else { + *uid = ucred.cr_uid; + *gid = ucred.cr_gid; + *pid = ucred.cr_pid; + } + return 0; +} +#elif defined(__FreeBSD__) int wl_os_socket_peercred(int sockfd, uid_t *uid, gid_t *gid, pid_t *pid) {