public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* Cygwin 1.7.x on Windows 7: Exit statuses of Win32 executables are sometimes wrong
@ 2011-04-29 20:01 John Dong
  2011-04-30 11:30 ` Edward McGuire
                   ` (3 more replies)
  0 siblings, 4 replies; 10+ messages in thread
From: John Dong @ 2011-04-29 20:01 UTC (permalink / raw)
  To: cygwin

Hi,

Cygwin on Windows 7, seems to exhibit a rather peculiar behavior: Sometimes the exit status of a Win32 process is incorrectly captured by Cygwin.

I'm running Cygwin 1.7.9(0.237/5/3) on Windows 7 64-bit, but I've reproduced this behavior with every release of Cygwin 1.7 on both 32-bit and 64-bit Windows 7. It does not seem to happen in XP 32-bit, and I've not tried any other environments.


To reproduce, first I wrote a Win32 console application (using Visual Studio 2010 / cl.exe version 16 as my compiler) that exits with the status the user passes in:

> int _tmain(int argc, _TCHAR* argv[])
> {
> 	int ret = _ttoi(argv[1]);
> 	_tprintf(_T("Exiting with %i\n"), ret); 
> 	
> 	return ret;
> }


Then, I wrote a shell script that called this executable ("exiter.exe") with argument 0 in an infinite loop:

> #!/bin/sh
> set -e
> while true; do
>  /cygdrive/c/exiter.exe 0
> echo $?
> done
> 

I expect this script to run forever, as the exit code should always be zero. However, after running this overnight, I see the script terminate:

> Exiting with 0
> 0
> Exiting with 0
> 0
> Exiting with 0
> 0
> Exiting with 0
> 0
> Exiting with 0
> 
> $ echo $?
> 1
> 



The last line of output implies that exiter.exe executed "return 0", but /bin/sh saw a nonzero exit status (of 1) and thus stopped execution due to -e.

Reproducing this seems nondeterministic -- sometimes I can get it to happen in 5 minutes, other times it takes overnight. I've tried using a different shell (like dash), but it doesn't make a difference, leading me to suspect this to be a lower-level issue within the Cygwin DLL. It also seems to not happen for non-zero exit codes (e.g. checking that exiter.exe 1 returns 1 always seems to succeed), though I'm not 100% confident that I've tested this thoroughly enough.

Again, I've not been able to reproduce this under Windows XP using any version of Cygwin, but I have been able to reproduce it on both 32-bit and 64-bit Windows 7. I'm not running anything special on this machine -- it's a fresh install of Windows 7 Professional, just with Cygwin installed.


Thanks in advance,

John


--
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] 10+ messages in thread

* Re: Cygwin 1.7.x on Windows 7: Exit statuses of Win32 executables are sometimes wrong
  2011-04-29 20:01 Cygwin 1.7.x on Windows 7: Exit statuses of Win32 executables are sometimes wrong John Dong
@ 2011-04-30 11:30 ` Edward McGuire
  2011-04-30 13:23   ` John Dong
  2011-05-10 17:22 ` John Dong
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 10+ messages in thread
From: Edward McGuire @ 2011-04-30 11:30 UTC (permalink / raw)
  To: cygwin

On Fri, Apr 29, 2011 at 13:35, John Dong <jdong@apple.com> wrote:
>I've tried using a different shell (like dash), but it doesn't make a difference, leading me to suspect this to be a lower-level issue within the Cygwin DLL.
Have you tried it with the stock Windows command processor? Something
like this (untested) script?

@echo off
:redo
rem c:\path\to\exiter.exe 0
if errorlevel 1 exit /b %errorlevel%
echo %errorlevel%
goto:redo

--
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] 10+ messages in thread

* Re: Cygwin 1.7.x on Windows 7: Exit statuses of Win32 executables are sometimes wrong
  2011-04-30 11:30 ` Edward McGuire
@ 2011-04-30 13:23   ` John Dong
  2011-05-02 17:18     ` John Dong
  0 siblings, 1 reply; 10+ messages in thread
