Re: [PATCH] t0005: skip signal death exit code test on Windows

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, Jun 7, 2013 at 3:07 PM, Johannes Sixt <j.sixt@xxxxxxxxxxxxx> wrote:
> Am 6/7/2013 14:46, schrieb Erik Faye-Lund:
>> On Fri, Jun 7, 2013 at 2:19 PM, Johannes Sixt <j.sixt@xxxxxxxxxxxxx> wrote:
>>> Am 6/7/2013 14:00, schrieb Erik Faye-Lund:
>>>> On Fri, Jun 7, 2013 at 12:24 PM, Johannes Sixt <j.sixt@xxxxxxxxxxxxx> wrote:
>>>>> Am 6/7/2013 12:12, schrieb Erik Faye-Lund:
>>>>>> diff --git a/compat/mingw.c b/compat/mingw.c
>>>>>> index b295e2f..8b3c1b4 100644
>>>>>> --- a/compat/mingw.c
>>>>>> +++ b/compat/mingw.c
>>>>>> @@ -1573,7 +1573,8 @@ static HANDLE timer_event;
>>>>>>  static HANDLE timer_thread;
>>>>>>  static int timer_interval;
>>>>>>  static int one_shot;
>>>>>> -static sig_handler_t timer_fn = SIG_DFL, sigint_fn = SIG_DFL;
>>>>>> +static sig_handler_t timer_fn = SIG_DFL, sigint_fn = SIG_DFL,
>>>>>> +    sigterm_fn = SIG_DFL;
>>>>>>
>>>>>>  /* The timer works like this:
>>>>>>   * The thread, ticktack(), is a trivial routine that most of the time
>>>>>> @@ -1688,6 +1689,10 @@ sig_handler_t mingw_signal(int sig,
>>>>>> sig_handler_t handler)
>>>>>>               sigint_fn = handler;
>>>>>>               break;
>>>>>>
>>>>>> +     case SIGTERM:
>>>>>> +             sigterm_fn = handler;
>>>>>> +             break;
>>>>>> +
>>>>>>       default:
>>>>>>               return signal(sig, handler);
>>>>>>       }
>>>>>> @@ -1715,6 +1720,13 @@ int mingw_raise(int sig)
>>>>>>                       sigint_fn(SIGINT);
>>>>>>               return 0;
>>>>>>
>>>>>> +     case SIGTERM:
>>>>>> +             if (sigterm_fn == SIG_DFL)
>>>>>> +                     exit(128 + SIGTERM);
>>>>>> +             else if (sigterm_fn != SIG_IGN)
>>>>>> +                     sigterm_fn(SIGTERM);
>>>>>> +             return 0;
>>>>>> +
>>>>>>       default:
>>>>>>               return raise(sig);
>>>>>>       }
>>>>>
>>>>> That's pointless and does not work. The handler would only be called when
>>>>> raise() is called, but not when a SIGTERM is received, e.g., via Ctrl-C
>>>>> from the command line, because that route ends up in MSVCRT, which does
>>>>> not know about this handler.
>>>>
>>>> That's not entirely true. On Windows, there's only *one* way to
>>>> generate SIGTERM; "signal(SIGTERM)". Ctrl+C does not generate SIGTERM.
>>>> We generate SIGINT on Ctrl+C in mingw_fgetc, but the default Control+C
>>>> handler routine calls ExitProcess():
>>>> http://msdn.microsoft.com/en-us/library/windows/desktop/ms683242(v=vs.85).aspx
>>>
>>> But a call to signal(SIGTERM, my_handler) should divert Ctrl+C to
>>> my_handler. The unpatched version does, because MSVCRT now knows about
>>> my_handler and sets things up so that the event handler calls my_handler.
>>
>> No, it does not:
>> Ctrl+C raises SIGINT, not SIGTERM.
>
> <action type="slap" destination="forehead"/>
>
> You are right. Your change would "fix" SIGTERM as it can be raised only
> via raise() on Windows nor can it be caught when a process is killed via
> mingw_kill(...,SIGTERM) by another process.
>
> But then the current handling of SIGINT in compat/mingw.c is broken. The
> handler is not propagated to MSVCRT, and after a SIGINT handler is
> installed, Ctrl+C still terminates the process. No?

Yeah, probably. I wasn't aware that it handled SIGINT, but yeah it
does. So this was indeed a regression.

> BTW, isn't mingw_signal() bogus in that it returns the SIGALRM handler
> even if a SIGINT handler is installed?

Yep, that's a bug. Thanks for noticing.

I've pushed out a branch here that tries to address these issues, but
I haven't had time to test them. I'll post the series when I have. In
the mean time:

https://github.com/kusma/git/tree/win32-signal-raise
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]