termux / termux-packages

A package build system for Termux.
https://termux.dev
Other
12.77k stars 2.94k forks source link

fish 3.2.1: fish shell crashing on start #6639

Open swg0101 opened 3 years ago

swg0101 commented 3 years ago

Problem description Fish shell crashes on my Pixel 4A 5G upon starting (Android 11). The crash appeared after doing a pkg upgrade but was not sure what the previous version I was using before (was working fine on Android 11 before the upgrade). Doing a fresh install of Termux and fish 3.2.1 does not resolve the issue. Setting SELinux to Permissive also does not resolve the issue (there were not any SELinux violations noted when it was in Enforcing mode). Both bash and zsh works fine on the device, but not fish.

~ $ fish
warning: Could not set up terminal.
warning: TERM environment variable not set.
error: Your history will not be saved.
warning-path: Unable to locate data directory derived from $HOME: '/data/.local/share/fish'.
warning-path: The error was 'Permission denied'.
warning-path: Please set $HOME to a directory where you have write access.

error: Your personal settings will not be saved.
warning-path: Unable to locate config directory derived from $HOME: '/data/.config/fish'.
warning-path: The error was 'Permission denied'.
warning-path: Please set $HOME to a directory where you have write access.

~ddata/com.ter.termux/files/usr/share/fish/config.: Invalid token '-n\'
from sourcing file ~ddata/com.ter.termux/files/usr/share/fish/config.
        called during startup
source: Error while reading file '/data/data/com.termux/files/usr/share/fish/config.fish'
~ddata/com.ter.termux/files/usr/etc/fish/config. (line 16): Missing end to balance this function definition
function __fish_command_not_found_handler --on-event fish_command_not_found
^
from sourcing file ~ddata/com.ter.termux/files/usr/etc/fish/config.
        called during startup
source: Error while reading file '/data/data/com.termux/files/usr/etc/fish/config.fish'
fish: Unknown command: e\x00\x00\x00
echo -n "$USER@$hostname $PWD "'> '
^
in command substitution

~ $ env
SHELL=/data/data/com.termux/files/usr/bin/bash
HISTCONTROL=ignoreboth
PREFIX=/data/data/com.termux/files/usr
PWD=/data/data/com.termux/files/home
LOGNAME=u0_a485
TERMUX_VERSION=0.108
EXTERNAL_STORAGE=/sdcard
LD_PRELOAD=/data/data/com.termux/files/usr/lib/libtermux-exec.so
HOME=/data/data/com.termux/files/home
LANG=en_US.UTF-8
DEX2OATBOOTCLASSPATH=/apex/com.android.art/javalib/core-oj.jar:/apex/com.android.art/javalib/core-libart.jar:/apex/com.android.art/javalib/core-icu4j.jar:/apex/com.android.art/javalib/okhttp.jar:/apex/com.android.art/javalib/bouncycastle.jar:/apex/com.android.art/javalib/apache-xml.jar:/system/framework/framework.jar:/system/framework/ext.jar:/system/framework/telephony-common.jar:/system/framework/voip-common.jar:/system/framework/ims-common.jar:/system/framework/framework-atb-backward-compatibility.jar
TMPDIR=/data/data/com.termux/files/usr/tmp
SSH_CONNECTION=127.0.0.1 48533 127.0.0.1 8022
ANDROID_DATA=/data
TERM=xterm
USER=u0_a485
ANDROID_I18N_ROOT=/apex/com.android.i18n
SHLVL=1
ANDROID_ROOT=/system
BOOTCLASSPATH=/apex/com.android.art/javalib/core-oj.jar:/apex/com.android.art/javalib/core-libart.jar:/apex/com.android.art/javalib/core-icu4j.jar:/apex/com.android.art/javalib/okhttp.jar:/apex/com.android.art/javalib/bouncycastle.jar:/apex/com.android.art/javalib/apache-xml.jar:/system/framework/framework.jar:/system/framework/ext.jar:/system/framework/telephony-common.jar:/system/framework/voip-common.jar:/system/framework/ims-common.jar:/system/framework/framework-atb-backward-compatibility.jar:/apex/com.android.conscrypt/javalib/conscrypt.jar:/apex/com.android.media/javalib/updatable-media.jar:/apex/com.android.mediaprovider/javalib/framework-mediaprovider.jar:/apex/com.android.os.statsd/javalib/framework-statsd.jar:/apex/com.android.permission/javalib/framework-permission.jar:/apex/com.android.sdkext/javalib/framework-sdkextensions.jar:/apex/com.android.wifi/javalib/framework-wifi.jar:/apex/com.android.tethering/javalib/framework-tethering.jar
SSH_CLIENT=127.0.0.1 48533 8022
ANDROID_TZDATA_ROOT=/apex/com.android.tzdata
PATH=/data/data/com.termux/files/usr/bin
ANDROID_ART_ROOT=/apex/com.android.art
SSH_TTY=/dev/pts/1
_=/data/data/com.termux/files/usr/bin/env

