]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
conf: fix thread_local support detection
authorChristian Brauner <christian.brauner@ubuntu.com>
Mon, 29 Mar 2021 10:49:51 +0000 (12:49 +0200)
committerChristian Brauner <christian.brauner@ubuntu.com>
Mon, 29 Mar 2021 11:32:00 +0000 (13:32 +0200)
Our detection for TLS wasn't working. Fix it.

Fixes: https://github.com/lxc/lxd/issues/8327
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
configure.ac
src/lxc/compiler.h
src/lxc/conf.c
src/lxc/conf.h
src/lxc/initutils.c

index b329b4ea772a4a8eaefbfec4fc327e88fbba03e6..76f2e1026891b89df15842b95d2876f90f6d7536 100644 (file)
@@ -629,7 +629,7 @@ AC_CHECK_DECLS([PR_SET_NO_NEW_PRIVS], [], [], [#include <sys/prctl.h>])
 AC_CHECK_DECLS([PR_GET_NO_NEW_PRIVS], [], [], [#include <sys/prctl.h>])
 
 # Check for some headers
-AC_CHECK_HEADERS([pty.h sys/memfd.h sys/personality.h sys/resource.h sys/signalfd.h sys/timerfd.h utmpx.h])
+AC_CHECK_HEADERS([pty.h sys/memfd.h sys/personality.h sys/resource.h sys/signalfd.h sys/timerfd.h utmpx.h threads.h])
 
 AC_CHECK_HEADER([ifaddrs.h],
        AM_CONDITIONAL(HAVE_IFADDRS_H, true)
index 5d45955d0afa4ab6d1498e494351530edc5d81d1..353677a5e87c0eb6b81a6a8f17fc91642ba9b6e7 100644 (file)
 
 #include "config.h"
 
-#ifndef thread_local
-#if __STDC_VERSION__ >= 201112L &&    \
-    !(defined(__STDC_NO_THREADS__) || \
-      (defined(__GNU_LIBRARY__) && __GLIBC__ == 2 && __GLIBC_MINOR__ < 16))
-#define thread_local _Thread_local
+#if defined(HAVE_THREADS_H)
+       #include <threads.h>
+       #define THREAD_LOCAL_STORAGE_SUPPORTED
+#elif defined(thread_local)
+       #define THREAD_LOCAL_STORAGE_SUPPORTED
 #else
-#define thread_local __thread
-#endif
+       #if __STDC_VERSION__ >= 201112L &&    \
+           !(defined(__STDC_NO_THREADS__) || \
+             (defined(__GNU_LIBRARY__) && __GLIBC__ == 2 && __GLIBC_MINOR__ < 16))
+               #define thread_local _Thread_local
+
+               #define THREAD_LOCAL_STORAGE_SUPPORTED
+       #else
+               #define thread_local __thread
+
+               #define THREAD_LOCAL_STORAGE_SUPPORTED
+       #endif
 #endif
 
 #if __GNUC__ >= 7
index 5c133bbb16bbfd6e23d52ccc1a6f7384de299efd..bceb2cebc45975d0553bfa54d8978d4746899d63 100644 (file)
@@ -36,6 +36,7 @@
 #include "af_unix.h"
 #include "caps.h"
 #include "cgroups/cgroup.h"
+#include "compiler.h"
 #include "conf.h"
 #include "config.h"
 #include "confile.h"
 
 lxc_log_define(conf, lxc);
 
-/* The lxc_conf of the container currently being worked on in an API call.
+/*
+ * The lxc_conf of the container currently being worked on in an API call.
  * This is used in the error calls.
  */
-#ifdef HAVE_TLS
+#if defined(THREAD_LOCAL_STORAGE_SUPPORTED)
 thread_local struct lxc_conf *current_config;
+#elif defined(ENFORCE_THREAD_SAFETY)
+#error ENFORCE_THREAD_SAFETY was set but cannot be guaranteed due to missing TLS
 #else
 struct lxc_conf *current_config;
 #endif
index b93c65276b94b264087351820c1e89a2895d3b80..939e47d75cc9b75ade7a7961aa97a4a66f54aaa2 100644 (file)
@@ -474,10 +474,12 @@ struct lxc_conf {
 __hidden extern int write_id_mapping(enum idtype idtype, pid_t pid, const char *buf, size_t buf_size)
     __access_r(3, 4);
 
-#ifdef HAVE_TLS
+#if defined(THREAD_LOCAL_STORAGE_SUPPORTED)
 extern thread_local struct lxc_conf *current_config;
+#elif defined(ENFORCE_THREAD_SAFETY)
+#error ENFORCE_THREAD_SAFETY was set but cannot be guaranteed due to missing TLS
 #else
-extern struct lxc_conf *current_config;
+struct lxc_conf *current_config;
 #endif
 
 __hidden extern int run_lxc_hooks(const char *name, char *hook, struct lxc_conf *conf, char *argv[]);
index 4a0aa41db777a84f3067d7d0987105352c98967b..c6206bff54809dafb93903ec4c4944df5fe8ba76 100644 (file)
@@ -54,8 +54,10 @@ const char *lxc_global_config_value(const char *option_name)
        };
 
        /* placed in the thread local storage pool for non-bionic targets */
-#ifdef HAVE_TLS
+#if defined(THREAD_LOCAL_STORAGE_SUPPORTED)
        static thread_local const char *values[sizeof(options) / sizeof(options[0])] = {0};
+#elif defined(ENFORCE_THREAD_SAFETY)
+       #error ENFORCE_THREAD_SAFETY was set but cannot be guaranteed due to missing TLS
 #else
        static const char *values[sizeof(options) / sizeof(options[0])] = {0};
 #endif