Skip to content

Commit 3d772fc

Browse files
stratakisvstinner
authored andcommitted
gh-156703: Set LD_LIBRARY_PATH in SystemTap trace commands (GH-156424)
Prefix commands passed to stap -c with LD_LIBRARY_PATH via env, when probes reside in libpython. This allows the interpreter to find libpython when staprun does not preserve the loader path. (cherry picked from commit faf4e52)
1 parent 13075a5 commit 3d772fc

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

‎Lib/test/test_dtrace.py‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,17 @@ def render_script(self, filename):
221221

222222
return script.replace(self.PROBE_PLACEHOLDER, self.python_probe())
223223

224+
def generate_trace_command(self, script_file, subcommand=None):
225+
probe_binary = get_probe_binary()
226+
if subcommand and probe_binary != sys.executable:
227+
library_path = os.path.dirname(probe_binary)
228+
if existing_path := os.environ.get("LD_LIBRARY_PATH"):
229+
library_path = os.pathsep.join((library_path, existing_path))
230+
env = shlex.join(["env", f"LD_LIBRARY_PATH={library_path}"])
231+
subcommand = f"{env} {subcommand}"
232+
233+
return super().generate_trace_command(script_file, subcommand)
234+
224235
def trace(self, script_file, subcommand=None, *, timeout=None,
225236
check_returncode=False):
226237
with tempfile.NamedTemporaryFile(

0 commit comments

Comments
 (0)