Unfortunately, the repo only has the latest version so I cannot try reverting:

~ $ apt policy fish
fish:
  Installed: 3.2.1
    Candidate: 3.2.1
      Version table:
       *** 3.2.1 500
        500 https://termux.org/packages stable/main aarch64 Packages
                100 /data/data/com.termux/files/usr/var/lib/dpkg/status

Steps to reproduce Launch fish - chsh to fish will result in an unusable shell.

Expected behavior Normal shell launch

Additional information

~ $ termux-info
Application version:
0.108
Packages CPU architecture:
aarch64
Subscribed repositories:
# sources.list
deb https://termux.org/packages/ stable main
# game-repo (sources.list.d/game.list)
deb https://grimler.se/game-packages-24 games stable
# science-repo (sources.list.d/science.list)
deb https://grimler.se/science-packages-24 science stable
Updatable packages:
All packages up to date
Android version:
11
Kernel build information:
Linux localhost 4.19.135-proton-v1.2-38382-g758ce76b9420 #1 SMP PREEMPT Thu Apr 15 19:54:15 PDT 2021 aarch64 Android
Device manufacturer:
Google
Device model:
Pixel 4a (5G)
Grimler91 commented 3 years ago

Do you get the same on device, i.e. not in a ssh shell?

Try export ANDROID_DATA=/data/data/com.termux/files/home and see if that makes a difference

swg0101 commented 3 years ago

No difference, on device or SSH, with or without the above command.

Grimler91 commented 3 years ago

Alright, I'll give it a try on android 11 to see if I can reproduce it later.

You can try the older fish version if you change to the grimler.se repository with termux-change-repo, I have not purged old versions there yet

swg0101 commented 3 years ago

Thanks - it seems like switching over to the oldest version didn't help too. I did also recently upgrade my Android to the April security update, so perhaps that might have something to do with it.

Here's also a strace from my device - seems like fish might be looking at the wrong directories for stuff...

strace.txt

ghost commented 3 years ago

I'm on Android 11 (device Pixel 5) with all latest updates and fish works without issues.

Your strace log contains this line:

openat(AT_FDCWD, "/data/.bash_history", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)

Any reason fish tries to open the Bash history file? Perhaps there some changes were applied to configuration files?

Shell transcript from the top post contains these lines:

source: Error while reading file '/data/data/com.termux/files/usr/etc/fish/config.fish'
fish: Unknown command: e\x00\x00\x00

This means file config.fish for unknown reason has null characters (0x00 in hex) which shouldn't happen. If you have not modified this file manually, this could indicate on problem with file system or even hardware because file is getting corrupted.

swg0101 commented 3 years ago

I did have a changed config before and thought that was the issue hence I cleared data on Termux and decided to start fresh. The strace was captured on a fresh install of Termux from F-Droid and has no changes whatsoever. I don't think it is a file corruption issue since it would have affected many different things and this is only affecting fish, even after clearing data on the app (and multiple times)...

I do think the issue might be related to the fact that it cannot correctly determine where the home directory is, even though $HOME is set, and hence Fish is accessing configs and folders in the root /data directory - which it is getting various Permission denied errors...

Grimler91 commented 3 years ago

