Skip to content

Commit 8f3bf9b

Browse files
authored
Issue 40 (#45)
Reset the LD_PRELOAD to its previous state, after Score-P was successfully initialised.
1 parent 15c6201 commit 8f3bf9b

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

scorep/__main__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ def scorep_main(argv=None):
8181
new_args.append(elem)
8282

8383
os.execve(sys.executable, new_args, os.environ)
84+
else:
85+
scorep.subsystem.reset_pereload()
8486

8587
scorep_bindings = importlib.import_module("scorep.scorep_bindings")
8688

scorep/subsystem.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def generate(scorep_config, keep_files=False):
7979
return(subsystem_lib_name, temp_dir)
8080

8181

82-
def init_environment(scorep_config=[], keep_files=False): # should move to subsystem
82+
def init_environment(scorep_config=[], keep_files=False):
8383
"""
8484
Set the inital needed environmet variables, to get everythin up an running.
8585
As a few variables interact with LD env vars, the programms needs to be restarted after this.
@@ -106,9 +106,23 @@ def init_environment(scorep_config=[], keep_files=False): # should move to subs
106106
sys.stderr.write(
107107
"LD_PRELOAD is already specified. If Score-P is already loaded this might lead to errors.")
108108
preload_str = preload_str + " " + os.environ["LD_PRELOAD"]
109+
os.environ["SCOREP_LD_PRELOAD_BACKUP"] = os.environ["LD_PRELOAD"]
110+
else:
111+
os.environ["SCOREP_LD_PRELOAD_BACKUP"] = ""
109112
os.environ["LD_PRELOAD"] = preload_str
110113

111114

115+
def reset_pereload():
116+
"""
117+
resets the environment variable `LD_PRELOAD` to the value before init_environment was called.
118+
"""
119+
if "SCOREP_LD_PRELOAD_BACKUP" in os.environ:
120+
if os.environ["SCOREP_LD_PRELOAD_BACKUP"] == "":
121+
del os.environ["LD_PRELOAD"]
122+
else:
123+
os.environ["LD_PRELOAD"] = os.environ["SCOREP_LD_PRELOAD_BACKUP"]
124+
125+
112126
def clean_up(keep_files=True):
113127
"""
114128
deletes the files that are associated to subsystem

0 commit comments

Comments
 (0)