termux / termux-app

Termux - a terminal emulator application for Android OS extendible by variety of packages.
https://f-droid.org/en/packages/com.termux
Other
36.49k stars 3.84k forks source link

[Bug]: vnc process terminated when switching to different app #2540

Closed magbulogtong81 closed 1 year ago

magbulogtong81 commented 2 years ago

Problem description

I have this weird bug on android 11 where the vncserver is killed whenever i switch to vnc viewer. i checked pstree to verify that the process for vncserver is running. it is on ubuntu proot-distro and i used tightvncserver for vnc and xfce4 for desktop environment.

its weird because i know this works on android 9 and below. ( i can't remember if this works on this phone with android 10)

here's what happend shown on video below

https://user-images.githubusercontent.com/46246619/150596194-42981a22-b554-4070-9605-d940d7d0d441.mp4

(here's a google drive link incase the video doesn't work here)

Steps to reproduce the behavior.

cat proot-ubuntu-login.sh shows my script that runs: proot-distro login ubuntu --user lil where "lil" is the user ./proot-ubuntu-login.sh (login with ubuntu) vncserver :1 (runs vnc on port 5901) pstree (shows process tree) then when I open it with vnc viewer(localhost:5901 or 127.0.0.1:5901), it says that the it can't connect to the server when i switch back to termux, i ran pstree, but the vnc process is not there anymore

What is the expected behavior?

the vncserver process is terminated when you switch to other apps. (vnc viewer app in this case)

System information

agnostic-apollo commented 2 years ago

Try running the server in foreground with vncserver -fg :1 since daemon may be getting killed by android.

https://manpages.debian.org/unstable/tigervnc-standalone-server/tigervncserver.1.en.html

WilsonBradley commented 1 year ago

Having same problem when running server nethunter kex Process dies within a 1-2 minutes What to use in command line to run in foreground?

Tanx

agnostic-apollo commented 1 year ago

https://wiki.termux.com/wiki/Hacking

magbulogtong81 commented 1 year ago

for those who might encounter this issue, try this: download tini from here

it might get downloaded with filename like tini-arm64. if it does, just rename it to tini

put it in your $PATH

add a .profile entry with nano or vim

paste this: if [ -z "$TINI_SESSION" ] then export TINI_SESSION="1" exec tini -s bash fi

close termux and open it again

type ps

if it shows like this: PID TTY TIME CMD 22845 pts/0 00:00:00 tini 22960 pts/0 00:00:00 bash 32212 pts/0 00:00:00 ps

then it's working. if it's showing a different one, you did it wrong.

WilsonBradley commented 1 year ago

for those who might encounter this issue, try this: download tini from here

it might get downloaded with filename like tini-arm64. if it does, just rename it to tini

put it in your $PATH

add a .profile entry with nano or vim

paste this: if [ -z "$TINI_SESSION" ] then export TINI_SESSION="1" exec tini -s bash fi

close termux and open it again

type ps

if it shows like this: PID TTY TIME CMD 22845 pts/0 00:00:00 tini 22960 pts/0 00:00:00 bash 32212 pts/0 00:00:00 ps

then it's working. if it's showing a different one, you did it wrong.

Thank you so much... Will give this a try to see if the process stays (will report back).. Appreciate it.!! Just for clarity, your saying choose the top tini , not the arm, etc.. image

WilsonBradley commented 1 year ago

for those who might encounter this issue, try this: download tini from here

it might get downloaded with filename like tini-arm64. if it does, just rename it to tini

put it in your $PATH

add a .profile entry with nano or vim

paste this: if [ -z "$TINI_SESSION" ] then export TINI_SESSION="1" exec tini -s bash fi

close termux and open it again

type ps

if it shows like this: PID TTY TIME CMD 22845 pts/0 00:00:00 tini 22960 pts/0 00:00:00 bash 32212 pts/0 00:00:00 ps

then it's working. if it's showing a different one, you did it wrong.

Sorry, noob here.. When you say put in your $PATH, you mean copy tini & .profile to here for example; /data/data/com.termux/files/home ? Im doing this on a phone so, copy/paste doesnt even seem to carry over from browser to termux. Termux doesnt seem to have edit functions..

magbulogtong81 commented 1 year ago

Sorry, noob here.. When you say put in your $PATH, you mean copy tini & .profile to here for example; /data/data/com.termux/files/home ? Im doing this on a phone so, copy/paste doesnt even seem to carry over from browser to termux. Termux doesnt seem to have edit functions..

you could download tini with wget (example: wget https://github.com/krallin/tini/releases/download/v0.19.0/tini-arm64)

what i mean about the $PATH is you should put the tini to a directory where you could execute it system wide (on linux, $PATH contains multiple directories) /data/data/com.termux/files/usr/bin should be your default $PATH

what i mean about the .profile entry is that you should create the .profile as a text file using nano or vim(or any text editor) on your home directory then paste the script mentioned above

magbulogtong81 commented 1 year ago

I forgot to mention, you should select the static build to make it work Screenshot_2022-11-22-06-46-35-21_40deb401b9ffe8e1df2f1cc5ba480b12

also, you should select the correct version for your device architecture. (you could check it by executing: dpkg --print-architecture on termux) if it shows arm/armhf, then select armhf if it shows arm64/aarch64, then select arm64 if it shows i386, then select i386 if it shows amd64, then select amd64

WilsonBradley commented 1 year ago

Thank you so much for your time/help I went ahead and installed openssh and was able to ssh from desktop (so cut / paste works ;-) ) It's .../usr/bin $ dpkg --print-architecture aarch64

I followed your instructions and tini is not running yet.. :-( ~ $ ps PID TTY TIME CMD 24692 pts/1 00:00:00 bash 24744 pts/1 00:00:00 ps

I wget tini into here and the .profile into here;

/data/data/com.termux/files/usr/bin

magbulogtong81 commented 1 year ago

I wget tini into here and the .profile into here;

/data/data/com.termux/files/usr/bin

no, that's wrong. .profile must be on home directory, so that termux will automatically execute the script, and tini must be on $PREFIX/bin; check the images below IMG_20221123_222952 IMG_20221123_223215

WilsonBradley commented 1 year ago

Thank you so much.. I honestly am learning a lot this way. Sorry for all the internal dialog, just "speaking out loud" to help me learn...

UPDATE: I was able to access file system on home and removed .profile. Will try following from start to install tini . Fingers crossed; .../usr/bin $ pwd /data/data/com.termux/files/usr/bin .../usr/bin $ wget https://github.com/krallin/tini/releases/download/v0.19.0/tini-arm64 --2022-11-23 09:53:45-- https://github.com/krallin/tini/releases/download/v0.19.0/tini-arm64 Resolving github.com... 140.82.114.3 Connecting to github.com|140.82.114.3|:443... connected. tini-arm64.1 100%[=============================================================================>] 23.34K --.-KB/s in 0.006s

2022-11-23 09:53:45 (3.69 MB/s) - ‘tini-arm64.1’ saved [23904/23904]

.../usr/bin $ ls tini. tini-arm64.1 .../usr/bin $ cp tini-arm64 tini .../usr/bin $ ls tini* tini tini-arm64 tini-arm64.1 ------------------------ looks like tini is renamed properly and there now,

~ $ pwd /data/data/com.termux/files/home ~ $ ls -a . .config .suroot .wget-hsts install-nethunter-termux kalifs-arm64-full.sha512sum nethunter-installer-termux usbtest .. .profile .termux 2MceZWr installer-nethunter-termux kalifs-arm64-full.tar.xz storage usbtest.c .bash_history .ssh .termux_authinfo 2MceZWr.1 kali-arm64 nethunter-installer usb.sh ~ $

---- .profile is now there.. fingers crossed ;-) ---- Do I need to chmod change permissions of .profile ? ---- hummm, now it dies again, because of permissions of .profile I tried chmod -x .profile, do I also need to change permissions to tini ?

bash: /data/data/com.termux/files/usr/bin/tini: Permission denied bash: exec: /data/data/com.termux/files/usr/bin/tini: cannot execute: Success

[Process completed (code 126) - press Enter]

---------------------------------chmod -x ---------------------------------here is the permissions for tini now :/data/data/com.termux/files/usr/bin $ ls -l tini -rwx------ 1 u0_a682 u0_a682 23904 2022-11-23 09:57 tini

--------------------------------- but when launching termux , get this. stuck/confused why it's saying required file not found, but it found it before. Is it looking for something else?

bash: /data/data/com.termux/files/usr/bin/tini: cannot execute: required file not found

[Process completed (code 127) - press Enter]

--------------------------------- have to launch termux in failsafe .. --------------------------------- I noticed that tini is only 24k , versus yours much bigger.. 24K /data/data/com.termux/files/usr/bin/tini

sylirre commented 1 year ago

@WilsonBradley You are trying to run a dynamic executable which is linked against GNU libc. See https://wiki.termux.com/wiki/Differences_from_Linux about this.

Try a static variant (https://github.com/krallin/tini/releases/download/v0.19.0/tini-static-arm64) but even it is not guaranteed to work properly in Termux.

WilsonBradley commented 1 year ago

@sylirre @magbulogtong81 YAY!!!! Got tini working. ~ $ ps PID TTY TIME CMD 3338 pts/1 00:00:00 tini 3371 pts/1 00:00:00 bash 3443 pts/1 00:00:00 ps

Thank you so much!!! WAS, hoping this would have helped keep kex (Xtigervnc) running on Android without it killing it within 1-2 min.. But still no..
However, I did learn a lot. Appreciate all your help.. Hoping this Android bug of killing background services will be resolved in future or a work around..

~ $ nethunter kex -r & [1] 12919 ~ $ vncserver: No matching VNC server running for this user! vncserver: No matching VNC server running for this user!

NetHunter KeX server sessions:

X DISPLAY # RFB PORT # RFB UNIX PATH PROCESS ID # SERVER 1 5901 12945 Xtigervnc

You can use the KeX client to connect to any of these displays.

[Process completed (signal 9) - press Enter]

WilsonBradley commented 1 year ago

For all Android users Version 12> Hope this helps you guys.. There is a adb workaround and can validate it works, (until reboot) adb into connected phone and paste below; adb shell "/system/bin/device_config put activity_manager max_phantom_processes 2147483647" More info here; https://youtu.be/jSHpmvfNUUA https://github.com/agnostic-apollo/Android-Docs/blob/master/en/docs/apps/processes/phantom-cached-and-empty-processes.md#device_config-command

agnostic-apollo commented 1 year ago

For all Android users above Version 8> Hope this helps you guys..

Phantom process killer was added in Android 12.

magbulogtong81 commented 1 year ago

@sylirre @magbulogtong81 YAY!!!! Got tini working. ~ $ ps PID TTY TIME CMD 3338 pts/1 00:00:00 tini 3371 pts/1 00:00:00 bash 3443 pts/1 00:00:00 ps

Thank you so much!!! WAS, hoping this would have helped keep kex (Xtigervnc) running on Android without it killing it within 1-2 min.. But still no..

huh. have you tried running a different server? like ssh or httpd? just to see if those also get killed.

EDIT: i mean, I'm sure it's working on mine (i used xtightvnc to show forground logs) I'm on android 12, so I'm also affected by the phantom process killer but this fixes it

https://user-images.githubusercontent.com/46246619/208008022-4253bbb2-28b1-4fbc-8cc5-433fe0e42aa3.mp4