From: Erik Faye-Lund <kusmabite@gmail.com>
To: Johannes Sixt <j.sixt@viscovery.net>
Cc: Jeff King <peff@peff.net>, Junio C Hamano <gitster@pobox.com>,
Felipe Contreras <felipe.contreras@gmail.com>,
git@vger.kernel.org
Subject: Re: [PATCH] t0005: skip signal death exit code test on Windows
Date: Fri, 7 Jun 2013 14:46:01 +0200 [thread overview]
Message-ID: <CABPQNSasTdkmpeGWb7_wZK2cQhiOyF7bX5ObcBg5kHm0KBGS5w@mail.gmail.com> (raw)
In-Reply-To: <51B1CFD4.3030908@viscovery.net>
On Fri, Jun 7, 2013 at 2:19 PM, Johannes Sixt <j.sixt@viscovery.net> wrote:
> Am 6/7/2013 14:00, schrieb Erik Faye-Lund:
>> On Fri, Jun 7, 2013 at 12:24 PM, Johannes Sixt <j.sixt@viscovery.net> wrote:
>>> Am 6/7/2013 12:12, schrieb Erik Faye-Lund:
>>>> On Thu, Jun 6, 2013 at 7:40 PM, Jeff King <peff@peff.net> wrote:
>>>>> On Thu, Jun 06, 2013 at 10:21:47AM -0700, Junio C Hamano wrote:
>>>>>
>>>>>>> The particular deficiency is that when a signal is raise()d whose SIG_DFL
>>>>>>> action will cause process death (SIGTERM in this case), the
>>>>>>> implementation of raise() just calls exit(3).
>>>>>>
>>>>>> After a bit of web searching, it seems to me that this behaviour of
>>>>>> raise() is in msvcrt, and compat/mingw.c::mingw_raise() just calls
>>>>>> that. In other words, "the implementation of raise()" is at an even
>>>>>> lower level than mingw/msys, and I would agree that it is a platform
>>>>>> issue.
>>>>>
>>>>> Yeah, if it were mingw_raise responsible for this, I would suggest using
>>>>> the POSIX shell "128+sig" instead. We could potentially check for
>>>>> SIG_DFL[1] mingw_raise and intercept and exit there. I don't know if
>>>>> that would create headaches or confusion for other msys programs,
>>>>> though. I'd leave that up to the msysgit people to decide whether it is
>>>>> worth the trouble.
>>>>>
>>>>
>>>> ...and here's the code to do just that:
>>>>
>>>> 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:
--->8---
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
void my_handler(int signum)
{
printf("signal: %d\n", signum);
exit(1);
}
int main()
{
signal(SIGTERM, my_handler);
while (1);
return 0;
}
--->8---
This quietly kills the process on Windows with MSVCRT's
signal-implementation. In fact SIGTERM isn't raised on Linux either.
Ctrl+C raises SIGINT, not SIGTERM.
next prev parent reply other threads:[~2013-06-07 12:46 UTC|newest]
Thread overview: 104+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-06-04 23:45 What's cooking in git.git (Jun 2013, #02; Tue, 4) Junio C Hamano
2013-06-05 0:04 ` [Administrivia] On ruby and contrib/ Junio C Hamano
2013-06-05 3:02 ` David Lang
2013-06-05 14:30 ` Felipe Contreras
2013-06-05 4:13 ` Michael Haggerty
2013-06-05 17:41 ` Junio C Hamano
2013-06-06 12:52 ` Matthieu Moy
2013-06-07 16:11 ` Junio C Hamano
2013-06-06 19:48 ` Thomas Ferris Nicolaisen
2013-06-05 14:45 ` Felipe Contreras
2013-06-06 7:26 ` demerphq
2013-06-06 7:46 ` Felipe Contreras
2013-06-06 12:24 ` Barry Fishman
2013-06-06 13:01 ` Felipe Contreras
2013-06-06 13:46 ` Barry Fishman
2013-06-06 14:09 ` Felipe Contreras
2013-06-06 14:41 ` Barry Fishman
2013-06-06 15:04 ` Felipe Contreras
2013-06-06 20:41 ` Charles McGarvey
2013-06-06 14:54 ` Greg Troxel
2013-06-06 15:17 ` Felipe Contreras
2013-06-06 16:09 ` David Lang
2013-06-06 18:16 ` Felipe Contreras
2013-06-06 20:29 ` Ramkumar Ramachandra
2013-06-06 20:19 ` David Lang
2013-06-07 14:24 ` Ramkumar Ramachandra
2013-06-07 15:20 ` Junio C Hamano
2013-06-07 15:28 ` Ramkumar Ramachandra
2013-06-07 19:04 ` Felipe Contreras
2013-06-07 19:27 ` Ramkumar Ramachandra
2013-06-07 19:38 ` Ramkumar Ramachandra
2013-06-09 2:57 ` Johannes Schindelin
2013-06-09 9:16 ` Ramkumar Ramachandra
2013-06-09 23:29 ` Junio C Hamano
2013-06-10 4:56 ` Felipe Contreras
2013-06-07 19:55 ` Junio C Hamano
2013-06-07 20:24 ` Felipe Contreras
2013-06-08 2:23 ` Duy Nguyen
2013-06-08 10:08 ` Felipe Contreras
2013-06-08 11:20 ` Duy Nguyen
2013-06-08 12:06 ` Felipe Contreras
2013-06-07 19:21 ` Felipe Contreras
2013-06-06 17:16 ` Greg Troxel
2013-06-06 18:24 ` Felipe Contreras
2013-06-06 21:05 ` Ramkumar Ramachandra
2013-06-06 21:31 ` Dependencies and packaging (Re: [Administrivia] On ruby and contrib/) Jonathan Nieder
2013-06-07 19:29 ` Felipe Contreras
2013-06-06 16:22 ` [Administrivia] On ruby and contrib/ Johannes Schindelin
2013-06-06 20:40 ` Ramkumar Ramachandra
2013-06-07 3:25 ` Johannes Schindelin
2013-06-07 15:20 ` Ramkumar Ramachandra
2013-06-07 17:57 ` Matthieu Moy
2013-06-07 18:14 ` Ramkumar Ramachandra
2013-06-07 18:24 ` Ramkumar Ramachandra
2013-06-07 18:32 ` Matthieu Moy
2013-06-07 18:48 ` Ramkumar Ramachandra
2013-06-07 19:00 ` Matthieu Moy
2013-06-07 19:10 ` Felipe Contreras
2013-06-07 18:33 ` Jonathan Nieder
2013-06-07 18:45 ` Matthew Ruffalo
2013-06-07 18:28 ` Junio C Hamano
2013-06-07 19:14 ` Felipe Contreras
2013-06-07 19:41 ` Ramkumar Ramachandra
2013-06-09 2:59 ` Johannes Schindelin
2013-06-08 2:17 ` Duy Nguyen
2013-06-08 10:02 ` Felipe Contreras
2013-06-08 11:28 ` Duy Nguyen
2013-06-08 11:56 ` Felipe Contreras
2013-06-08 12:07 ` Duy Nguyen
2013-06-08 13:20 ` Felipe Contreras
2013-06-08 17:15 ` Jeff King
2013-06-08 17:40 ` Felipe Contreras
2013-06-09 0:10 ` Jeff King
2013-06-09 1:17 ` Felipe Contreras
2013-06-09 2:23 ` Jeff King
2013-06-09 2:41 ` Felipe Contreras
2013-06-09 3:07 ` Johannes Schindelin
2013-06-05 6:59 ` What's cooking in git.git (Jun 2013, #02; Tue, 4) Johannes Sixt
2013-06-05 7:12 ` Jeff King
2013-06-06 6:34 ` [PATCH] t0005: skip signal death exit code test on Windows Johannes Sixt
2013-06-06 6:37 ` Jeff King
2013-06-06 6:41 ` Felipe Contreras
2013-06-06 6:44 ` Jeff King
2013-06-06 6:48 ` Felipe Contreras
2013-06-06 17:21 ` Junio C Hamano
2013-06-06 17:40 ` Jeff King
2013-06-07 6:22 ` Johannes Sixt
2013-06-07 10:12 ` Erik Faye-Lund
2013-06-07 10:24 ` Johannes Sixt
2013-06-07 12:00 ` Erik Faye-Lund
2013-06-07 12:19 ` Johannes Sixt
2013-06-07 12:46 ` Erik Faye-Lund [this message]
2013-06-07 13:07 ` Johannes Sixt
2013-06-07 14:20 ` Erik Faye-Lund
2013-06-10 5:48 ` [PATCH] mingw: make mingw_signal return the correct handler Johannes Sixt
2013-06-10 11:37 ` Erik Faye-Lund
2013-06-10 20:50 ` Junio C Hamano
2013-06-09 0:18 ` [PATCH] t0005: skip signal death exit code test on Windows Jeff King
2013-06-09 20:31 ` Junio C Hamano
2013-06-10 5:30 ` Johannes Sixt
2013-06-10 11:38 ` Erik Faye-Lund
2013-06-06 18:32 ` Felipe Contreras
2013-06-07 10:01 ` Erik Faye-Lund
2013-06-07 10:03 ` Erik Faye-Lund
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CABPQNSasTdkmpeGWb7_wZK2cQhiOyF7bX5ObcBg5kHm0KBGS5w@mail.gmail.com \
--to=kusmabite@gmail.com \
--cc=felipe.contreras@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=j.sixt@viscovery.net \
--cc=peff@peff.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).