Fix attachp tests when ptrace_scope is missing (#2438)

* Fix attachp tests when ptrace_scope is missing

Assume we can attach to any process when ptrace_scope is not available. This is the case in WSL2.

* Update tests/gdb-tests/tests/test_attachp.py

---------

Co-authored-by: Disconnect3d <dominik.b.czarnota@gmail.com>
pull/2441/head
peace-maker 1 year ago committed by GitHub
parent 2000b4ac4e
commit 34f58d8fdf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -5,6 +5,7 @@ import os
import re
import subprocess
import tempfile
from pathlib import Path
import pytest
@ -16,10 +17,16 @@ if os.getuid() == 0:
can_attach = True
else:
# see `man ptrace`
with open("/proc/sys/kernel/yama/ptrace_scope") as f:
result = f.read()
if len(result) >= 1 and result[0] == "0":
can_attach = True
ptrace_scope = Path("/proc/sys/kernel/yama/ptrace_scope")
if ptrace_scope.exists():
with ptrace_scope.open() as f:
result = f.read()
if len(result) >= 1 and result[0] == "0":
can_attach = True
else:
# If the file doesn't exist, assume we can attach
# This is the case e.g. for running tests under WSL2
can_attach = True
REASON_CANNOT_ATTACH = (
"Test skipped due to inability to attach (needs sudo or sysctl -w kernel.yama.ptrace_scope=0"

Loading…
Cancel
Save