You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Make privileged functions available on Android #152936
configure.ac contains a list of privileged functions which are "blocked" on Android, i.e. they simply won't exist in the stdlib. This was because when any of the underlying C functions are called by a non-root user, instead of returning a PermissionError as they would on Linux, they cause a low-level crash of the whole process.
This approach has 2 problems:
Users of these functions will probably be able to handle a PermissionError, but not an AttributeError.
It prevents using the functions on rooted devices.
Termux is working around this by making Python check the UID and raise the PermissionError itself in a non-root context. I think it would be a good idea to adopt this upstream.
This change should only affect Android; on other platforms, UID checks should continue to be done by the underlying C function.
Most of these functions are documented as "not Android"; that should also be removed.
Functions which are blocked in configure.ac for other reasons should continue to be blocked.
Has this already been discussed elsewhere?
I have already discussed this feature proposal on the Termux issue tracker
To clarify - do these methods work as expected when invoked as root?
If so - this seems reasonable; my only question would be around documentation. If EPERM isn't a documented POSIX-expected result from any of the affected methods, we should make sure the docs for those methods clarify the "extension" that Python is adding.
do these methods work as expected when invoked as root?
According to termux/termux-packages#30310 (comment), "chroot, sethostname & setgid, setuid" have all been verified to work. Running apps as root isn't an officially supported mode of Android, but it's reasonably common among power users, so we might as well support it if we can.
If EPERM isn't a documented POSIX-expected result from any of the affected methods
I'm pretty sure it is, but I'll check when reviewing the PR. If so, then the proposed behavior would be identical to POSIX as far as the Python user can tell, so no extra documentation is required.
Activity
pythongh-152936: Make privileged functions available on Android
freakboy3742 commentedon Jul 6, 2026
To clarify - do these methods work as expected when invoked as root?
If so - this seems reasonable; my only question would be around documentation. If
EPERMisn't a documented POSIX-expected result from any of the affected methods, we should make sure the docs for those methods clarify the "extension" that Python is adding.mhsmith commentedon Jul 7, 2026
According to termux/termux-packages#30310 (comment), "chroot, sethostname & setgid, setuid" have all been verified to work. Running apps as root isn't an officially supported mode of Android, but it's reasonably common among power users, so we might as well support it if we can.
I'm pretty sure it is, but I'll check when reviewing the PR. If so, then the proposed behavior would be identical to POSIX as far as the Python user can tell, so no extra documentation is required.
pythongh-152936: Use posix_error for Android checks
pythongh-152936: Document Android support in os and socket
pythongh-152936: Fix test_os and test_posix failures on Android
pythongh-152936: Fix AttributeError for os.chroot on platforms withou…
gh-152936: Make privileged functions available on Android (#152977)
Merge branch 'main' into tachyon-native-callable
pythongh-152936: Make privileged functions available on Android (pyth…
pythongh-152936: Make privileged functions available on Android (pyth…