From 3d5fd9652f7ce3b79f778f057710a522816aa03d Mon Sep 17 00:00:00 2001
From: Sascha Wildner <saw@online.de>
Date: Sat, 16 Feb 2019 10:19:41 +0100
Subject: [PATCH] Fix up mysql80-{client,server}.

---
 databases/mysql80-server/Makefile.DragonFly   |  1 +
 .../patch-router_src_routing_src_connection.h | 11 +++++
 .../dragonfly/patch-sql_CMakeLists.txt        | 13 ++++++
 ...ps_platform_thread__attrs__api__freebsd.cc | 41 +++++++++++++++++++
 4 files changed, 66 insertions(+)
 create mode 100644 databases/mysql80-server/Makefile.DragonFly
 create mode 100644 databases/mysql80-server/dragonfly/patch-router_src_routing_src_connection.h
 create mode 100644 databases/mysql80-server/dragonfly/patch-sql_CMakeLists.txt
 create mode 100644 databases/mysql80-server/dragonfly/patch-sql_resourcegroups_platform_thread__attrs__api__freebsd.cc

diff --git a/databases/mysql80-server/Makefile.DragonFly b/databases/mysql80-server/Makefile.DragonFly
new file mode 100644
index 00000000000..c30ad23b623
--- /dev/null
+++ b/databases/mysql80-server/Makefile.DragonFly
@@ -0,0 +1 @@
+USES+=	alias
diff --git a/databases/mysql80-server/dragonfly/patch-router_src_routing_src_connection.h b/databases/mysql80-server/dragonfly/patch-router_src_routing_src_connection.h
new file mode 100644
index 00000000000..d562201227b
--- /dev/null
+++ b/databases/mysql80-server/dragonfly/patch-router_src_routing_src_connection.h
@@ -0,0 +1,11 @@
+--- router/src/routing/src/connection.h~	2018-12-20 21:14:03.000000000 +0100
++++ router/src/routing/src/connection.h	2019-02-16 08:46:29.295005000 +0100
+@@ -38,6 +38,8 @@
+ class MySQLRouting;
+ class MySQLRoutingContext;
+ 
++#include <sys/socket.h>	/* XXX hack to get at struct sockaddr_storage */
++
+ namespace mysql_harness {
+ class PluginFuncEnv;
+ }
diff --git a/databases/mysql80-server/dragonfly/patch-sql_CMakeLists.txt b/databases/mysql80-server/dragonfly/patch-sql_CMakeLists.txt
new file mode 100644
index 00000000000..4fc8f095f08
--- /dev/null
+++ b/databases/mysql80-server/dragonfly/patch-sql_CMakeLists.txt
@@ -0,0 +1,13 @@
+--- sql/CMakeLists.txt~	2018-12-20 21:14:03.000000000 +0100
++++ sql/CMakeLists.txt	2019-02-14 10:05:34.467372000 +0100
+@@ -543,6 +543,10 @@ IF(CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
+   LIST(APPEND SQL_SHARED_SOURCES resourcegroups/platform/thread_attrs_api_freebsd.cc)
+ ENDIF()
+ 
++IF(CMAKE_SYSTEM_NAME MATCHES "DragonFly")
++  LIST(APPEND SQL_SHARED_SOURCES resourcegroups/platform/thread_attrs_api_freebsd.cc)
++ENDIF()
++
+ IF(CMAKE_SYSTEM_NAME MATCHES "SunOS")
+   LIST(APPEND SQL_SHARED_SOURCES resourcegroups/platform/thread_attrs_api_solaris.cc)
+ ENDIF()
diff --git a/databases/mysql80-server/dragonfly/patch-sql_resourcegroups_platform_thread__attrs__api__freebsd.cc b/databases/mysql80-server/dragonfly/patch-sql_resourcegroups_platform_thread__attrs__api__freebsd.cc
new file mode 100644
index 00000000000..9e70790b0b7
--- /dev/null
+++ b/databases/mysql80-server/dragonfly/patch-sql_resourcegroups_platform_thread__attrs__api__freebsd.cc
@@ -0,0 +1,41 @@
+--- sql/resourcegroups/platform/thread_attrs_api_freebsd.cc.orig	2018-12-20 21:14:03.000000000 +0100
++++ sql/resourcegroups/platform/thread_attrs_api_freebsd.cc	2019-02-15 18:07:12.094634000 +0100
+@@ -22,7 +22,7 @@
+ #include "thread_attrs_api.h"
+ 
+ #include <errno.h>
+-#include <sys/cpuset.h>
++#include <sys/lwp.h>
+ #include <sys/resource.h>
+ #include <sys/sysctl.h>
+ #include <sys/time.h>
+@@ -48,8 +48,7 @@ bool bind_to_cpu(cpu_id_t cpu_id, my_thr
+ 
+   CPU_ZERO(&cpu_set);
+   CPU_SET(cpu_id, &cpu_set);
+-  if (cpuset_setaffinity(CPU_LEVEL_WHICH, CPU_WHICH_TID, thread_id,
+-                         sizeof(cpu_set), &cpu_set) == -1) {
++  if (lwp_setaffinity(getpid(), thread_id, &cpu_set) == -1) {
+     char errbuf[MYSQL_ERRMSG_SIZE];
+     LogErr(ERROR_LEVEL, ER_RES_GRP_SET_THR_AFFINITY_FAILED, thread_id, cpu_id,
+            my_errno(), my_strerror(errbuf, MYSQL_ERRMSG_SIZE, my_errno()));
+@@ -73,8 +72,7 @@ bool bind_to_cpus(const std::vector<cpu_
+   CPU_ZERO(&cpu_set);
+   for (const auto &cpu_id : cpu_ids) CPU_SET(cpu_id, &cpu_set);
+ 
+-  if (cpuset_setaffinity(CPU_LEVEL_WHICH, CPU_WHICH_TID, thread_id,
+-                         sizeof(cpu_set), &cpu_set) == -1) {
++  if (lwp_setaffinity(getpid(), thread_id, &cpu_set) == -1) {
+     char errbuf[MYSQL_ERRMSG_SIZE];
+     LogErr(ERROR_LEVEL, ER_RES_GRP_SET_THR_AFFINITY_FAILED, thread_id,
+            my_errno(), my_strerror(errbuf, MYSQL_ERRMSG_SIZE, my_errno()));
+@@ -100,8 +98,7 @@ bool unbind_thread(my_thread_os_id_t thr
+   }
+   for (cpu_id_t cpu_id = 0; cpu_id < num_cpus; ++cpu_id)
+     CPU_SET(cpu_id, &cpu_set);
+-  if (cpuset_setaffinity(CPU_LEVEL_WHICH, CPU_WHICH_TID, thread_id,
+-                         sizeof(cpu_set), &cpu_set) == -1) {
++  if (lwp_setaffinity(getpid(), thread_id, &cpu_set) == -1) {
+     char errbuf[MYSQL_ERRMSG_SIZE];
+     LogErr(ERROR_LEVEL, ER_RES_GRP_THD_UNBIND_FROM_CPU_FAILED, thread_id,
+            my_errno(), my_strerror(errbuf, MYSQL_ERRMSG_SIZE, my_errno()));
-- 
2.20.1

