Changeset View
Changeset View
Standalone View
Standalone View
head/graphics/wayland/files/patch-src_wayland-server.c
--- src/wayland-server.c.orig 2020-02-11 23:46:03 UTC | --- src/wayland-server.c.orig 2020-12-21 10:17:10 UTC | ||||
+++ src/wayland-server.c | +++ src/wayland-server.c | ||||
@@ -25,6 +25,8 @@ | @@ -25,6 +25,8 @@ | ||||
#define _GNU_SOURCE | #define _GNU_SOURCE | ||||
+#include "../config.h" | +#include "../config.h" | ||||
+ | + | ||||
#include <stdbool.h> | #include <stdbool.h> | ||||
#include <stdlib.h> | #include <stdlib.h> | ||||
#include <stdint.h> | #include <stdint.h> | ||||
@@ -44,6 +46,11 @@ | @@ -44,6 +46,15 @@ | ||||
#include <sys/file.h> | #include <sys/file.h> | ||||
#include <sys/stat.h> | #include <sys/stat.h> | ||||
+#ifdef HAVE_SYS_UCRED_H | +#ifdef HAVE_SYS_UCRED_H | ||||
+#include <sys/types.h> | +#include <sys/param.h> | ||||
+#include <sys/ucred.h> | +#include <sys/ucred.h> | ||||
+#ifndef SOL_LOCAL | |||||
+/* DragonFly or FreeBSD < 12.2 */ | |||||
+#define SOL_LOCAL 0 | |||||
+#endif | +#endif | ||||
+#endif | |||||
+ | + | ||||
#include "wayland-util.h" | #include "wayland-util.h" | ||||
#include "wayland-private.h" | #include "wayland-private.h" | ||||
#include "wayland-server-private.h" | #include "wayland-server-private.h" | ||||
@@ -79,7 +86,13 @@ struct wl_client { | @@ -79,7 +86,13 @@ struct wl_client { | ||||
struct wl_list link; | struct wl_list link; | ||||
struct wl_map objects; | struct wl_map objects; | ||||
struct wl_priv_signal destroy_signal; | struct wl_priv_signal destroy_signal; | ||||
+#ifdef HAVE_SYS_UCRED_H | +#ifdef HAVE_SYS_UCRED_H | ||||
+ /* FreeBSD */ | + /* FreeBSD */ | ||||
+ struct xucred xucred; | + struct xucred xucred; | ||||
+#else | +#else | ||||
+ /* Linux */ | + /* Linux */ | ||||
struct ucred ucred; | struct ucred ucred; | ||||
+#endif | +#endif | ||||
int error; | int error; | ||||
struct wl_priv_signal resource_created_signal; | struct wl_priv_signal resource_created_signal; | ||||
}; | }; | ||||
@@ -315,7 +328,13 @@ wl_resource_post_error(struct wl_resource *resource, | @@ -315,7 +328,17 @@ wl_resource_post_error(struct wl_resource *resource, | ||||
static void | static void | ||||
destroy_client_with_error(struct wl_client *client, const char *reason) | destroy_client_with_error(struct wl_client *client, const char *reason) | ||||
{ | { | ||||
+#ifdef HAVE_SYS_UCRED_H | +#ifdef HAVE_SYS_UCRED_H | ||||
+ /* FreeBSD */ | + /* FreeBSD */ | ||||
+#if defined(__FreeBSD__) && __FreeBSD_version >= 1300030 | |||||
+ wl_log("%s (pid %u)\n", reason, client->xucred.cr_pid); | |||||
+#else | |||||
+ wl_log("%s\n", reason); | + wl_log("%s\n", reason); | ||||
+#endif | |||||
+#else | +#else | ||||
+ /* Linux */ | + /* Linux */ | ||||
wl_log("%s (pid %u)\n", reason, client->ucred.pid); | wl_log("%s (pid %u)\n", reason, client->ucred.pid); | ||||
+#endif | +#endif | ||||
wl_client_destroy(client); | wl_client_destroy(client); | ||||
} | } | ||||
@@ -529,10 +548,20 @@ wl_client_create(struct wl_display *display, int fd) | @@ -529,10 +552,20 @@ wl_client_create(struct wl_display *display, int fd) | ||||
if (!client->source) | if (!client->source) | ||||
goto err_client; | goto err_client; | ||||
+#if defined(SO_PEERCRED) | +#if defined(SO_PEERCRED) | ||||
+ /* Linux */ | + /* Linux */ | ||||
len = sizeof client->ucred; | len = sizeof client->ucred; | ||||
if (getsockopt(fd, SOL_SOCKET, SO_PEERCRED, | if (getsockopt(fd, SOL_SOCKET, SO_PEERCRED, | ||||
&client->ucred, &len) < 0) | &client->ucred, &len) < 0) | ||||
goto err_source; | goto err_source; | ||||
+#elif defined(LOCAL_PEERCRED) | +#elif defined(LOCAL_PEERCRED) | ||||
+ /* FreeBSD */ | + /* FreeBSD */ | ||||
+ len = sizeof client->xucred; | + len = sizeof client->xucred; | ||||
+ if (getsockopt(fd, SOL_SOCKET, LOCAL_PEERCRED, | + if (getsockopt(fd, SOL_LOCAL, LOCAL_PEERCRED, | ||||
+ &client->xucred, &len) < 0 || | + &client->xucred, &len) < 0 || | ||||
+ client->xucred.cr_version != XUCRED_VERSION) | + client->xucred.cr_version != XUCRED_VERSION) | ||||
+ goto err_source; | + goto err_source; | ||||
+#endif | +#endif | ||||
client->connection = wl_connection_create(fd); | client->connection = wl_connection_create(fd); | ||||
if (client->connection == NULL) | if (client->connection == NULL) | ||||
@@ -586,12 +615,23 @@ WL_EXPORT void | @@ -586,12 +619,28 @@ WL_EXPORT void | ||||
wl_client_get_credentials(struct wl_client *client, | wl_client_get_credentials(struct wl_client *client, | ||||
pid_t *pid, uid_t *uid, gid_t *gid) | pid_t *pid, uid_t *uid, gid_t *gid) | ||||
{ | { | ||||
+#ifdef HAVE_SYS_UCRED_H | +#ifdef HAVE_SYS_UCRED_H | ||||
+ /* FreeBSD */ | + /* DragonFly or FreeBSD */ | ||||
if (pid) | if (pid) | ||||
+ *pid = 0; /* FIXME: not defined on FreeBSD */ | +#if defined(__FreeBSD__) && __FreeBSD_version >= 1300030 | ||||
+ /* Since https://cgit.freebsd.org/src/commit/?id=c5afec6e895a */ | |||||
+ *pid = client->xucred.cr_pid; | |||||
+#else | |||||
+ *pid = 0; | |||||
+#endif | |||||
+ if (uid) | + if (uid) | ||||
+ *uid = client->xucred.cr_uid; | + *uid = client->xucred.cr_uid; | ||||
+ if (gid) | + if (gid) | ||||
+ *gid = client->xucred.cr_gid; | + *gid = client->xucred.cr_gid; | ||||
+#else | +#else | ||||
+ /* Linux */ | + /* Linux */ | ||||
+ if (pid) | + if (pid) | ||||
*pid = client->ucred.pid; | *pid = client->ucred.pid; | ||||
if (uid) | if (uid) | ||||
*uid = client->ucred.uid; | *uid = client->ucred.uid; | ||||
if (gid) | if (gid) | ||||
*gid = client->ucred.gid; | *gid = client->ucred.gid; | ||||
+#endif | +#endif | ||||
} | } | ||||
/** Get the file descriptor for the client | /** Get the file descriptor for the client |