From: John Dong @ 2011-04-30 13:23 UTC (permalink / raw)
  To: Edward McGuire; +Cc: cygwin

Hi Edward,

Yeah, I forgot to mention that I tried scripting it in a batch file outside cygwin in much the same way as your script, and it ran for a day or two without fail. I can keep that going for longer just in case it fails less frequently, but I don't think it's a Windows / MSVCRT bug.


John


On Apr 29, 2011, at 2:04 PM, Edward McGuire wrote:

> On Fri, Apr 29, 2011 at 13:35, John Dong <jdong@apple.com> wrote:
>> I've tried using a different shell (like dash), but it doesn't make a difference, leading me to suspect this to be a lower-level issue within the Cygwin DLL.
> Have you tried it with the stock Windows command processor? Something
> like this (untested) script?
> 
> @echo off
> :redo
> rem c:\path\to\exiter.exe 0
> if errorlevel 1 exit /b %errorlevel%
> echo %errorlevel%
> goto:redo
> 
> --
> 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
> 


--
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] 10+ messages in thread

* Re: Cygwin 1.7.x on Windows 7: Exit statuses of Win32 executables are sometimes wrong
  2011-04-30 13:23   ` John Dong
@ 2011-05-02 17:18     ` John Dong
  0 siblings, 0 replies; 10+ messages in thread
From: John Dong @ 2011-05-02 17:18 UTC (permalink / raw)
  To: Edward McGuire; +Cc: cygwin

Hi Edward,

For what it's worth, I just left it running since my last reply and it's still running. I can fairly confidently say this only happens when executing a Windows binary from Cygwin.

Any insights or suggestions of further things to test would be greatly appreciated. These kinds of bugs certainly aren't fun to chase down.


John


On Apr 29, 2011, at 5:29 PM, John Dong wrote:

> Hi Edward,
> 
> Yeah, I forgot to mention that I tried scripting it in a batch file outside cygwin in much the same way as your script, and it ran for a day or two without fail. I can keep that going for longer just in case it fails less frequently, but I don't think it's a Windows / MSVCRT bug.
> 
> 
> John
> 
> 
> On Apr 29, 2011, at 2:04 PM, Edward McGuire wrote:
> 
>> On Fri, Apr 29, 2011 at 13:35, John Dong <jdong@apple.com> wrote:
>>> I've tried using a different shell (like dash), but it doesn't make a difference, leading me to suspect this to be a lower-level issue within the Cygwin DLL.
>> Have you tried it with the stock Windows command processor? Something
>> like this (untested) script?
>> 
>> @echo off
>> :redo
>> rem c:\path\to\exiter.exe 0
>> if errorlevel 1 exit /b %errorlevel%
>> echo %errorlevel%
>> goto:redo
>> 
>> --
>> 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
>> 
> 
> 
> --
> 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
> 


--
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] 10+ messages in thread

* Re: Cygwin 1.7.x on Windows 7: Exit statuses of Win32 executables are sometimes wrong
  2011-04-29 20:01 Cygwin 1.7.x on Windows 7: Exit statuses of Win32 executables are sometimes wrong John Dong
  2011-04-30 11:30 ` Edward McGuire
@ 2011-05-10 17:22 ` John Dong
  2011-05-25 14:16 ` Edward Lam
  2011-05-26  6:02 ` Corinna Vinschen
  3 siblings, 0 replies; 10+ messages in thread
From: John Dong @ 2011-05-10 17:22 UTC (permalink / raw)
  To: cygwin

I can still reproduce this on the latest snapshot. I also tried some different hardware and virtual machines too, and I don't think my machine is to blame.

Has anyone else been able to reproduce this bug? Or have pointers of further things I can do to diagnose it?


Thanks in advance,

John

On Apr 29, 2011, at 11:35 AM, John Dong wrote:

> Hi,
> 
> Cygwin on Windows 7, seems to exhibit a rather peculiar behavior: Sometimes the exit status of a Win32 process is incorrectly captured by Cygwin.
> 
> I'm running Cygwin 1.7.9(0.237/5/3) on Windows 7 64-bit, but I've reproduced this behavior with every release of Cygwin 1.7 on both 32-bit and 64-bit Windows 7. It does not seem to happen in XP 32-bit, and I've not tried any other environments.
> 
> 
> To reproduce, first I wrote a Win32 console application (using Visual Studio 2010 / cl.exe version 16 as my compiler) that exits with the status the user passes in:
> 
>> int _tmain(int argc, _TCHAR* argv[])
>> {
>> 	int ret = _ttoi(argv[1]);
>> 	_tprintf(_T("Exiting with %i\n"), ret); 
>> 	
>> 	return ret;
>> }
> 
> 
> Then, I wrote a shell script that called this executable ("exiter.exe") with argument 0 in an infinite loop:
> 
>> #!/bin/sh
>> set -e
>> while true; do
>> /cygdrive/c/exiter.exe 0
>> echo $?
>> done
>> 
> 
> I expect this script to run forever, as the exit code should always be zero. However, after running this overnight, I see the script terminate:
> 
>> Exiting with 0
>> 0
>> Exiting with 0
>> 0
>> Exiting with 0
>> 0
>> Exiting with 0
>> 0
>> Exiting with 0
>> 
>> $ echo $?
>> 1
>> 
> 
> 
> 
> The last line of output implies that exiter.exe executed "return 0", but /bin/sh saw a nonzero exit status (of 1) and thus stopped execution due to -e.
> 
> Reproducing this seems nondeterministic -- sometimes I can get it to happen in 5 minutes, other times it takes overnight. I've tried using a different shell (like dash), but it doesn't make a difference, leading me to suspect this to be a lower-level issue within the Cygwin DLL. It also seems to not happen for non-zero exit codes (e.g. checking that exiter.exe 1 returns 1 always seems to succeed), though I'm not 100% confident that I've tested this thoroughly enough.
> 
> Again, I've not been able to reproduce this under Windows XP using any version of Cygwin, but I have been able to reproduce it on both 32-bit and 64-bit Windows 7. I'm not running anything special on this machine -- it's a fresh install of Windows 7 Professional, just with Cygwin installed.
> 
> 
> Thanks in advance,
> 
> John
> 
> 
> --
> 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
> 


--
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] 10+ messages in thread

* Re: Cygwin 1.7.x on Windows 7: Exit statuses of Win32 executables are sometimes wrong
  2011-04-29 20:01 Cygwin 1.7.x on Windows 7: Exit statuses of Win32 executables are sometimes wrong John Dong
  2011-04-30 11:30 ` Edward McGuire
  2011-05-10 17:22 ` John Dong
@ 2011-05-25 14:16 ` Edward Lam
  2011-05-25 14:20   ` Christopher Faylor
  2011-05-26  6:02 ` Corinna Vinschen
  3 siblings, 1 reply; 10+ messages in thread
From: Edward Lam @ 2011-05-25 14:16 UTC (permalink / raw)
  To: cygwin

On 29/04/2011 2:35 PM, John Dong wrote:
> Reproducing this seems nondeterministic -- sometimes I can get it to
> happen in 5 minutes, other times it takes overnight. I've tried using
> a different shell (like dash), but it doesn't make a difference,
> leading me to suspect this to be a lower-level issue within the
> Cygwin DLL. It also seems to not happen for non-zero exit codes (e.g.
> checking that exiter.exe 1 returns 1 always seems to succeed), though
> I'm not 100% confident that I've tested this thoroughly enough.
>
> Again, I've not been able to reproduce this under Windows XP using
> any version of Cygwin, but I have been able to reproduce it on both
> 32-bit and 64-bit Windows 7. I'm not running anything special on this
> machine -- it's a fresh install of Windows 7 Professional, just with
> Cygwin installed.

FWIW, we've been running into this as well. It appears to NOT be a 
problem with Cygwin 1.5 on Windows 7. It only started happening on 
Cygwin 1.7. As a result, we haven't had a reliable Windows 7 build 
machine for a while now because we use a Cygwin gmake process that 
compiles with MSVC.

-Edward

--
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] 10+ messages in thread

* Re: Cygwin 1.7.x on Windows 7: Exit statuses of Win32 executables are sometimes wrong
  2011-05-25 14:16 ` Edward Lam
@ 2011-05-25 14:20   ` Christopher Faylor
  2011-05-26  2:20     ` John Dong
  0 siblings, 1 reply; 10+ messages in thread
From: Christopher Faylor @ 2011-05-25 14:20 UTC (permalink / raw)
  To: cygwin

On Wed, May 25, 2011 at 10:16:03AM -0400, Edward Lam wrote:
>On 29/04/2011 2:35 PM, John Dong wrote:
>> Reproducing this seems nondeterministic -- sometimes I can get it to
>> happen in 5 minutes, other times it takes overnight. I've tried using
>> a different shell (like dash), but it doesn't make a difference,
>> leading me to suspect this to be a lower-level issue within the
>> Cygwin DLL. It also seems to not happen for non-zero exit codes (e.g.
>> checking that exiter.exe 1 returns 1 always seems to succeed), though
>> I'm not 100% confident that I've tested this thoroughly enough.
>>
>> Again, I've not been able to reproduce this under Windows XP using
>> any version of Cygwin, but I have been able to reproduce it on both
>> 32-bit and 64-bit Windows 7. I'm not running anything special on this
>> machine -- it's a fresh install of Windows 7 Professional, just with
>> Cygwin installed.
>
>FWIW, we've been running into this as well. It appears to NOT be a 
>problem with Cygwin 1.5 on Windows 7. It only started happening on 
>Cygwin 1.7. As a result, we haven't had a reliable Windows 7 build 
>machine for a while now because we use a Cygwin gmake process that 
>compiles with MSVC.

As always: http://cygwin.com/acronyms#PTC

--
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] 10+ messages in thread

* Re: Cygwin 1.7.x on Windows 7: Exit statuses of Win32 executables are sometimes wrong
  2011-05-25 14:20   ` Christopher Faylor
@ 2011-05-26  2:20     ` John Dong
  2011-05-26  5:47       ` Christopher Faylor
  0 siblings, 1 reply; 10+ messages in thread
From: John Dong @ 2011-05-26  2:20 UTC (permalink / raw)
  To: cygwin

Hi Chris,


It's nice to hear from Edward that we're not the only ones to notice this behavior.

Of course, patches would be nice, and I would be interested in digging in into this if someone familiar with Cygwin's codebase would be willing to enlighten me as to the codepath for grabbing Win32 process exit codes and how it differs from "Cygwin processes".


John


On May 25, 2011, at 7:19 AM, Christopher Faylor wrote:

> On Wed, May 25, 2011 at 10:16:03AM -0400, Edward Lam wrote:
>> On 29/04/2011 2:35 PM, John Dong wrote:
>>> Reproducing this seems nondeterministic -- sometimes I can get it to
>>> happen in 5 minutes, other times it takes overnight. I've tried using
>>> a different shell (like dash), but it doesn't make a difference,
>>> leading me to suspect this to be a lower-level issue within the
>>> Cygwin DLL. It also seems to not happen for non-zero exit codes (e.g.
>>> checking that exiter.exe 1 returns 1 always seems to succeed), though
>>> I'm not 100% confident that I've tested this thoroughly enough.
>>> 
>>> Again, I've not been able to reproduce this under Windows XP using
>>> any version of Cygwin, but I have been able to reproduce it on both
>>> 32-bit and 64-bit Windows 7. I'm not running anything special on this
>>> machine -- it's a fresh install of Windows 7 Professional, just with
>>> Cygwin installed.
>> 
>> FWIW, we've been running into this as well. It appears to NOT be a 
>> problem with Cygwin 1.5 on Windows 7. It only started happening on 
>> Cygwin 1.7. As a result, we haven't had a reliable Windows 7 build 
>> machine for a while now because we use a Cygwin gmake process that 
>> compiles with MSVC.
> 
> As always: http://cygwin.com/acronyms#PTC
> 
> --
> 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
> 


--
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] 10+ messages in thread

* Re: Cygwin 1.7.x on Windows 7: Exit statuses of Win32 executables are sometimes wrong
  2011-05-26  2:20     ` John Dong