Works on my arm android 11 device as well. Does /data/data/com.termux/files/usr/etc/fish/config.fish look alright? Does the error change if you export HOME=/sdcard/ for example?

swg0101 commented 3 years ago

Yep that file looks fine. Export HOME=/sdcard/ also doesn't do anything...

ghost commented 3 years ago

I don't think it is a file corruption issue since it would have affected many different things and this is only affecting fish

Run dpkg --verify, just in case.

swg0101 commented 3 years ago

Only shows that sources.list was modified (I think an upgrade wanted to replace it or it was because of the replace repo command)...

.../files/home $ dpkg --verify
??5?????? c /data/data/com.termux/files/usr/etc/apt/sources.list
ghost commented 3 years ago

Ok, then files are fine. Issue perhaps in something else.

swg0101 commented 3 years ago

How does your strace compare and where did it start diverging? ltrace is kind of interesting that it seems like the ncurses is showing a nil TERM variable and seems like fish is erroring on that right after:

~ $ ltrace -fe getenv fish
[pid 20768] fish->getenv("TMPDIR")                                                                                                                                   = "/data/data/com.termux/files/usr/"...
[pid 20768] fish->getenv("FISH_DEBUG")                                                                                                                               = nil
[pid 20768] libc.so->getenv("POSIXLY_CORRECT")                                                                                                                       = nil
[pid 20768] fish->getenv("FISH_DEBUG_OUTPUT")                                                                                                                        = nil
[pid 20768] fish->getenv("SHLVL")                                                                                                                                    = "1"
[pid 20768] fish->getenv("PWD")                                                                                                                                      = "/data/data/com.termux/files/home"...
[pid 20768] fish->getenv("TERM")                                                                                                                                     = "xterm"
[pid 20768] libncursesw.so.6->getenv("TERM")                                                                                                                         = nil
warning: Could not set up terminal.
warning: TERM environment variable not set.
error: Your history will not be saved.
warning-path: Unable to locate data directory derived from $HOME: '/data/.local/share/fish'.
warning-path: The error was 'Permission denied'.
warning-path: Please set $HOME to a directory where you have write access.

error: Your personal settings will not be saved.
warning-path: Unable to locate config directory derived from $HOME: '/data/.config/fish'.
warning-path: The error was 'Permission denied'.
warning-path: Please set $HOME to a directory where you have write access.

~ddata/com.ter.termux/files/usr/share/fish/config.: Invalid token '-n\'
from sourcing file ~ddata/com.ter.termux/files/usr/share/fish/config.
        called during startup
source: Error while reading file '/data/data/com.termux/files/usr/share/fish/config.fish'
~ddata/com.ter.termux/files/usr/etc/fish/config. (line 16): Missing end to balance this function definition
function __fish_command_not_found_handler --on-event fish_command_not_found
^
from sourcing file ~ddata/com.ter.termux/files/usr/etc/fish/config.
        called during startup
