]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
ceph.in: put libasan.so path before other LD_PRELOAD paths
authorKefu Chai <kchai@redhat.com>
Mon, 24 May 2021 09:27:34 +0000 (17:27 +0800)
committerKefu Chai <kchai@redhat.com>
Mon, 24 May 2021 09:28:08 +0000 (17:28 +0800)
to ensure it is the first one to be preaload. to address following error
like:

==821517==ASan runtime does not come first in initial library list; you should either link runtime to your application or manually preload it with LD_PRELOAD.

Signed-off-by: Kefu Chai <kchai@redhat.com>
src/ceph.in

index 757f3f38937e7eb68bc645c6429e608836de9081..0aaba996f9122230dc0275ac682f28b9a5e7df94 100755 (executable)
@@ -23,6 +23,7 @@ from time import sleep
 import grp
 import os
 import pwd
+import re
 import shutil
 import stat
 import sys
@@ -65,6 +66,16 @@ MYPDIR = os.path.dirname(MYDIR)
 DEVMODEMSG = '*** DEVELOPER MODE: setting PATH, PYTHONPATH and LD_LIBRARY_PATH ***'
 
 
+def add_to_ld_path(path_name, path):
+    paths = re.split('[ :]', os.environ.get(path_name, ''))
+    if path in paths:
+        return 0
+    else:
+        paths.insert(0, path)
+        os.environ[path_name] = ':'.join(paths)
+        return 1
+
+
 def respawn_in_path(lib_path, pybind_path, pythonlib_path, asan_lib_path):
     execv_cmd = []
     if 'CEPH_DBG' in os.environ:
@@ -76,21 +87,18 @@ def respawn_in_path(lib_path, pybind_path, pythonlib_path, asan_lib_path):
         lib_path_var = "LD_LIBRARY_PATH"
 
     execv_cmd += sys.argv
+    ld_paths_changed = 0
     if asan_lib_path:
-        os.environ['LD_PRELOAD'] = asan_lib_path
-    if lib_path_var in os.environ:
-        if lib_path not in os.environ[lib_path_var]:
-            os.environ[lib_path_var] += ':' + lib_path
-            if "CEPH_DEV" not in os.environ:
-                print(DEVMODEMSG, file=sys.stderr)
-            os.execvp(execv_cmd[0], execv_cmd)
-    else:
-        os.environ[lib_path_var] = lib_path
+        ld_paths_changed += add_to_ld_path('LD_PRELOAD', asan_lib_path)
+    if add_to_ld_path(lib_path_var, lib_path) > 0:
         if "CEPH_DEV" not in os.environ:
             print(DEVMODEMSG, file=sys.stderr)
+        ld_paths_changed += 1
+    if ld_paths_changed > 0:
         os.execvp(execv_cmd[0], execv_cmd)
-    sys.path.insert(0, pybind_path)
-    sys.path.insert(0, pythonlib_path)
+    else:
+        sys.path.insert(0, pybind_path)
+        sys.path.insert(0, pythonlib_path)
 
 
 def get_pythonlib_dir():