]> git.proxmox.com Git - mirror_lxc.git/commitdiff
build: support thread-safety enforcement as option
authorChristian Brauner <brauner@kernel.org>
Mon, 13 Jun 2022 11:46:15 +0000 (13:46 +0200)
committerChristian Brauner (Microsoft) <christian.brauner@ubuntu.com>
Mon, 13 Jun 2022 13:33:31 +0000 (15:33 +0200)
Signed-off-by: Christian Brauner (Microsoft) <christian.brauner@ubuntu.com>
meson.build
meson_options.txt
src/lxc/log.h
src/tests/oss-fuzz.sh

index ace66c0c8b75e562b675e9889fe0bea2a6ccb849..65058e1eefb51307d81ebeff9bc6316c781ccbcd 100644 (file)
@@ -148,6 +148,7 @@ want_openssl = get_option('openssl')
 want_selinux = get_option('selinux')
 want_oss_fuzz = get_option('oss-fuzz')
 want_seccomp = get_option('seccomp')
+want_thread_safety = get_option('thread-safety')
 
 srcconf.set_quoted('DEFAULT_CGROUP_PATTERN', cgrouppattern)
 if coverity
@@ -403,6 +404,8 @@ if want_oss_fuzz
     fuzzing_engine = meson.get_compiler('cpp').find_library('FuzzingEngine')
 endif
 
+srcconf.set10('ENFORCE_THREAD_SAFETY', want_thread_safety)
+
 ## PAM.
 pam = cc.find_library('pam', has_headers: 'security/pam_modules.h', required: want_pam_cgroup)
 srcconf.set10('HAVE_PAM', pam.found())
@@ -415,6 +418,28 @@ srcconf.set10('HAVE_STRCHRNUL', have)
 have = cc.has_function('openpty', prefix: '#include <pty.h>', args: '-D_GNU_SOURCE')
 srcconf.set10('HAVE_OPENPTY', have)
 
+have_func_strerror_r = cc.has_function('strerror_r', prefix: '#include <string.h>', args: '-D_GNU_SOURCE')
+srcconf.set10('HAVE_STRERROR_R', have)
+
+have_func_strerror_r_char_p = false
+
+if have_func_strerror_r
+    code = '''
+#define _GNU_SOURCE
+#include <string.h>
+int func (void) {
+    char error_string[256];
+    char *ptr = strerror_r (-2, error_string, 256);
+    char c = *strerror_r (-2, error_string, 256);
+    return c != 0 && ptr != (void*) 0L;
+}
+'''
+
+have_func_strerror_r_char_p = cc.compiles(code, name : 'strerror_r() returns char *')
+endif
+
+srcconf.set10('STRERROR_R_CHAR_P', have_func_strerror_r_char_p)
+
 ## Compiler attributes.
 foreach ccattr: [
     'fallthrough',
@@ -435,6 +460,7 @@ foreach tuple: [
     ['execveat'],
     ['faccessat'],
     ['strchrnul'],
+    ['strerror_r'],
     ['fgetln'],
     ['fsconfig'],
     ['fsmount'],
index 807a6ebec226aa4ee0e127d40173bf692181bdba..4a2da223cc4ccde62997903296d7fe1d420595a8 100644 (file)
@@ -77,3 +77,6 @@ option('usernet-db-path', type: 'string', value: 'lxc/nics',
 
 option('oss-fuzz', type : 'boolean', value : 'false',
        description : 'build against oss-fuzz')
+
+option('thread-safety', type : 'boolean', value : 'true',
+       description : 'whether the build fails when thread-safe logging cannot be guaranteed')
index 6cee31886c487c2526ec4ada6c875a5670ca9716..554a2e1d483a74d67b9f347febac0af1fc4b46b3 100644 (file)
@@ -304,12 +304,10 @@ __lxc_unused static inline void LXC_##LEVEL(struct lxc_log_locinfo* locinfo,      \
  * Helper macro to define errno string.
  */
 #if HAVE_STRERROR_R
-       #if !HAVE_DECL_STRERROR_R
-               #ifdef STRERROR_R_CHAR_P
-                       char *strerror_r(int errnum, char *buf, size_t buflen);
-               #else
-                       int strerror_r(int errnum, char *buf, size_t buflen);
-               #endif
+       #ifdef STRERROR_R_CHAR_P
+       char *strerror_r(int errnum, char *buf, size_t buflen);
+       #else
+       int strerror_r(int errnum, char *buf, size_t buflen);
        #endif
 
        #ifdef STRERROR_R_CHAR_P
index 665facdcd40f0950e54ba9ea1365fc1f1a50d2a1..4a3920a7756f5ccd0360cbc23cb0d7ce22a89838 100755 (executable)
@@ -46,6 +46,7 @@ meson setup san_build \
        -Dseccomp=false \
        -Db_lto=false \
        -Db_pie=false \
+       -Dthread-safety=false \
        -Doss-fuzz=true
 ninja -C san_build -v