Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docker detection code fails with cgroups v2 #614

Open
benfred opened this issue Sep 20, 2023 · 0 comments
Open

Docker detection code fails with cgroups v2 #614

benfred opened this issue Sep 20, 2023 · 0 comments

Comments

@benfred
Copy link
Owner

benfred commented Sep 20, 2023

In the event of a permissions denied error, py-spy attempts to see if you are running in a docker container and if so displays an error message to make sure you've enabled SYS_PTRACE:

https://github.com/benfred/py-spy/blob/492b41c07c26c6edbe061da942c8dae41d86091e/src/main.rs#L474C1-L486

This works by checking the contents of /proc/self/cgroups - but only works with cgroups v1, and in cgroups v2 this fails since this file only contains 0::/ , and no message is displayed.

One idea is to directly test for the SYS_PTRACE capability #459 (comment)

According to https://stackoverflow.com/questions/68816329/how-to-get-docker-container-id-from-within-the-container-with-cgroup-v2 , we can also probably inspect /proc/self/mountinfo to figure out if we're running in docker.

Another option is to look for the presence of a /.dockerenv file - though this isn't recommended moby/moby#18355 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant