summaryrefslogtreecommitdiff
path: root/mysys
diff options
context:
space:
mode:
authorDmitry Shulga <dmitry.shulga@mariadb.com>2023-03-16 16:25:57 +0700
committerDmitry Shulga <dmitry.shulga@mariadb.com>2023-03-16 16:25:57 +0700
commit1310b3a02fe6c5eb14d61adbe13453ee0ab966fa (patch)
tree2404a6230e818a78dea84bd4059103c2772b3c44 /mysys
parentd77aaa6994b30660bd8788d3415ae4a44f55d9a0 (diff)
downloadmariadb-git-1310b3a02fe6c5eb14d61adbe13453ee0ab966fa.tar.gz
MDEV-30811: Build issues on macOS 11.0
Building of MariaDB server version 11.0 and 11.1 fails on MacOS 12.x (Monterey). Build failure happened on generating header files from the error messages contained in the file errmsg-utf8.txt. This process is performed by the utility comp_err that crashes when it is run on MacOS Monterey. comp_err invokes my_init at the very beginning of start before initialization of thread environment done. While executing my_init the function my_readlink is called. my_readlink is wrapper around the system call readlink with extra errors handling. In case the system call readlink returns error the following block of code is run if (my_thread_var) my_errno= errno; my_thred_var is macros that expanded to invocation of my_pthread_getspecific() against supplied thread specific key THR_KEY_mysys. Unfortunately, the tsd key THR_KEY_mysys is initialized right after the call of my_init() so return value of pthread_getspecific is platform dependent. On Linux pthread_getspecific returns NULL if key is not a valid TSD key. On MacOS, the effect of calling pthread_getspecific() with a key value not obtained from pthread_key_create() is undefined. So, on MacOS pthread_getspecific() returns some invalid address where the errno value is written. It leads to a crash latter when the library API function pthread_self() is called. To fix the issue, initialization of thread environment is moved at very beginning of the main() function in order to run it as the first step to have full initiliazed environment at the moment when my_init() is ivoked.
Diffstat (limited to 'mysys')
-rw-r--r--mysys/my_init.c12
-rw-r--r--mysys/my_symlink.c4
2 files changed, 7 insertions, 9 deletions
diff --git a/mysys/my_init.c b/mysys/my_init.c
index 138b4697f97..73d767377b4 100644
--- a/mysys/my_init.c
+++ b/mysys/my_init.c
@@ -176,6 +176,12 @@ my_bool my_init(void)
mysql_stdin= & instrumented_stdin;
my_progname_short= "unknown";
+ /* Initialize our mutex handling */
+ my_mutex_init();
+
+ if (my_thread_global_init())
+ return 1;
+
if (my_progname)
{
char link_name[FN_REFLEN];
@@ -198,12 +204,6 @@ my_bool my_init(void)
}
}
- /* Initialize our mutex handling */
- my_mutex_init();
-
- if (my_thread_global_init())
- return 1;
-
#if defined(SAFEMALLOC) && !defined(DBUG_OFF)
dbug_sanity= sf_sanity;
#endif
diff --git a/mysys/my_symlink.c b/mysys/my_symlink.c
index e7833992f0d..a07f67a179f 100644
--- a/mysys/my_symlink.c
+++ b/mysys/my_symlink.c
@@ -54,10 +54,8 @@ int my_readlink(char *to, const char *filename, myf MyFlags)
if ((length=readlink(filename, to, FN_REFLEN-1)) < 0)
{
- if (my_thread_var)
- my_errno= errno;
/* Don't give an error if this wasn't a symlink */
- if (errno == EINVAL)
+ if ((my_errno=errno) == EINVAL)
{
result= 1;
strnmov(to, filename, FN_REFLEN);