| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
Use shlex.join() when building tracer -c command strings for avoiding issues with spaces.
There was a problem hiding this comment.
Can you also modify f"Command {' '.join(command)!r} failed " to use shlex.join() in run_readelf() and trace()?
Sorry, something went wrong.
|
I tried to create a path with a space to test if the command/paths are properly quoted. I renamed the dtracedata/ directory to dtrace data/: mv Lib/test/dtracedata/ "Lib/test/dtrace data/". I applied this patch: diff --git a/Lib/test/test_dtrace.py b/Lib/test/test_dtrace.py
index 30731b8f90a..b890f467807 100644
--- a/Lib/test/test_dtrace.py
+++ b/Lib/test/test_dtrace.py
@@ -22,7 +22,7 @@
def abspath(filename):
- return os.path.abspath(findfile(filename, subdir="dtracedata"))
+ return os.path.abspath(findfile(filename, subdir="dtrace data"))
def normalize_trace_output(output):For example, this bpftrace program test fails: sudo ./python -m test -v test_dtrace -m test.test_dtrace.BPFTraceOptimizedTests.test_gc I extracted the executed command and simplified it: $ sudo bpftrace -e 'usdt:/home/vstinner/python/main/python:python:function__entry {}' -c "/home/vstinner/python/main/python -O -O '/home/vstinner/python/main/Lib/test/dtrace data/gc.py'"
Attached 1 probe
/home/vstinner/python/main/python: can't open file "/home/vstinner/python/main/'/home/vstinner/python/main/Lib/test/dtrace": [Errno 2] No such file or directory
So python fails to find its filename parameter. |
Sorry, something went wrong.
|
Same error if I try to create a Python executable path with a space in assert_usable(): $ git diff
diff --git a/Lib/test/test_dtrace.py b/Lib/test/test_dtrace.py
index 30731b8f90a..011507bd5c3 100644
--- a/Lib/test/test_dtrace.py
+++ b/Lib/test/test_dtrace.py
@@ -314,9 +314,15 @@ def assert_usable(self):
# Check if bpftrace is available and can attach to USDT probes
program = f'usdt:{sys.executable}:python:function__entry {{ printf("probe: success\\n"); exit(); }}'
try:
+ exe = sys.executable + ' .exe'
+ import shutil
+ shutil.copy2(sys.executable, exe)
+ cmd = shlex.join([exe, "-c", "pass"])
+ print("CMD", cmd)
+ cmd = ["bpftrace", "-e", program, "-c", cmd]
+ print("CMD", cmd)
proc = create_process_group(
- ["bpftrace", "-e", program, "-c",
- shlex.join([sys.executable, "-c", "pass"])],
+ cmd,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
universal_newlines=True,If I run manually bpftrace, it also fails: $ sudo bpftrace -e 'usdt:/home/vstinner/python/main/python:python:function__entry { printf("probe: success\\n"); exit(); }' '-c' "'/home/vstinner/python/main/python .exe' -c pass"
ERROR: Failed to fork child: path ''/home/vstinner/python/main/python' does not exist or is not executable
|
Sorry, something went wrong.
There was a problem hiding this comment.
LGTM. The AssertionError changes are useful. I'm less sure that the bpftrace are useful, but well, they look correct at least. It's just that bpftrace doesn't handle properly commands (-c argument) with quotes.
Sorry, something went wrong.
|
Thanks @stratakis for the PR, and @vstinner for merging it 🌮🎉.. I'm working now to backport this PR to: 3.15. |
Sorry, something went wrong.
|
GH-153459 is a backport of this pull request to the 3.15 branch. |
Sorry, something went wrong.
|
Merged. Thanks for the fix! |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Use shlex.join() when building tracer -c command strings for avoiding issues with spaces.