source: Error while reading file '/data/data/com.termux/files/usr/etc/fish/config.fish'
fish: Unknown command: e\x00\x00\x00
echo -n "$USER@$hostname $PWD "'> '
^
in command substitution
[pid 20768] fish->getenv("XDG_RUNTIME_DIR")                                                                                                                          = nil
[pid 20768] fish->getenv("TMPDIR")                                                                                                                                   = "/data/data/com.termux/files/usr/"...
ghost commented 3 years ago
~ $ ltrace -fe getenv fish
[pid 14153] fish->getenv("TMPDIR")                                                = "/data/data/com.termux/files/usr/"...
[pid 14153] fish->getenv("FISH_DEBUG")                                            = nil
[pid 14153] libc.so->getenv("POSIXLY_CORRECT")                                    = nil
[pid 14153] fish->getenv("FISH_DEBUG_OUTPUT")                                     = nil
[pid 14153] fish->getenv("SHLVL")                                                 = "1"
[pid 14153] fish->getenv("PWD")                                                   = "/data/data/com.termux/files/home"...
[pid 14153] fish->getenv("TERM")                                                  = "xterm-256color"
[pid 14153] libncursesw.so.6->getenv("TERM")                                      = "xterm-256color"
[pid 14153] libncursesw.so.6->getenv("TERMINFO")                                  = nil
[pid 14153] libncursesw.so.6->getenv("HOME")                                      = "/data/data/com.termux/files/home"...
[pid 14153] libncursesw.so.6->getenv("HOME")                                      = "/data/data/com.termux/files/home"...
[pid 14153] libncursesw.so.6->getenv("TERMINFO_DIRS")                             = nil
[pid 14153] libncursesw.so.6->getenv("TERMCAP")                                   = nil
[pid 14153] libncursesw.so.6->getenv("TERMPATH")                                  = nil
[pid 14153] libncursesw.so.6->getenv("TERMINFO")                                  = nil
[pid 14153] libncursesw.so.6->getenv("HOME")                                      = "/data/data/com.termux/files/home"...
[pid 14153] libncursesw.so.6->getenv("TERMINFO_DIRS")                             = nil
[pid 14153] libncursesw.so.6->getenv("TERMCAP")                                   = nil
[pid 14153] libncursesw.so.6->getenv("TERMPATH")                                  = nil
[pid 14154] +++ exited (status 0) +++
[pid 14155] +++ exited (status 0) +++
[pid 14156] +++ exited (status 0) +++
[pid 14157] +++ exited (status 0) +++
W[pid 14158] +++ exited (status 0) +++
elcome to fish, the friendly interactive shell
Type help for instructions on how to use fish
[pid 14159] +++ exited (status 0) +++
[pid 14161] +++ exited (status 0) +++
[pid 14162] +++ exited (status 0) +++
[pid 14163] +++ exited (status 0) +++
[pid 14164] +++ exited (status 0) +++
[pid 14165] +++ exited (status 0) +++
[pid 14168] libtermux-exec.so->getenv("TERMUX_ANDROID10_DEBUG")                   = nil
[pid 14168] libtermux-exec.so->getenv("TERMUX_ANDROID10")                         = nil
[pid 14168] --- Called exec() ---
[pid 14168] fish->getenv("POSIXLY_CORRECT")                                       = nil
[pid 14168] +++ exited (status 0) +++
[pid 14153] --- SIGCHLD (Child exited) ---
[pid 14153] unexpected breakpoint at 0x7c5f75820c
u0_a299@localhost ~> [pid 14153] fish->getenv("XDG_RUNTIME_DIR")                                       = nil
[pid 14153] fish->getenv("TMPDIR")                                                = "/data/data/com.termux/files/usr/"...
[pid 14160] +++ exited (status 0) +++

[pid 14167] +++ exited (status 0) +++

u0_a299@localhost ~>
swg0101 commented 3 years ago

Interesting, it looks like mine doesn't even get to the HOME variable before crashing. But curious why my libncursesw.so.6->getenv("TERM") would return nil while yours would return xterm-256color....

ghost commented 3 years ago

Because it is not exported. It is visible for current process, but not for sub processes.

Here is what will be with variable not set.

~ $ unset TERM
~ $ fish
warning: Could not set up terminal.
warning: TERM environment variable not set.
Welcome to fish, the friendly interactive shell
Type help for instructions on how to use fish
error: missing argument
in function '__fish_print_pipestatus' with arguments '\[ \] \| 0'
        called on line 1 of file /data/data/com.termux/files/usr/share/fish/functions/fish_prompt.fish
in command substitution
        called on line 33 of file /data/data/com.termux/files/usr/share/fish/functions/fish_prompt.fish
in function 'fish_prompt'
in command substitution
u0_a299@localhost ~>

Doing just TERM=xterm won't work.

~ $ TERM=xterm
~ $ fish
warning: Could not set up terminal.
warning: TERM environment variable not set.
Welcome to fish, the friendly interactive shell
Type help for instructions on how to use fish
error: missing argument
in function '__fish_print_pipestatus' with arguments '\[ \] \| 0'
        called on line 1 of file /data/data/com.termux/files/usr/share/fish/functions/fish_prompt.fish
in command substitution
        called on line 33 of file /data/data/com.termux/files/usr/share/fish/functions/fish_prompt.fish
in function 'fish_prompt'
in command substitution
u0_a299@localhost ~>

