public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* Running native exe from Cygwin in random instances reports incorrect error code 127
@ 2016-01-18 17:40 David Sicilia
  2016-01-18 22:45 ` Warren Young
  0 siblings, 1 reply; 4+ messages in thread
From: David Sicilia @ 2016-01-18 17:40 UTC (permalink / raw)
  To: cygwin

Hi there,

I have a strange problem for which I could not find any help online or
in the Cygwin FAQs (have been searching for about a month now).  I
have Cygwin64 on Windows 7 (downloaded maybe about 8 months ago).

I have a bash script that, in addition to running Cygwin programs,
runs a few native Windows executables (e.g. powershell.exe, windows
python.exe, some C++ binary that I've compiled for Windows [not
cygwin], etc.).

This works fine normally, except in random instances (I'd say it
happens maybe one out of every 30 runs), I observe the following:

   1) The Cygwin bash script runs the native executable
   2) The executable is properly located by bash and begins to run
(i.e., I can see output from the native windows program)
   3) The native windows program successfully completes and exits with
code 0 internally
   4) But -- the error code returned to the bash script is 127 --
despite no indication of an error anywhere

Here's an example:

  #!/bin/bash
  # Run windows binary
  # program is properly located and runs to completion with no errors
  ./nativeWindowsProgram.exe
  echo $?   # maybe 1 out of 30 times this returns 127
  127

This only happens with native binaries, including with one of my own
compiled (from C++) native windows .exe files in which I know for
certain that it is returning a zero error code.

So in other words, the bash script, despite having located and run the
native windows exe successfully, is still handed an error code of 127.
I realize that 127 usually means "Command not found" but that is not
the case here, because the native program always runs, and always runs
successfully (I verified this).

This happens randomly -- today I run the script a few times and it's
fine, then tomorrow I run it a few times (unchanged) and I observe
this issue on one of those runs.  Furthermore, it only happens when
running the native windows binaries in the shell script (never happens
for Cygwin programs).

This is really mystifying me, I've searched all over but I can't find
anything.  Does anyone have any idea?  I could always setup my bash
script to ignore the 127 return code from invocations of native exes,
but I'd prefer to get to the bottom of it.  Any ideas?

Thank you

--
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: Running native exe from Cygwin in random instances reports incorrect error code 127
  2016-01-18 17:40 Running native exe from Cygwin in random instances reports incorrect error code 127 David Sicilia
@ 2016-01-18 22:45 ` Warren Young
  2016-01-19  8:40   ` Larry Hall (Cygwin)
  0 siblings, 1 reply; 4+ messages in thread
From: Warren Young @ 2016-01-18 22:45 UTC (permalink / raw)
  To: The Cygwin Mailing List

On Jan 18, 2016, at 8:27 AM, David Sicilia <dpsicilia@gmail.com> wrote:
> 
>   3) The native windows program successfully completes and exits with
> code 0 internally
>   4) But -- the error code returned to the bash script is 127 --
> despite no indication of an error anywhere

We’ll want a simple test case showing the problem.  I can’t replicate it here.

That is to say, given hello.c:

    #include <stdio.h>

    int main(void)
    {
        printf("Hello, world!\n");
        return 0;
    }

…compiled via Visual Studio 2015’s cl, I can run it thousands of times successfully via runhello.sh:

    #!/bin/bash
    typeset -i i=0
    echo -n "0: "
    while ./hello
    do
        i=i+1
        echo -n "$i: "
    done
    echo “Error: $?"

If the same pair of programs work on your system, then the problem is not with *all* native .exes, as you claim, so you’d need to narrow down what your program is doing that actually causes the problem.

If this pair of programs *fails* on your system, then you’ve probably got a BLODA problem:

    https://cygwin.com/faq/faq.html#faq.using.bloda
--
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: Running native exe from Cygwin in random instances reports incorrect error code 127
  2016-01-18 22:45 ` Warren Young
@ 2016-01-19  8:40   ` Larry Hall (Cygwin)
  2016-01-20  0:34     ` Warren Young
  0 siblings, 1 reply; 4+ messages in thread
From: Larry Hall (Cygwin) @ 2016-01-19  8:40 UTC (permalink / raw)
  To: cygwin

On 01/18/2016 02:50 PM, Warren Young wrote:
> On Jan 18, 2016, at 8:27 AM, David Sicilia <dpsicilia@gmail.com> wrote:
>>
>>    3) The native windows program successfully completes and exits with
>> code 0 internally
>>    4) But -- the error code returned to the bash script is 127 --
>> despite no indication of an error anywhere
>
> We’ll want a simple test case showing the problem.  I can’t replicate it here.

<snip>

> If this pair of programs *fails* on your system, then you’ve probably got a BLODA problem:
>
>      https://cygwin.com/faq/faq.html#faq.using.bloda

The somewhat coincidental recent thread below makes me bet on BLODA,
particularly if it's only happening sometimes.  I could see BLODA
blocking access to a needed DLL in some cases just at the wrong time,
resulting in a code 127.

<https://cygwin.com/ml/cygwin/2016-01/msg00197.html>


-- 
Larry

_____________________________________________________________________

A: Yes.
 > Q: Are you sure?
 >> A: Because it reverses the logical flow of conversation.
 >>> Q: Why is top posting annoying in email?

--
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: Running native exe from Cygwin in random instances reports incorrect error code 127
  2016-01-19  8:40   ` Larry Hall (Cygwin)
@ 2016-01-20  0:34     ` Warren Young
  0 siblings, 0 replies; 4+ messages in thread
From: Warren Young @ 2016-01-20  0:34 UTC (permalink / raw)
  To: cygwin

On Jan 18, 2016, at 7:46 PM, Larry Hall (Cygwin) <reply-to-list-only-lh@cygwin.com> wrote:
> 
> On 01/18/2016 02:50 PM, Warren Young wrote:
> 
>> If this pair of programs *fails* on your system, then you’ve probably got a BLODA problem:
>> 
>>     https://cygwin.com/faq/faq.html#faq.using.bloda
> 
> The somewhat coincidental recent thread below makes me bet on BLODA,
> particularly if it's only happening sometimes.  I could see BLODA
> blocking access to a needed DLL in some cases just at the wrong time,
> resulting in a code 127.

The other thread is basically reporting a known weirdness on Windows, which is that DLLs require the executable flag to be set in its ACL, else it can’t be loaded into an EXE.  In Cygwin, we see this as a missing ‘x’ bit in ls -l output.

It’s not precisely a Cygwin problem, but we do see it sometimes in software built with Cygwin which comes from an *ix system, where libfoo.{so,a} doesn’t require chmod +x to be loaded into an executable.  When ported, the build system doesn’t do the right thing on Cygwin, so it fails.

I assume it’s portability software such as libtool and cmake that are fixing up this detail for most software ported from *ix to Cygwin.

But yes, you’re right, a BLODA misstep could cause a DLL to fail to load, causing a lookalike symptom even though the actual cause is different.
--
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:[~2016-01-19 22:40 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-01-18 17:40 Running native exe from Cygwin in random instances reports incorrect error code 127 David Sicilia
2016-01-18 22:45 ` Warren Young
2016-01-19  8:40   ` Larry Hall (Cygwin)
2016-01-20  0:34     ` Warren Young

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