Skip to content

Commit 96277bb

Browse files
committed
gh-98894: Set LD_LIBRARY_PATH in SystemTap trace commands
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.
1 parent f54fd2a commit 96277bb

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
@@ -229,6 +229,17 @@ def render_script(self, filename):
229229

230230
return script.replace(self.PROBE_PLACEHOLDER, self.python_probe())
231231

232+
def generate_trace_command(self, script_file, subcommand=None):
233+
probe_binary = get_probe_binary()
234+
if subcommand and probe_binary != sys.executable:
235+
library_path = os.path.dirname(probe_binary)
236+
if existing_path := os.environ.get("LD_LIBRARY_PATH"):
237+
library_path = os.pathsep.join((library_path, existing_path))
238+
env = shlex.join(["env", f"LD_LIBRARY_PATH={library_path}"])
239+
subcommand = f"{env} {subcommand}"
240+
241+
return super().generate_trace_command(script_file, subcommand)
242+
232243
def trace(self, script_file, subcommand=None, *, timeout=None,
233244
check_returncode=False):
234245
with tempfile.NamedTemporaryFile(

0 commit comments

Comments
 (0)