Fixing:

~ $ export TERM=xterm
~ $ fish
Welcome to fish, the friendly interactive shell
Type help for instructions on how to use fish
u0_a299@localhost ~>

Have you made any changes so your environment variables doesn't look right?

You have a non-default value (xterm instead of xterm-256color) in

[pid 20768] fish->getenv("TERM")                                                                                                                                     = "xterm"
swg0101 commented 3 years ago

No, I have not made any changes to any configuration files. This was from a fresh install of Termux with no config changes. Where is the default value usually set (is it some kind of rc type script?)

That being said, exporting it does not work either:

~ $ export TERM=xterm
~ $ fish
warning: Could not set up terminal.
warning: TERM environment variable not set.
error: Your history will not be saved.
warning-path: Unable to locate data directory derived from $HOME: '/data/.local/share/fish'.
warning-path: The error was 'Permission denied'.
warning-path: Please set $HOME to a directory where you have write access.

error: Your personal settings will not be saved.
warning-path: Unable to locate config directory derived from $HOME: '/data/.config/fish'.
warning-path: The error was 'Permission denied'.
warning-path: Please set $HOME to a directory where you have write access.

~ddata/com.ter.termux/files/usr/share/fish/config.: Invalid token '-n\'
from sourcing file ~ddata/com.ter.termux/files/usr/share/fish/config.
        called during startup
source: Error while reading file '/data/data/com.termux/files/usr/share/fish/config.fish'
~ddata/com.ter.termux/files/usr/etc/fish/config. (line 16): Missing end to balance this function definition
function __fish_command_not_found_handler --on-event fish_command_not_found
^
from sourcing file ~ddata/com.ter.termux/files/usr/etc/fish/config.
        called during startup
source: Error while reading file '/data/data/com.termux/files/usr/etc/fish/config.fish'
fish: Unknown command: e\x00\x00\x00
echo -n "$USER@$hostname $PWD "'> '
^
in command substitution
~ $ export TERM=xterm
~ $ ltrace -fe getenv fish
[pid 29023] fish->getenv("TMPDIR")                                                                 = "/data/data/com.termux/files/usr/"...
[pid 29023] fish->getenv("FISH_DEBUG")                                                             = nil
[pid 29023] libc.so->getenv("POSIXLY_CORRECT")                                                     = nil
[pid 29023] fish->getenv("FISH_DEBUG_OUTPUT")                                                      = nil
[pid 29023] fish->getenv("SHLVL")                                                                  = "1"
[pid 29023] fish->getenv("PWD")                                                                    = "/data/data/com.termux/files/home"...
[pid 29023] fish->getenv("TERM")                                                                   = "xterm"
[pid 29023] libncursesw.so.6->getenv("TERM")                                                       = nil
warning: Could not set up terminal.
warning: TERM environment variable not set.
error: Your history will not be saved.
warning-path: Unable to locate data directory derived from $HOME: '/data/.local/share/fish'.
warning-path: The error was 'Permission denied'.
warning-path: Please set $HOME to a directory where you have write access.

error: Your personal settings will not be saved.
warning-path: Unable to locate config directory derived from $HOME: '/data/.config/fish'.
warning-path: The error was 'Permission denied'.
warning-path: Please set $HOME to a directory where you have write access.

~ddata/com.ter.termux/files/usr/share/fish/config.: Invalid token '-n\'
from sourcing file ~ddata/com.ter.termux/files/usr/share/fish/config.
        called during startup
source: Error while reading file '/data/data/com.termux/files/usr/share/fish/config.fish'
~ddata/com.ter.termux/files/usr/etc/fish/config. (line 16): Missing end to balance this function definition
function __fish_command_not_found_handler --on-event fish_command_not_found
^
from sourcing file ~ddata/com.ter.termux/files/usr/etc/fish/config.
        called during startup
source: Error while reading file '/data/data/com.termux/files/usr/etc/fish/config.fish'
fish: Unknown command: e\x00\x00\x00
echo -n "$USER@$hostname $PWD "'> '
^
in command substitution
[pid 29023] fish->getenv("XDG_RUNTIME_DIR")                                                        = nil
[pid 29023] fish->getenv("TMPDIR")                                                                 = "/data/data/com.termux/files/usr/"...
ghost commented 3 years ago

