swrap: Add env variable to disable deep binding
authorAndreas Schneider <asn@samba.org>
Wed, 28 Nov 2018 08:20:58 +0000 (09:20 +0100)
committerAndreas Schneider <asn@samba.org>
Tue, 12 Feb 2019 15:54:18 +0000 (16:54 +0100)
Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
doc/socket_wrapper.1
doc/socket_wrapper.1.txt
src/socket_wrapper.c

index 7e102242ac3d48fae1c71984846759554c75edfc..a064eed7bada7412a8f30769124211b0b44577fe 100644 (file)
@@ -2,12 +2,12 @@
 .\"     Title: socket_wrapper
 .\"    Author: Samba Team
 .\" Generator: DocBook XSL Stylesheets vsnapshot <http://docbook.sf.net/>
-.\"      Date: 2018-06-26
+.\"      Date: 2018-11-28
 .\"    Manual: \ \&
 .\"    Source: \ \&
 .\"  Language: English
 .\"
-.TH "SOCKET_WRAPPER" "1" "2018\-06\-26" "\ \&" "\ \&"
+.TH "SOCKET_WRAPPER" "1" "2018\-11\-28" "\ \&" "\ \&"
 .\" -----------------------------------------------------------------
 .\" * Define some portability stuff
 .\" -----------------------------------------------------------------
@@ -147,6 +147,11 @@ If you need to see what is going on in socket_wrapper itself or try to find a bu
 3 = TRACE
 .RE
 .RE
+.PP
+\fBSOCKET_WRAPPER_DISABLE_DEEPBIND\fR
+.RS 4
+This allows you to disable deep binding in socket_wrapper\&. This is useful for running valgrind tools or sanitizers like (address, undefined, thread)\&.
+.RE
 .SH "EXAMPLE"
 .sp
 .if n \{\
index 583b50a29c95f79bc2b154124de3724b931d8825..da16c6d0e39b8115cb280ba718eb5f44c625a615 100644 (file)
@@ -1,6 +1,6 @@
 socket_wrapper(1)
 =================
-:revdate: 2018-06-26
+:revdate: 2018-11-28
 :author: Samba Team
 
 NAME
@@ -78,6 +78,11 @@ debug symbols.
 - 2 = DEBUG
 - 3 = TRACE
 
+*SOCKET_WRAPPER_DISABLE_DEEPBIND*::
+
+This allows you to disable deep binding in socket_wrapper. This is useful for
+running valgrind tools or sanitizers like (address, undefined, thread).
+
 EXAMPLE
 -------
 
index ca0a833653b561da8a70bcef3bb7ea3b35e53677..f9993a27d749d3b13a658c75682082cc521c8381 100644 (file)
@@ -587,15 +587,25 @@ static void *swrap_load_lib_handle(enum swrap_lib lib)
        int i;
 
 #ifdef RTLD_DEEPBIND
-       const char *env = getenv("LD_PRELOAD");
+       const char *env_preload = getenv("LD_PRELOAD");
+       const char *env_deepbind = getenv("SOCKET_WRAPPER_DISABLE_DEEPBIND");
+       bool enable_deepbind = true;
 
        /* Don't do a deepbind if we run with libasan */
-       if (env != NULL && strlen(env) < 1024) {
-               const char *p = strstr(env, "libasan.so");
-               if (p == NULL) {
-                       flags |= RTLD_DEEPBIND;
+       if (env_preload != NULL && strlen(env_preload) < 1024) {
+               const char *p = strstr(env_preload, "libasan.so");
+               if (p != NULL) {
+                       enable_deepbind = false;
                }
        }
+
+       if (env_deepbind != NULL && strlen(env_deepbind) >= 1) {
+               enable_deepbind = false;
+       }
+
+       if (enable_deepbind) {
+               flags |= RTLD_DEEPBIND;
+       }
 #endif
 
        switch (lib) {