public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* Ctrl-Break killing subprocess even though handled in parent process
@ 2017-05-13 10:21 Brien Oberstein
  2017-05-13 16:20 ` Andrey Repin
  2017-05-13 16:45 ` Brian Inglis
  0 siblings, 2 replies; 4+ messages in thread
From: Brien Oberstein @ 2017-05-13 10:21 UTC (permalink / raw)
  To: cygwin

Hi,

I have a dotnet windows console application that runs a bash script as a
subprocess using CreateProcess()  under the covers.

My windows app traps Ctrl-Break via SetConsoleCtrlHandler() and handles it
(returning true from the handler).

I execute the script via the command "bash.exe --login script.sh".

Somehow the Ctrl-Break is reaching the subprocess and causing it to be
killed, which is undesireable.

Is there a way to either prevent the Ctrl-Break from reaching the cygwin
subprocess or telling cygwin/bash to ignore it?

Thanks,
Brien


--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Ctrl-Break killing subprocess even though handled in parent process
  2017-05-13 10:21 Ctrl-Break killing subprocess even though handled in parent process Brien Oberstein
@ 2017-05-13 16:20 ` Andrey Repin
  2017-05-13 16:45 ` Brian Inglis
  1 sibling, 0 replies; 4+ messages in thread
From: Andrey Repin @ 2017-05-13 16:20 UTC (permalink / raw)
  To: Brien Oberstein, cygwin

Greetings, Brien Oberstein!

> I have a dotnet windows console application that runs a bash script as a
> subprocess using CreateProcess()  under the covers.

> My windows app traps Ctrl-Break via SetConsoleCtrlHandler() and handles it
> (returning true from the handler).

> I execute the script via the command "bash.exe --login script.sh".

> Somehow the Ctrl-Break is reaching the subprocess and causing it to be
> killed, which is undesireable.

> Is there a way to either prevent the Ctrl-Break from reaching the cygwin
> subprocess or telling cygwin/bash to ignore it?

You will be laughing, but I just stumbled upon this issue myself with
TCC+bash -i. When I press ^Break in bash prompt, parent TCC dies.


-- 
With best regards,
Andrey Repin
Saturday, May 13, 2017 18:53:59

Sorry for my terrible english...


--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Ctrl-Break killing subprocess even though handled in parent process
  2017-05-13 10:21 Ctrl-Break killing subprocess even though handled in parent process Brien Oberstein
  2017-05-13 16:20 ` Andrey Repin
@ 2017-05-13 16:45 ` Brian Inglis
  2017-05-14 13:53   ` Brien Oberstein
  1 sibling, 1 reply; 4+ messages in thread
From: Brian Inglis @ 2017-05-13 16:45 UTC (permalink / raw)
  To: cygwin

On 2017-05-13 03:42, Brien Oberstein wrote:
> I have a dotnet windows console application that runs a bash script
> as a subprocess using CreateProcess() under the covers.
> My windows app traps Ctrl-Break via SetConsoleCtrlHandler() and
> handles it (returning true from the handler).
> I execute the script via the command "bash.exe --login script.sh".
> Somehow the Ctrl-Break is reaching the subprocess and causing it to
> be killed, which is undesireable.
> Is there a way to either prevent the Ctrl-Break from reaching the
> cygwin subprocess or telling cygwin/bash to ignore it?

Add to top of script: 
trap '' SIGINT SIGTERM
does equivalent of SIG_IGN (do nothing) on named signals. 

$ info bash trap
or
$ help trap
in bash gives you more info. 

Watch out for subshells, as signals are reset in subshells, 
so you will need to set up the trap in all subshells.

-- 
Take care. Thanks, Brian Inglis, Calgary, Alberta, Canada

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 4+ messages in thread

* RE: Ctrl-Break killing subprocess even though handled in parent process
  2017-05-13 16:45 ` Brian Inglis
@ 2017-05-14 13:53   ` Brien Oberstein
  0 siblings, 0 replies; 4+ messages in thread
From: Brien Oberstein @ 2017-05-14 13:53 UTC (permalink / raw)
  To: Brian.Inglis, cygwin

Hi Brian,

You know, I thought I tried this already, but somehow now its working.

Thanks!

-----Original Message-----
From: Brian Inglis [mailto:Brian.Inglis@SystematicSw.ab.ca] 
Sent: Saturday, May 13, 2017 12:29 PM
To: cygwin@cygwin.com
Subject: Re: Ctrl-Break killing subprocess even though handled in parent process

On 2017-05-13 03:42, Brien Oberstein wrote:
> I have a dotnet windows console application that runs a bash script
> as a subprocess using CreateProcess() under the covers.
> My windows app traps Ctrl-Break via SetConsoleCtrlHandler() and
> handles it (returning true from the handler).
> I execute the script via the command "bash.exe --login script.sh".
> Somehow the Ctrl-Break is reaching the subprocess and causing it to
> be killed, which is undesireable.
> Is there a way to either prevent the Ctrl-Break from reaching the
> cygwin subprocess or telling cygwin/bash to ignore it?

Add to top of script: 
trap '' SIGINT SIGTERM
does equivalent of SIG_IGN (do nothing) on named signals. 

$ info bash trap
or
$ help trap
in bash gives you more info. 

Watch out for subshells, as signals are reset in subshells, 
so you will need to set up the trap in all subshells.

-- 
Take care. Thanks, Brian Inglis, Calgary, Alberta, Canada


--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2017-05-14 13:43 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-05-13 10:21 Ctrl-Break killing subprocess even though handled in parent process Brien Oberstein
2017-05-13 16:20 ` Andrey Repin
2017-05-13 16:45 ` Brian Inglis
2017-05-14 13:53   ` Brien Oberstein

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).