Menu

#135 signal handling seems broken

1.0
wont-fix
nobody
2015-11-02
2015-02-23
No

I can't seem to ctrl-c kill golang tests (go test ...) programs that I run in my msys2 terminal. go test programs are run as a child process of go.

I thought it was a bug with Go, but they seem to think this kind of stuff is a bug in the shell.
E.g., here https://github.com/golang/go/issues/4347 they say CYGWIN does not forward the signals properly. This was back in 2012 though...

As an experiment, I grabbed a small signal testing program:

#include <stdio.h>
#include <signal.h>
#include <unistd.h>

void sig_handler(int signo) {
    printf("sig %d\n", signo);
    fflush(stdout);
}

int main(void) {
    if (signal(SIGINT, sig_handler) == SIG_ERR) {
        printf("\ncan't catch SIGINT\n");
    }
    while(1) 
    sleep(1);
    return 0;
}

Here's what happens when I run it in msys2, and hit ctrl-c

user@user-PC /d/prog/signal
$ gcc signal.c && ./a.exe

user@user-PC /d/prog/signal

So it doesn't look like the signal is really being sent; the program is just killed.

Here's what happens when I run the exact same executable in cmd.exe:

D:\prog\signal>a.exe
sig 2
^C
D:\prog\signal>

(I had to hit ctrl-c twice to really quit)

