-
Notifications
You must be signed in to change notification settings - Fork 463
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
[Feature request] Getting rid of sharedUserId #668
Comments
The first approach with a persistent connection sound almost like what I made for termux/termux-app#2921, just that my version is integrated into the Termux app and (as usual in contrast to your approaches lol) only uses the public Android APIs. If you're running as root, can't you just drop back to the Termux user? I think apollo made a utility that drops the user and applies the correct SELinux stuff. I don't know much about Android internals, is a process created with Regarding protocols, just sending unions is probably fine, but could leak stack data through uninitialized struct padding bytes. I don't think any plugin to date has to handle confidential/secure data or cryptographic keys or something like that, so it shouldn't be an issue. |
I always had problems with making
Dropping to termux user is process-wide operation. It will work in the case if you want to launch some commands but it will may fail to pass you file descriptors (i.e. in the case if you use termux-usb, but I am not so sure).
System treats it as a regular child process, like
I always fill the whole allocated area of event I am planning to send with zeros, right after allocation. I am pretty sure that is not a problem.
I experimented with writing Java binding for Wayland which should run just fine in Android. https://github.com/twaik/wayland-java-experiment . Of course currently it is not complete, but potentially we can make it a base of Termux:API or Termux:GUI but it may be an overkill. |
|
I'll test tomorrow if it still works in new Android versions. |
Found a version that doesn't break the build, but works on my machine. I fixed everything now for API 34, still works, including FD passing over unix socket connection. |
5/6. Ah, yes, that would work too. Thanks for the fixes. Will your design even work with |
You'd check if the filesystem socket accepts connections, if it doesn't you poke the plugin with For the plugin to not get killed there are 2 options:
Because the service interaction is managed through the Termux app, the only thing you need is to call |
hmmm, I see. Hopefully, synchronization or incoming queue delay won't be an issue. A foreground service is already going to be used by plugin apps to manage API actions in future, and notification can be disabled on Android Callback service could be looked into too. |
We can create long-running service for termux-api without actually showing notification. Android does not show notification by default if you create a channel with |
Feature description
Lot of users have problems with sharedUserId.
Termux:X11 a lot of time does not have this problem.
Probably it will be good for Termux:API to implement something similar.
Connection establishing problem
Currently the most complicated problem is establishing connection.
termux-api
command creates two abstract sockets and executesam broadcast
with passing names of these abstract sockets as an arguments (extras).It is problematic for two reasons.
am
restrictions.I see 2 ways to handle this.
First way
You can use some Java code (yeah, invoking app_process for this) to send broadcast with pinned binder, which will return file descriptors of sockets (probably created by
socketpair
, abstract sockets can not be shared this way) created bytermux-api
command when Termux:API's BroadcastReceiver invokes this Binder. Something like this:some code
This code is got from Termux:X11, but maybe most of it may be replaced with similar code from
TermuxAm
.This code must be called on every
termux-api
invocation only in the case ifsocketpair
created sockets are used. In the case if Java code will create server socket (i.e. in$TMPDIR/termux-api-socket
) and stay in background (and will send sockets of newly-created connections to Termux:API through Broadcasts or already-established socketpair connection) you will need to launch this code only once.termux-api
can check if Unix socket in$TMPDIR/termux-api-socket
is connectable and if there is a lock file that should be created by Java code. OF COURSE this java code can be used to verify if we use Termux:API apk with right signature (hardcoded on compilation stage).Second way
You can add an ability to pass file descriptors through Binder to regular
TermuxAm
andtermux-am-socket
in similar way. In this case we will be able to go on usingam broadcast
command.But in this case you can not verify if right Termux:API apk is installed. Or probably you may integrate signature verification to both
TermuxAm
andtermux-am-socket
too :).Restrictions
That will be problematic for root users. For some reason SELinux blocks Unix sockets from being passed through Binder. Probably you will need to create two pipes (one for reading and one for writing) and pass one side of both pipes through Binder.
File access problem
In the case of disabling
sharedUserId
Termux:API will lose access to files in$PREFIX
and$HOME
.I am proposing to not send
stdin
andstdout
contents in both ways directly. Instead of that you can implement some simple command system to send buffers got fromstdin
/stdout
, create/modify/delete files, pass file descriptors (i.e. fortermux-usb
) and do other stuff.To avoid creating complicated IPC system you can go libxcb way and pass smth like
union Event
which will contain all possible events. I did this in Termux:X11:some code
This code can be combined with
poll
orselect
to not create threads for handling stdin/stdout/socket events separately.@tareksander probably all of that is applicable to
termux-gui
too since it is based ontermux-api
and it is incompatible with F-Droid builds of Termux and its plugins.Ping @agnostic-apollo @Grimler91 @tareksander.
The text was updated successfully, but these errors were encountered: