msys2 / MSYS2-packages

Package scripts for MSYS2.
https://packages.msys2.org
BSD 3-Clause "New" or "Revised" License
1.28k stars 486 forks source link

Segmentation faults when running MSYS shells in non-mintty terminals. #2651

Open svraka opened 2 years ago

svraka commented 2 years ago

Describe the issue

Can't use MSYS shells in non-mintty terminals.

I'm not sure, if this is right place to raise my issue, and I have no idea whether this is can be even solved on MSYS's side, or it's just my corporate issued Windows 10 machine with a bunch of BLODA misbehaving. However, it concerns launching a shell, and the related packages come from MSYS, hence the issue here.

Steps to Reproduce the Problem

When trying to run vanilla MSYS2, or MINGW shells without any additional packages, or custom configuration in terminals other than mintty following the official recommendations, the shell hangs in all terminal emulators I tried (Windows Terminal, Alacritty, Emacs shell mode, even Windows's cmd.exe), with a bash.exe process consuming 100% of a CPU thread, seemingly indefinitely. This happens after running an MSYS Bash first in mintty, successfully going though the first setup, and upgrading packages.

With bash in verbose mode (msys2_shell.cmd -defterm -here -no-start -msys -shell bash -v) I can see it gets stuck when trying to source the profile. Throwing in a couple of echos in the sourced files in /etc it seems to me the shell builtins work, problems come from tying to run any executable. Sourcing only hangs on command substitutions but of course calling executables directly, or with exec also fail but the latter two happen silently and the shell doesn't stop on error in these cases. Adding echo $? after these calls, I get 134 (SIGABRT) errors every time. After replacing all these calls with the hardcoded values they normally get in mintty (see the patch below, with which shells in mintty still work) I can get to a prompt. Here shell builtins still work but any executable -- including Windows executables -- results in segmentation fault with a 139 error.

$ ls
Segmentation fault

$ echo $?
139

$ echo "This works" > test

$ [ -e test ]

$ echo $?
0

$ rm test
Segmentation fault

$ winver
Segmentation fault

Interestingly, Git Bash works from every terminal I tried by setting the shell command line in the terminal emulator to C:/Git/bin/bash.exe.

Patch for getting to a working prompt ``` diff diff --git a/post-install/01-devices.post b/post-install/01-devices.post index d5b6fe3..a1c9095 100644 --- a/post-install/01-devices.post +++ b/post-install/01-devices.post @@ -16,8 +16,6 @@ maybe_create_devs () fi fi - # Create it if necessary - mkdir -m 755 "${DEVDIR}" 2> /dev/null if [ ! -e "${DEVDIR}" ] then echo diff --git a/post-install/06-windows-files.post b/post-install/06-windows-files.post index fbedb37..c2b493d 100644 --- a/post-install/06-windows-files.post +++ b/post-install/06-windows-files.post @@ -1,7 +1,8 @@ maybe_create_winetc () { local FILES="hosts protocols services networks" - local WINSYS32HOME="$(exec /usr/bin/cygpath -S -w)" + local WINSYS32HOME="C:\WINDOWS\system32" + local WINETC="${WINSYS32HOME}\\drivers\\etc" if [ ! -d "${WINETC}" ]; then @@ -15,13 +16,12 @@ maybe_create_winetc () do if [ ! -e "/etc/${mketc}" -a ! -L "/etc/${mketc}" ] then - # Windows only uses the first 8 characters - local WFILE="${WINETC}\\$(exec expr substr "${mketc}" 1 8)" - /usr/bin/cp -p -v "${WFILE}" "/etc/${mketc}" + echo "This exists already" fi done - /usr/bin/chmod 1777 /tmp 2>/dev/null + # This is is drwxr-xr-x in mintty... + # /usr/bin/chmod 1777 /tmp 2>/dev/null } maybe_create_winetc diff --git a/profile b/profile index 20e03e1..af4d106 100644 --- a/profile +++ b/profile @@ -79,8 +79,8 @@ SYSCONFDIR="${SYSCONFDIR:=/etc}" ORIGINAL_TMP="${ORIGINAL_TMP:-${TMP}}" ORIGINAL_TEMP="${ORIGINAL_TEMP:-${TEMP}}" unset TMP TEMP -tmp=$(exec cygpath -w "$ORIGINAL_TMP" 2> /dev/null) -temp=$(exec cygpath -w "$ORIGINAL_TEMP" 2> /dev/null) +tmp='C:\Users\myuser\AppData\Local\Temp' +temp='C:\Users\myuser\AppData\Local\Temp' TMP="/tmp" TEMP="/tmp" @@ -120,8 +120,8 @@ for postinst in $(export LC_COLLATE=C; echo /etc/post-install/*.post); do done if [ ! "x${BASH_VERSION}" = "x" ]; then - HOSTNAME="$(exec /usr/bin/hostname)" - SHELL=`which bash` + HOSTNAME="mycomputer" + SHELL="/usr/bin/bash" profile_d sh [ -f "/etc/bash.bashrc" ] && . "/etc/bash.bashrc" elif [ ! "x${KSH_VERSION}" = "x" ]; then ```

Additional Context: Operating System, Screenshots

Windows 10 1909 64 bit, Version 10.0.18363.1646

maksim-petukhov commented 2 years ago

I'm experiencing the same issue. The key thing is

This happens after running an MSYS Bash first in mintty, successfully going though the first setup, and upgrading packages.

I can't reproduce this in Windows docker image

Additional Context

Windows 10 21H1 (19043.1288) msys2 20210725

zymill commented 2 years ago

I'm experiencing the issue maybe it's same! Always crashed fail ( cannot arrive to show username) when I start MSYS Bash after msys2-x86_64-20210604.exe was installed on my PC with Windows 10 21H1 (19043.1288). I don't know where is the MSYS program execution log file. I hope to show some helpful info but I cannot find them. Please help me if you can. (E-mail: zymill@163.com )

Thanks!

svraka commented 2 years ago

I'm experiencing the issue maybe it's same! Always crashed fail ( cannot arrive to show username) when I start MSYS Bash after msys2-x86_64-20210604.exe was installed on my PC with Windows 10 21H1 (19043.1288).

Hi @zymill, does it crash, or do you also have a bash.exe consuming 100% a CPU core?

I don't know where is the MSYS program execution log file. I hope to show some helpful info but I cannot find them. Please help me if you can. (E-mail: zymill@163.com )

There's no log but you could try running bash in verbose with msys2_shell.cmd -defterm -here -no-start -msys -shell bash -liv and check the output.

zymill commented 2 years ago

Hi @zymill, does it crash, or do you also have a bash.exe consuming 100% a CPU core? There's no log but you could try running bash in verbose with msys2_shell.cmd -defterm -here -no-start -msys -shell bash -liv and check the output.

Thanks a lot! @svraka

I have not encountered with one 100% CPU core。 mingw64.exe or msys2.exe will crash after be started. (always no response, There is no choice but to close) Today Rely on you help, I start with command as below: "msys2_shell.cmd -defterm -here"

output logs (I hope it can provide some clues to locate the problem.):

bash: /dev/null: No such device or address bash: /dev/null: No such device or address bash: /dev/null: No such device or address bash: /dev/null: No such device or address /usr/bin/pacman-key: line 535: /dev/null: No such device or address /usr/share/makepkg/util/message.sh: line 28: /dev/null: No such device or address /usr/bin/pacman-key: line 599: /dev/null: No such device or address ==> ERROR: Cannot find the gpg binary required for all pacman-key operations. /usr/bin/pacman-key: line 535: /dev/null: No such device or address /usr/share/makepkg/util/message.sh: line 28: /dev/null: No such device or address /usr/bin/pacman-key: line 599: /dev/null: No such device or address ==> ERROR: Cannot find the gpg binary required for all pacman-key operations. /usr/bin/pacman-key: line 535: /dev/null: No such device or address /usr/share/makepkg/util/message.sh: line 28: /dev/null: No such device or address /usr/bin/pacman-key: line 599: /dev/null: No such device or address ==> ERROR: Cannot find the gpg binary required for all pacman-key operations. gpgconf: Fatal: failed to open '/dev/null': No such device or address gpgconf: error running '/usr/bin/gpg-connect-agent': exit status 2 gpgconf: error running '/usr/bin/gpg-connect-agent KILLDIRMNGR': General error gpgconf: Fatal: failed to open '/dev/null': No such device or address gpgconf: error running '/usr/bin/gpg-connect-agent': exit status 2 gpgconf: error running '/usr/bin/gpg-connect-agent scd killscd': General error gpgconf: Fatal: failed to open '/dev/null': No such device or address gpgconf: error running '/usr/bin/gpg-connect-agent': exit status 2 gpgconf: error running '/usr/bin/gpg-connect-agent KILLAGENT': General error


last program can arrive here:

               C   A   U   T   I   O   N                     

              This is first start of MSYS2.                 
   You MUST restart shell to apply necessary actions.        

Administrator@hybase MSYS /

ls

autorebase.bat clang64.ini home mingw32.ico msys2.exe proc uninstall.dat bin clangarm64 InstallationLog.txt mingw32.ini msys2.ico tmp uninstall.exe clang32 components.xml installer.dat mingw64 msys2.ini ucrt64 uninstall.ini clang64 dev installerResources mingw64.exe msys2_shell.cmd ucrt64.exe usr clang64.exe dir mingw32 mingw64.ico network.xml ucrt64.ico var clang64.ico etc mingw32.exe mingw64.ini opt ucrt64.ini

Administrator@hybase MSYS /

zymill commented 2 years ago

I have copy one null.sys from another normal PC (c:/windows/system32/driver/null.sys) overwrite current file. excute cmd in windows' cmd.exe : C:\Users\Administrator>sc start null [use "C:\Users\Administrator>sc query null" if you have started it ] SERVICE_NAME: null TYPE : 1 KERNEL_DRIVER STATE : 4 RUNNING (STOPPABLE, NOT_PAUSABLE, IGNORES_SHUTDOWN) WIN32_EXIT_CODE : 0 (0x0) SERVICE_EXIT_CODE : 0 (0x0) CHECKPOINT : 0x0 WAIT_HINT : 0x0 PID : 0 FLAGS : msys2 bash will do work if you can look these! I hope it will help you who encounter the same problem.