Few patches from Ravenports for DragonFly BSD support

Submitted by Leonid Bobrov on Jan. 20, 2019, 5:59 a.m.

Details

Message ID 20190120055926.GA68485@leo.lan
State New
Series "Few patches from Ravenports for DragonFly BSD support"
Headers show

Commit Message

Leonid Bobrov Jan. 20, 2019, 5:59 a.m.
From 660f1a59a0ff09f1c21e97087b713d6751e3de10 Mon Sep 17 00:00:00 2001
From: Leonid Bobrov <mazocomp@disroot.org>
Date: Sun, 20 Jan 2019 07:33:46 +0200
Subject: [PATCH] Few patches from Ravenports for DragonFly BSD support

Taken from https://github.com/jrmarino/ravensource/tree/master/bucket_D7/wayland/patches
---
 cursor/wayland-cursor.c |  4 ++++
 src/scanner.c           |  2 +-
 src/wayland-server.c    | 34 +++++++++++++++++++++++++++++++---
 src/wayland-util.c      |  1 +
 tests/test-compositor.c | 26 ++++++++++++++++++++++++--
 tests/test-runner.c     | 33 +++++++++++++++++++++++++++++++++
 6 files changed, 94 insertions(+), 6 deletions(-)

Patch hide | download patch | download mbox

diff --git a/cursor/wayland-cursor.c b/cursor/wayland-cursor.c
index d40c5c8..51f9266 100644
--- a/cursor/wayland-cursor.c
+++ b/cursor/wayland-cursor.c
@@ -98,7 +98,11 @@  shm_pool_resize(struct shm_pool *pool, int size)
 
 	pool->data = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED,
 			  pool->fd, 0);
+#if defined(__DragonFly__)
+	if (pool->data == MAP_FAILED)
+#else
 	if (pool->data == (void *)-1)
+#endif
 		return 0;
 	pool->size = size;
 
diff --git a/src/scanner.c b/src/scanner.c
index a94be5d..ac07473 100644
--- a/src/scanner.c
+++ b/src/scanner.c
@@ -1956,7 +1956,7 @@  int main(int argc, char *argv[])
 		buf = XML_GetBuffer(ctx.parser, XML_BUFFER_SIZE);
 		len = fread(buf, 1, XML_BUFFER_SIZE, input);
 		if (len < 0) {
-			fprintf(stderr, "fread: %m\n");
+			fprintf(stderr, "fread: %s\n", strerror(errno));
 			fclose(input);
 			exit(EXIT_FAILURE);
 		}
diff --git a/src/wayland-server.c b/src/wayland-server.c
index eae8d2e..cc6229f 100644
--- a/src/wayland-server.c
+++ b/src/wayland-server.c
@@ -43,6 +43,13 @@ 
 #include <sys/file.h>
 #include <sys/stat.h>
 
+#include "../config.h"
+
+#ifdef HAVE_SYS_UCRED_H
+#include <sys/types.h>
+#include <sys/ucred.h>
+#endif
+
 #include "wayland-util.h"
 #include "wayland-private.h"
 #include "wayland-server.h"
@@ -77,7 +84,11 @@  struct wl_client {
 	struct wl_list link;
 	struct wl_map objects;
 	struct wl_priv_signal destroy_signal;
+#ifdef HAVE_SYS_UCRED_H
+	struct xucred xucred;
+#else
 	struct ucred ucred;
+#endif
 	int error;
 	struct wl_priv_signal resource_created_signal;
 };
@@ -303,7 +314,11 @@  wl_resource_post_error(struct wl_resource *resource,
 static void
 destroy_client_with_error(struct wl_client *client, const char *reason)
 {
+#ifdef HAVE_SYS_UCRED_H
+	wl_log("%s (uid %u)\n", reason, client->xucred.cr_uid);
+#else
 	wl_log("%s (pid %u)\n", reason, client->ucred.pid);
+#endif
 	wl_client_destroy(client);
 }
 
@@ -502,7 +517,9 @@  WL_EXPORT struct wl_client *
 wl_client_create(struct wl_display *display, int fd)
 {
 	struct wl_client *client;
+#ifndef HAVE_SYS_UCRED_H
 	socklen_t len;
+#endif
 
 	client = zalloc(sizeof *client);
 	if (client == NULL)
@@ -517,10 +534,12 @@  wl_client_create(struct wl_display *display, int fd)
 	if (!client->source)
 		goto err_client;
 
+#ifndef HAVE_SYS_UCRED_H
 	len = sizeof client->ucred;
 	if (getsockopt(fd, SOL_SOCKET, SO_PEERCRED,
 		       &client->ucred, &len) < 0)
 		goto err_source;
+#endif
 
 	client->connection = wl_connection_create(fd);
 	if (client->connection == NULL)
@@ -574,12 +593,21 @@  WL_EXPORT void
 wl_client_get_credentials(struct wl_client *client,
 			  pid_t *pid, uid_t *uid, gid_t *gid)
 {
+#ifdef HAVE_SYS_UCRED_H
+	if (pid)
+		*pid = 0;
+	if (uid)
+		*uid = client->xucred.cr_uid;
+	if (gid)
+		*gid = client->xucred.cr_gid;
+#else
 	if (pid)
 		*pid = client->ucred.pid;
 	if (uid)
 		*uid = client->ucred.uid;
 	if (gid)
 		*gid = client->ucred.gid;
+#endif
 }
 
 /** Get the file descriptor for the client
@@ -1329,7 +1357,7 @@  socket_data(int fd, uint32_t mask, void *data)
 	client_fd = wl_os_accept_cloexec(fd, (struct sockaddr *) &name,
 					 &length);
 	if (client_fd < 0)
-		wl_log("failed to accept: %m\n");
+		wl_log("failed to accept: %s\n", strerror(errno));
 	else
 		if (!wl_client_create(display, client_fd))
 			close(client_fd);
@@ -1434,12 +1462,12 @@  _wl_display_add_socket(struct wl_display *display, struct wl_socket *s)
 
 	size = offsetof (struct sockaddr_un, sun_path) + strlen(s->addr.sun_path);
 	if (bind(s->fd, (struct sockaddr *) &s->addr, size) < 0) {
-		wl_log("bind() failed with error: %m\n");
+		wl_log("bind() failed with error: %s\n", strerror(errno));
 		return -1;
 	}
 
 	if (listen(s->fd, 128) < 0) {
-		wl_log("listen() failed with error: %m\n");
+		wl_log("listen() failed with error: %s\n", strerror(errno));
 		return -1;
 	}
 
diff --git a/src/wayland-util.c b/src/wayland-util.c
index 3a471a8..41ef323 100644
--- a/src/wayland-util.c
+++ b/src/wayland-util.c
@@ -29,6 +29,7 @@ 
 #include <stdio.h>
 #include <string.h>
 #include <stdarg.h>
+#include <pthread.h>
 
 #include "wayland-util.h"
 #include "wayland-private.h"
diff --git a/tests/test-compositor.c b/tests/test-compositor.c
index 72f6351..07b2a44 100644
--- a/tests/test-compositor.c
+++ b/tests/test-compositor.c
@@ -97,12 +97,33 @@  handle_client_destroy(void *data)
 {
 	struct client_info *ci = data;
 	struct display *d;
-	siginfo_t status;
+#ifdef __DragonFly__
+	int status;
+#else
+ 	siginfo_t status;
+#endif
 
 	d = ci->display;
 
-	assert(waitid(P_PID, ci->pid, &status, WEXITED) != -1);
+#ifdef __DragonFly__
+	assert(waitpid(ci->pid, &status, 0) != -1);
+#else
+ 	assert(waitid(P_PID, ci->pid, &status, WEXITED) != -1);
+#endif
 
+#ifdef __DragonFly__
+	if (WIFEXITED(status)) {
+		if (WEXITSTATUS(status) != EXIT_SUCCESS)
+			fprintf(stderr, "Client '%s' exited with code %d\n",
+				ci->name, WEXITSTATUS(status));
+
+		ci->exit_code = WEXITSTATUS(status);
+	} else if (WIFSIGNALED(status) || WCOREDUMP(status)) {
+		fprintf(stderr, "Client '%s' was killed by signal %d\n",
+			ci->name, WTERMSIG(status));
+		ci->exit_code = WEXITSTATUS(status);
+	}
+#else
 	switch (status.si_code) {
 	case CLD_KILLED:
 	case CLD_DUMPED:
@@ -118,6 +139,7 @@  handle_client_destroy(void *data)
 		ci->exit_code = status.si_status;
 		break;
 	}
+#endif
 
 	++d->clients_terminated_no;
 	if (d->clients_no == d->clients_terminated_no) {
diff --git a/tests/test-runner.c b/tests/test-runner.c
index 1487dc4..aa0aef6 100644
--- a/tests/test-runner.c
+++ b/tests/test-runner.c
@@ -28,6 +28,7 @@ 
 #include <unistd.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <signal.h>
 #include <sys/types.h>
 #include <sys/wait.h>
 #include <sys/stat.h>
@@ -37,7 +38,9 @@ 
 #include <errno.h>
 #include <limits.h>
 #include <sys/ptrace.h>
+#ifndef __DragonFly__
 #include <sys/prctl.h>
+#endif
 #ifndef PR_SET_PTRACER
 # define PR_SET_PTRACER 0x59616d61
 #endif
@@ -255,17 +258,22 @@  is_debugger_attached(void)
 		close(pipefd[0]);
 		if (buf == '-')
 			_exit(1);
+#ifndef __DragonFly__
 		if (ptrace(PTRACE_ATTACH, ppid, NULL, NULL) != 0)
 			_exit(1);
+#endif
 		if (!waitpid(-1, NULL, 0))
 			_exit(1);
+#ifndef __DragonFly__
 		ptrace(PTRACE_CONT, NULL, NULL);
 		ptrace(PTRACE_DETACH, ppid, NULL, NULL);
+#endif
 		_exit(0);
 	} else {
 		close(pipefd[0]);
 
 		/* Enable child to ptrace the parent process */
+#ifndef __DragonFly__
 		rc = prctl(PR_SET_PTRACER, pid);
 		if (rc != 0 && errno != EINVAL) {
 			/* An error prevents us from telling if a debugger is attached.
@@ -279,6 +287,7 @@  is_debugger_attached(void)
 			/* Signal to client that parent is ready by passing '+' */
 			write(pipefd[1], "+", 1);
 		}
+#endif
 		close(pipefd[1]);
 
 		waitpid(pid, &status, 0);
@@ -293,7 +302,11 @@  int main(int argc, char *argv[])
 	const struct test *t;
 	pid_t pid;
 	int total, pass;
+#ifdef __DragonFly__
+	int status;
+#else
 	siginfo_t info;
+#endif
 
 	if (isatty(fileno(stderr)))
 		is_atty = 1;
@@ -336,6 +349,12 @@  int main(int argc, char *argv[])
 		if (pid == 0)
 			run_test(t); /* never returns */
 
+#ifdef __DragonFly__
+		if (wait(&status)) {
+			fprintf(stderr, "waitid failed: %m\n");
+			abort();
+		}
+#else
 		if (waitid(P_PID, pid, &info, WEXITED)) {
 			stderr_set_color(RED);
 			fprintf(stderr, "waitid failed: %m\n");
@@ -343,7 +362,20 @@  int main(int argc, char *argv[])
 
 			abort();
 		}
+#endif
 
+		fprintf(stderr, "test \"%s\":\t", t->name);
+#ifdef __DragonFly__
+		if (WIFEXITED(status)) {
+			fprintf(stderr, "exit status %d", WEXITSTATUS(status));
+			if (WEXITSTATUS(status) == EXIT_SUCCESS)
+				success = 1;
+			break;
+		} else if (WIFSIGNALED(status) || WCOREDUMP(status)) {
+			fprintf(stderr, "signal %d", WTERMSIG(status));
+			break;
+		}
+#else
 		switch (info.si_code) {
 		case CLD_EXITED:
 			if (info.si_status == EXIT_SUCCESS)
@@ -367,6 +399,7 @@  int main(int argc, char *argv[])
 
 			break;
 		}
+#endif
 
 		if (success) {
 			pass++;

Comments

Pekka Paalanen Jan. 24, 2019, 10:53 a.m.
On Sun, 20 Jan 2019 07:59:26 +0200
Leonid Bobrov <mazocomp@disroot.org> wrote:

> From 660f1a59a0ff09f1c21e97087b713d6751e3de10 Mon Sep 17 00:00:00 2001
> From: Leonid Bobrov <mazocomp@disroot.org>
> Date: Sun, 20 Jan 2019 07:33:46 +0200
> Subject: [PATCH] Few patches from Ravenports for DragonFly BSD support
> 
> Taken from https://github.com/jrmarino/ravensource/tree/master/bucket_D7/wayland/patches
> ---
>  cursor/wayland-cursor.c |  4 ++++
>  src/scanner.c           |  2 +-
>  src/wayland-server.c    | 34 +++++++++++++++++++++++++++++++---
>  src/wayland-util.c      |  1 +
>  tests/test-compositor.c | 26 ++++++++++++++++++++++++--
>  tests/test-runner.c     | 33 +++++++++++++++++++++++++++++++++
>  6 files changed, 94 insertions(+), 6 deletions(-)

Hi,

you need to split this into logical patches, each patch doing one
logical thing. It is not the same as one patch per file. Each patch
needs to have a commit message explaining why the patch was written,
and so on. Please, see
https://gitlab.freedesktop.org/wayland/wayland/blob/master/CONTRIBUTING.md

As for merging, I think I saw some bits that don't actually need any
#ifdef BSD guards but would be good fixes regardless of the OS. Patches
that do not depend on a specific OS I think we can land without having
a BSD in CI, but patches that depend on being built on a BSD should
come with CI. I won't personally have the time to figure out how to run
a BSD in Gitlab CI, someone else needs to write the patch.

It would also be good to instead of hardcoding things like
#if Dragonfly /* no mremap */ to have autoconf test for the existence of
mremap, since the fallback to munmap+mmap seems quite generic.


Thanks,
pq
Leonid Bobrov Jan. 24, 2019, 1:31 p.m.
On Thu, Jan 24, 2019 at 12:53:28PM +0200, Pekka Paalanen wrote:
> Hi,
> 
> you need to split this into logical patches, each patch doing one
> logical thing. It is not the same as one patch per file. Each patch
> needs to have a commit message explaining why the patch was written,
> and so on. Please, see
> https://gitlab.freedesktop.org/wayland/wayland/blob/master/CONTRIBUTING.md
> 

Ok.

> As for merging, I think I saw some bits that don't actually need any
> #ifdef BSD guards but would be good fixes regardless of the OS. Patches
> that do not depend on a specific OS I think we can land without having
> a BSD in CI, but patches that depend on being built on a BSD should
> come with CI. I won't personally have the time to figure out how to run
> a BSD in Gitlab CI, someone else needs to write the patch.
> 
> It would also be good to instead of hardcoding things like
> #if Dragonfly /* no mremap */ to have autoconf test for the existence of
> mremap, since the fallback to munmap+mmap seems quite generic.
> 

Ok, I'll resend after Gitlab CI will be set up.

Meanwhile I'll make sure this patch gets to Ravenports:
https://github.com/mazocomp/openbsd-wip/blob/master/graphics/wayland/patches/patch-src_wayland-shm_c#L43

> 
> Thanks,
> pq