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

[Termux] PermissionError: [Errno 13] Permission denied: '/proc/filesystems' #2191

Open
babaric-dev opened this issue Jan 9, 2023 · 7 comments

Comments

@babaric-dev
Copy link

babaric-dev commented Jan 9, 2023

Summary

  • OS: Termux PRoot Ubuntu 22.04 (proot-distro)
  • Architecture: arm64
  • Psutil version:5.9.0
  • Python version: 3.10.6
  • Type: ??

Description

I ran this in the Python interactive console of PRoot Ubuntu:

>>> import psutil
>>> psutil.disk_partitions()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3/dist-packages/psutil/__init__.py", line 2021, in disk_partitions
    ret = _psplatform.disk_partitions(all)
  File "/usr/lib/python3/dist-packages/psutil/_pslinux.py", line 1275, in disk_partitions
    with open_text("%s/filesystems" % procfs_path) as f:
  File "/usr/lib/python3/dist-packages/psutil/_common.py", line 725, in open_text
    return open(fname, "rt", **kwargs)
PermissionError: [Errno 13] Permission denied: '/proc/filesystems'
>>>

It shows PermissionError.

True that we can't really access /proc/filesystems on Android. But at least handle the error with try except and return []?
Better solution: use another way of getting partitions.

@giampaolo
Copy link
Owner

Notes to self:

  1. we read /proc/filesystems only if the function is invoked as disk_partitions(all=False); if all=True, reading /proc/filesystems is superfluous, so it should not raise exception
  2. find out how /proc/filesystems is written and provide a fallback function with hard-coded values in case of EPERM

@babaric-dev what happens if you call disk_partitions(all=True)? Does the function succeed? I want to make sure there are no other permission errors

@babaric-dev
Copy link
Author

babaric-dev commented Jan 9, 2023

With or without all=True, it shows the exact same error message.

>>> psutil.disk_partitions(all=True)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3/dist-packages/psutil/__init__.py", line 2021, in disk_partitions
    ret = _psplatform.disk_partitions(all)
  File "/usr/lib/python3/dist-packages/psutil/_pslinux.py", line 1275, in disk_partitions
    with open_text("%s/filesystems" % procfs_path) as f:
  File "/usr/lib/python3/dist-packages/psutil/_common.py", line 725, in open_text
    return open(fname, "rt", **kwargs)
PermissionError: [Errno 13] Permission denied: '/proc/filesystems'
>>> psutil.disk_partitions(all=False)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3/dist-packages/psutil/__init__.py", line 2021, in disk_partitions
    ret = _psplatform.disk_partitions(all)
  File "/usr/lib/python3/dist-packages/psutil/_pslinux.py", line 1275, in disk_partitions
    with open_text("%s/filesystems" % procfs_path) as f:
  File "/usr/lib/python3/dist-packages/psutil/_common.py", line 725, in open_text
    return open(fname, "rt", **kwargs)
PermissionError: [Errno 13] Permission denied: '/proc/filesystems'
>>>

As I said, /proc/filesystems is unaccessible in Android. cat or stating it shows Permission Denied too.

giampaolo added a commit that referenced this issue Jan 9, 2023
@giampaolo
Copy link
Owner

I just pushed 2da9950. Can you try installing psutil from latest master branch and retry running disk_partitions(all=True)? Run:

python3 -m pip install --upgrade git+https://github.com/giampaolo/psutil.git@master
python3 -c "import psutil; print(psutil.disk_partitions(all=True))"

@babaric-dev
Copy link
Author

Works! But after updating to git version, I see it can't read /proc/stat. Another error. I will open an issue for this later

@babaric-dev
Copy link
Author

Why can't we close this?

@giampaolo
Copy link
Owner

Because of:

  1. find out how /proc/filesystems is written and provide a fallback function with hard-coded values in case of EPERM

@Blackwood416
Copy link

For proot-distro, you can fix this issue by following these steps. First, download fake /proc files(proc.tar.xz) from here. And then extract file named filesystems to your termux home directory. Last, append this --bind ~/filesystems:/proc/filesystems to the end of your proot-login line.

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

No branches or pull requests

3 participants