This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

sh.exe returns incorrect exit code


C:\> sh
sh-4.1$ which -a sh
/usr/bin/sh
sh-4.1$ sh --version
GNU bash, version 4.1.10(4)-release (i686-pc-cygwin)
. . .
sh-4.1$ exit
exit


In my make process I get random errors due to non-zero return codes.  In each case there is not any actual compiler errors.  When rerunning the build I may get failures in other random places.  After a very tedious debugging session using Sysinternals' Process Monitor I determined that sh.exe is messing up.  A full build may run > 50,000 total processes with a mixture of cygwin and Win32 executables.

The compiler (pscl.exe in my trace below) returns exit code 0 to its parent (sh.exe).  sh.exe incorrectly returns exit code 32256 (0x7E00) to its parent (sh.exe).  Parent sh.exe returns error code 1 to its parent (make.exe).  make.exe shuts down the build due to errors.

Below is the relevant process tree.

make.exe (PID=77256) launches sh.exe -c "pscl.exe . || (shopt -s nullglob && rm -f xxx.obj; exit 1)"
+--- sh.exe (PID=94584) launches sh.exe <no command line given>
     +--- sh.exe (PID=32240) launches pscl.exe . 
          +--- pscl.exe (PID=135060-a Win32 executable) launches a bunch of subprocesses .
          +--- pscl.exe (PID=135060) exits with errorlevel 0
     +--- sh.exe (PID=32240) exits with errorlevel 32256 (0x7E00)
+--- sh.exe (PID=94584) launches sh.exe <no command line given>
     +--- sh.exe (PID=84604) launches sh.exe <no command line given>
          +--- sh.exe (PID=156240) launches rm.exe -f xxx.obj
               +--- rm.exe (PID=884) runs
          +--- sh.exe (PID=156240) exits with errorlevel 0
               +--- rm.exe (PID=884) exits with errorlevel 1
     +--- sh.exe (PID=84604) exits with errorlevel 256
+--- sh.exe (PID=94584) exits with errorlevel 1
make.exe exits with errorlevel 2

The errorlevel 32256 (0x7E00) returned by PID 32240 (the forked copy of sh.exe) is bogus.  Any idea what errorlevel 32256 means between sh.exe and its forked copy of itself?  I don't really know how to check this further.  I'm hoping someone can help me determine what this return code represents and why the forked copy of sh.exe would return it.

I can see how fork() starts a second copy of the same cygwin executable (for sh.exe at least).  There appears to be some special return code numbering system between sh.exe and the forked child copy of itself.  Later another forked copy of sh.exe (PID=84604) exits with code 256 and the parent copy of sh.exe (PID=94584) translates this to its own exit code of 1 which is the correct final value for that situation.  In other parts of the process tree not shown here I can see the forked sh.exe exits with 512 and the parent sh.exe correctly translate this to its own exit code 2.  If the cygwin/sh.exe protocol is for the parent to take the forked copy's exit code and right shift it 8 bits, then this means a forked exit code of 0x7E00 translates to a real exit code of 0x7E (0n126).  Does exit code 126 correspond with some internal sh.exe concept?

Thanks in advance for wading through this post.
Darrel

Attachment: cygcheck.out
Description: Binary data

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

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]