@ 2011-05-26  5:47       ` Christopher Faylor
  0 siblings, 0 replies; 10+ messages in thread
From: Christopher Faylor @ 2011-05-26  5:47 UTC (permalink / raw)
  To: cygwin

On Wed, May 25, 2011 at 07:20:35PM -0700, John Dong wrote:
>It's nice to hear from Edward that we're not the only ones to notice
>this behavior.
>
>Of course, patches would be nice, and I would be interested in digging
>in into this if someone familiar with Cygwin's codebase would be
>willing to enlighten me as to the codepath for grabbing Win32 process
>exit codes and how it differs from "Cygwin processes".

Look in pinfo.cc and sigproc.cc.

cgf

--
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] 10+ messages in thread

* Re: Cygwin 1.7.x on Windows 7: Exit statuses of Win32 executables are sometimes wrong
  2011-04-29 20:01 Cygwin 1.7.x on Windows 7: Exit statuses of Win32 executables are sometimes wrong John Dong
                   ` (2 preceding siblings ...)
  2011-05-25 14:16 ` Edward Lam
@ 2011-05-26  6:02 ` Corinna Vinschen
  3 siblings, 0 replies; 10+ messages in thread
From: Corinna Vinschen @ 2011-05-26  6:02 UTC (permalink / raw)
  To: cygwin

On Apr 29 11:35, John Dong wrote:
> Hi,
> 
> Cygwin on Windows 7, seems to exhibit a rather peculiar behavior: Sometimes the exit status of a Win32 process is incorrectly captured by Cygwin.

Please:

http://cygwin.com/acronyms/#PCYMTWLL
http://cygwin.com/acronyms/#TOFU


> [...]
> > int _tmain(int argc, _TCHAR* argv[])
> > {
> > 	int ret = _ttoi(argv[1]);
> > 	_tprintf(_T("Exiting with %i\n"), ret); 
> > 	
> > 	return ret;
> > }
> 
> Then, I wrote a shell script that called this executable ("exiter.exe") with argument 0 in an infinite loop:
> 
> > #!/bin/sh
> > set -e
> > while true; do
> >  /cygdrive/c/exiter.exe 0
> > echo $?
> > done
> > 
> 
> I expect this script to run forever, as the exit code should always be zero. However, after running this overnight, I see the script terminate:
> 
> > Exiting with 0
> > 0
> > Exiting with 0
> > 
> > $ echo $?
> > 1
> > 

I'm running your testcase on a W7 32 bit machine for about 12 hours now,
and it's still running.  The only difference is that I built exiter.exe
using MingW gcc, rather than VC++, but that doesn't change the fact that
the resulting application is a native one.

Did any of you running into this problem check if this could be a BLODA
problem(*)?


Corinna

(*) http://cygwin.com/faq/faq.using.html#faq.using.bloda

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Project Co-Leader          cygwin AT cygwin DOT com
Red Hat

--
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] 10+ messages in thread

end of thread, other threads:[~2011-05-26  6:02 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-04-29 20:01 Cygwin 1.7.x on Windows 7: Exit statuses of Win32 executables are sometimes wrong John Dong
2011-04-30 11:30 ` Edward McGuire
2011-04-30 13:23   ` John Dong
2011-05-02 17:18     ` John Dong
2011-05-10 17:22 ` John Dong
2011-05-25 14:16 ` Edward Lam
2011-05-25 14:20   ` Christopher Faylor
2011-05-26  2:20     ` John Dong
2011-05-26  5:47       ` Christopher Faylor
2011-05-26  6:02 ` Corinna Vinschen

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