So is signal handling just busted in msys2? It seems like there may be issues with native windows processes receiving signals (like in go's case), but why would my own process compiled with gcc not be able to receive signals inside the msys2 shell? In the first case, perhaps you could see if the running programs were a native program, and if so, send the appropriate message instead of signal? In the second case, I don't know what's going on. I'm also not entirely clear about the distinction between CYGWIN/msys2/MinGW, so please redirect me if need be.

FWIW, I'm running msys2 that was installed from msys2-x86_64-20141113.exe

Discussion

  • Alexx83

    Alexx83 - 2015-02-23

    As MSYS2 is derived from Cygwin it have the same issues.

     
  • David Macek

    David Macek - 2015-04-19

    Do you still see the same issue? I compiled this program and I see one "sig 2" per every ^C pressed (the program does not exit) in both mintty and Windows console.

    I'm using msys2-runtime 2.1.0.16305.2579661-2.

     
  • Chucky Ellison

    Chucky Ellison - 2015-04-20

    I updated everything. msys2-runtime is at 2.1.0.16305.2579661-2; mintty is at mintty svn-trunk-r1322 (x86_64-pc-msys).

    I still see the same issue. Using mintty, I do not see any ^Cs, the program just immediately exits when I hit control-c. Using windows console, I only see the first ^C, the second causes the program to quit. I'm on windows 7; perhaps this is different in different versions of windows.

     
  • David Macek

    David Macek - 2015-04-20

    Oh, I'm sorry. I compiled using msys2-gcc. I see what you see, when I compile using mingw.

    It seems mintty is really somehow eating the Ctrl+C's.

     
  • David Macek

    David Macek - 2015-04-20

    Given the huge amount of results for "mintty ctrl c" on Google, regarding both Cygwin and mintty, I'm not sure who's to blame. Running the program inside bash in a regular Windows console gives "sig 2", so it seems to be tied to something mintty does. Running the program as wintpy ./a reverses the effect.

     
  • Jens Frederich

    Jens Frederich - 2015-10-30

    Any update?

    I've the same issue. For instance run cdb (Debugging Tools for Windows) inside a Mintty bash shell. Cdb use Ctrl-C to stop debugging, but on Ctrl-C my complete debugging session is kill!

    v% cdb foo.exe
    
    Microsoft (R) Windows Debugger Version 6.3.9600.17336 AMD64
    Copyright (c) Microsoft Corporation. All rights reserved.
    
    CommandLine: CANape32.exe
    Symbol search path is: *** Invalid ***
    ****************************************************************************
    * Symbol loading may be unreliable without a symbol search path.           *
    * Use .symfix to have the debugger choose a symbol path.                   *
    * After setting your symbol path, use .reload to refresh symbol locations. *
    ****************************************************************************
    Executable search path is:
    ModLoad: 00000000`001d0000 00000000`0dfdc000   foo.exe
    ModLoad: 00000000`77100000 00000000`772a9000   ntdll.dll
    ModLoad: 00000000`772e0000 00000000`77460000   ntdll32.dll
    ModLoad: 00000000`72c90000 00000000`72ccf000   C:\Windows\SYS
    (1758.15b0): Break instruction exception - code 80000003 (first chance)
    *** ERROR: Symbol file could not be found.  Defaulted to export symbols for ntdll.dll -
    ntdll!CsrSetPriorityClass+0x40:
    00000000`771a6d50 cc              int     3
    0:000> g
    ModLoad: 00000000`6ab00000 00000000`6abf5000   C:\Windows\SysWOW64\propsys.dll
    ModLoad: 00000000`6d470000 00000000`6d491000   C:\Windows\SysWOW64\ntmarta.dll
    ModLoad: 00000000`768f0000 00000000`76935000   C:\Windows\syswow64\WLDAP32.dll
    
    ^^^^ hit CTRL-C kills my debug session
    v%
    
    correct behaviour on Dos Box:
    
    ^^^^ hit CTRL-C stop at debugger
    (1184.15e0): Break instruction exception - code 80000003 (first chance)
    ntdll!DbgBreakPoint:
    00000000`7714b110 cc              int     3
    0:013>
    
     
  • Jens Frederich

    Jens Frederich - 2015-10-30

    That's a mintty issue. I've tried Cygwin inside a Dos Box and Cygwin inside a Mintty terminal. The Dos Box handles the Ctrl-C signal correct, Mintty not.

     
  • Jens Frederich

    Jens Frederich - 2015-10-30

    Mintty and urxvt have the same issue. Only Cygwin bash via Dos Box works.

     
  • David Macek

    David Macek - 2015-11-02

    Please don't call the Windows terminal "Dos Box", this only confuses people (DOSBox is an unrelated product).

    Taking mintty's comment into account, this is either an issue common in mintty and urxvt, or an underlying issue in Cygwin. Either way, it seems there's little incentive for anyone to work on this, possibly because there's no clear solution. I suggest you first try looking around the Internet or digging into the code to find out what exactly makes mintty/urxvt kill processes upon Ctrl+C instead of passing the right signal. A discussion pointing to a specific piece of code will be more effective in persuading people to join and help.

     
  • Jens Frederich

    Jens Frederich - 2015-11-02

    I'm a user and as user I want to execute each command line program via terminal and expect right behaviour. The terminal should handle all signals well. No matter whether is it a Unix based or Windows pty based signal.

    It's not possible to come up with code. Cdb is Microsoft closed source tool.

    Perpaps this tool [winpty]https://github.com/rprichard/winpty) fills the gap.

     
  • David Macek

    David Macek - 2015-11-02

    As a user of free open-source software maintaned by volunteers, you should also understand that not every user wish can be fulfilled. I'm not saying the current situation is ideal, but it's not bad enough to get much developer attention.

    Also, keep in mind that mintty is not advertised as a universal terminal. Its author tries to make it very clear that it's designed to work with Cygwin/MSYS2, and full compatibility with native Windows programs is not among the project's goals.

    I was talking about the code of Cygwin and mintty.

    If you're okay with using winpty, that should solve the problem for you. I assumed that you didn't want to use it, as you didn't react to me mentioning it.

     
  • Jens Frederich

    Jens Frederich - 2015-11-02

    It's a very unreal working scenario that I use one terminal for Unix like tools and another terminal for Dos tools. Sorry, I do claim that the most user mixing MSYS2 binaries with native Windows binaries in the same session.

    Winpty works well and fills the gap. Please place a note at the MSYS2 FAQ for the next one which fall for it. Thanks.

    MSYS2 is a very good environment, I like it really.

     
  • David Macek

    David Macek - 2015-11-02
    • status: open --> wont-fix
     
  • Jens Frederich

    Jens Frederich - 2015-11-02

    No no it's a create tool suite and I use it every day and stay happy!