skeeto / w64devkit

Portable C and C++ Development Kit for x64 (and x86) Windows
The Unlicense
2.68k stars 185 forks source link

Launching the BusyBox shell from Windows' CMD or PowerShell and pressing Ctrl+C will overlap both shells #95

Open Semphriss opened 7 months ago

Semphriss commented 7 months ago

I noticed this when trying to setup for myself an easy-to-use shell environment.

If I open a CMD or PowerShell window, and then launch bash.exe from the command line, and then I press Ctrl+C, it will appear like both CMD/PowerShell and the BusyBox shell will fight for my terminal. Both will print their prefixes at the same time, and it seems that each of my keystrokes is sent in alternance to each shell, so if I were to type "exit" and enter, one shell would get "xt" and the other "ei" and enter. The terminal becomes essentially unusable.

The Ctrl+C bug passes through any running command, so if I'm within the BusyBox shell running another program like GCC or even sleep 10, just one Ctrl+C will both interrupt the running program as expected, and cause the bug I describe. Pressing Ctrl+C more times does not appear to change anything, the only way that I'm aware of to work around the problem is to close and reopen the terminal.

Straightforward reproduction steps:

  1. Launch CMD or Powershell
  2. From the shell, execute BusyBox's bash.exe or sh.exe
  3. Optionally, launch a program that takes time, like sleep 10
  4. Press Ctrl+C once

The effects should be immediately visible; pressing return a few times shows the clash between the shells.

I'm not entirely sure where is the most relevant place to report this issue since I'm not sure what's in cause here; I can bump the bug report to BusyBox or elsewhere if needed.

rmyorston commented 7 months ago

Ctrl+C is a long-standing problem in the Windows port of BusyBox.

Instead of using the alias binaries I recommend starting the shell with busybox sh; the fewer processes involved the better.

Peter0x44 commented 7 months ago

Well I suppose the "intended" way for w64devkit is to start w64devkit.exe and not go though cmd at all Doesn't seem like a w64devkit issue

Semphriss commented 7 months ago

Indeed, although when using IDEs like VSCode, the embedded terminal automatically opens PowerShell, and I have to use that to open w64devkit, so I would say I'm stuck with that scenario, unless there is some way to work around it.

It may be a BusyBox issue more than a w64devkit issue, but I would definitely consider it an issue. For the same reason that if I open Dash from Bash, I expect Dash to properly catch keyboards interrupts, I would expect any shell that is called from a different shell to either properly catch interrupts or, if it's not possible for some reason, to not attempt to catch them at all and exit immediately. I think that opening a shell from another one is a use case that's regular enough to warrant supporting within w64devkit, or at least attempting to.

rmyorston commented 7 months ago

We don't want the w64devkit alias to react to Ctrl+C.

Patch: alias.txt