~ $ export TERM=xterm ~ $ fish warning: Could not set up terminal. warning: TERM environment variable not set.

Really weird.

Could you run logcat | grep avc to log all SELinux denials?

swg0101 commented 3 years ago

No AVC denials - doesn't work even with SELinux is on Permissive.

~ $ sha1sum $PREFIX/lib/libncursesw.so.6
dad9670762e85035f34840c6b2b269ae42807754  /data/data/com.termux/files/usr/lib/libncursesw.so.6

~ $ ls -la $PREFIX/lib/libncursesw.so*
lrwxrwxrwx 1 u0_a485 u0_a485     18 Apr 16 00:39 /data/data/com.termux/files/usr/lib/libncursesw.so -> libncursesw.so.6
lrwxrwxrwx 1 u0_a485 u0_a485     34 Apr 16 00:39 /data/data/com.termux/files/usr/lib/libncursesw.so.6 -> libncursesw.so.6.2
-rw------- 1 u0_a485 u0_a485 339192 Apr 16 00:39 /data/data/com.termux/files/usr/lib/libncursesw.so.6.2
Grimler91 commented 3 years ago

Are you using a custom rom? Have you upgraded the rom or kernel recently (around the time when fish stopped working)?

Do you have magisk installed, and any installed magisk modules?

swg0101 commented 3 years ago

Yeah, I have been using Proton AOSP for quite some time. It used to work on the same ROM but stopped working recently. I did upgrade the ROM yesterday, but fish did stop working on the previous version even though it worked before on the previous version. I am not too sure if there is an external factor that could potentially cause this though, which is really weird.

Magisk is installed and there were some modules installed earlier - however, disabling all the modules and rebooting makes no difference and fish still crashes on startup.

On the xterm variable, I do see that it was my SSH client setting it to xterm (instead of the default xterm-256color value in Termux itself). However, it seems like on both cases, libncursesw.so.6 will return TERM=nil.

suhan-paradkar commented 3 years ago

@swg0101 fish is now updated to a newer version... Check if you run into the same errors again

swg0101 commented 3 years ago

Same errors on 3.2.2, but zsh still seems to work fine...

thunder-coding commented 3 years ago

Same errors on 3.2.2, but zsh still seems to work fine...

Are you using any Oh My Fish plugin or any thing else? Some OMF plugins are problematic with fish.

swg0101 commented 3 years ago

Nope, straight from stock.

stale[bot] commented 2 years ago

This issue/PR has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Prn-Ice commented 1 year ago

Hi @swg0101, did you manage to fix this?

swg0101 commented 1 year ago

No, went to zsh instead since this was broken.

Prn-Ice commented 1 year ago

I see, thanks

CrazyHack4 commented 1 year ago

Hola cómo podría eliminar, desactivar fish y volver a la Bash original de termux??

OrdinaryEnder commented 1 year ago

Hola cómo podría eliminar, desactivar fish y volver a la Bash original de termux??

chsh 

luego selecciona bash

pkg remove fish

Listo, debes salir de termux y comenzarlo de nuevo

CrazyHack4 commented 1 year ago

Bro lo hice tal como me dijistes ahora el detalle es que al iniciar doy enter y me saca de la terminal me aparece es Unknown command: '-l' (run 'pkg help' for usage information)

[Process completed (code 1) - press Enter]

El jue., 25 de agosto de 2022 5:47 p. m., OrdinaryEnder < @.***> escribió:

Hola cómo podría eliminar, desactivar fish y volver a la Bash original de termux??

chsh

luego selecciona bash

pkg remove bash

Listo, debes salir de termux y comenzarlo de nuevo

— Reply to this email directly, view it on GitHub https://github.com/termux/termux-packages/issues/6639#issuecomment-1227830717, or unsubscribe https://github.com/notifications/unsubscribe-auth/A2K4X3TO3VLFSAWO6ZEVCJDV27ZWHANCNFSM43A72VSQ . You are receiving this because you commented.Message ID: @.***>